I am a newbie. I have seen many masters’ compilation es6 environment using gulp, and I have tried it myself, but I still don’t quite understand how to use it in actual projects.
When I saw the examples written by the masters, I put The js files compiled from multiple es6 files are eventually merged into one bundle.js file, and bundle.js is also referenced in the page.
My current project has multiple pages. For example, a.html needs to reference a.js and jquery.js, b.html needs to reference b.js and jquery.js, and c.html needs to reference b.js and c. .js and jquery.js. How to compile the file in this case, and how to use it in html?
The first situation you mentioned is that you wrote the file yourself
gulp
任务,将多个文件最终合并成为一个bundle.js
.Similarly, for the second scene you mentioned, you only need to write multiple
gulp
任务,最终分别不同的入口文件打包不同的a.js
,b.js
and so on.The
html
文件中对应引入即可,gulp
作为build
tool can be used in any environment. After all, the production environment only uses the generated files.Just quote the compressed and merged js in
gulp
的自定义任务可以压缩和合并js
文件,只需要申明文件路径即可。bundle.js
应该是webpack
生成的,webpack
针对ES6和浏览器具有兼容性优化。在html
中可以直接在index.html
In
gulp
的watch
事件中添加针对js
文件的监听,这样即可在有任何监听的js
文件被修改后重新压缩合并所有js
file for updates