How to use gulp compiled es6 files in real projects?
PHP中文网
PHP中文网 2017-05-19 10:34:53
0
2
552

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?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
phpcn_u1582

The first situation you mentioned is that you wrote the file yourselfgulp任务,将多个文件最终合并成为一个bundle.js.

Similarly, for the second scene you mentioned, you only need to write multiple gulp任务,最终分别不同的入口文件打包不同的a.jsb.jsand 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 gulpwatch事件中添加针对js文件的监听,这样即可在有任何监听的js文件被修改后重新压缩合并所有jsfile for updates

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template