简体   繁体   中英

How to add a new JavaScript file

https://github.com/puikinsh/Adminator-admin-dashboard

When you use this webpack I want to create and load a new JavaScript file. When using this webpack, I want to create a new javascript file and load it, how do I do that?

If I want to add a new HTML file, I need to add the HTML name to htmlPlugin.js, and then create the HTML file.

However, when I create a new JavaScript file and load it in src/assets/scripts/index.js, it does not work properly. Can someone please help me?

If you need to add a new JS is as simple as adding it, exporting some methods or class, and (the most crucial part) importing it, because if webpack doesn't find any usage, it won't include it.

For example: create a sample.js in folder src/scripts with

export default (function() {
  alert('Hello world')
})()

and, in index.js, add

import './sample'

And you'll see an alert box when the page is loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM