Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

How to use JS Modules in metronic 8 laravel?


I've faced this issue so many times that it became annoying at this point.
When I add NPM package like the doc is mentioning and run laravel mix, it bundles the package and works. However!!!

I can't follow the package documentation and code examples due to the following errors I'm getting. When I create a new JS file named 'Pintura-options.js' within public/demo8/plugins/custom/FilePond/Pintura-options.js and try to use

import something from @something
...I get an error that I can't use import outside of a module, or something like that.

When I try to use that same code within the blade file itself under <script type="module"/> I get another error.

I tried adding code in a separate JS file, withing a script tag, and within the master template...I couldn't get the code to work.. I reached a point where I started a new fresh project without Metronic just to check and the code worked as expected.

I just want to know, how can I use JS modules? where do I place the files? I'm completely lost. When I read package's docs I always ditch the module bundlers and focus on CDNs instead and I am sure that's a very bad idea for Metronic rules.

Kindly help,
Thank you


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)


Hi,

Sorry for the delay. Could you please separate your custom plugin into another folder? Not in the folder plugins/custom.

Then update the webpack.mix.js to include your custom js file.

https://laravel-mix.com/docs/main/mixjs


Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(