Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • 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.




Thanks


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(