84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
相似问题:https://segmentfault.com/q/10...
比如现在我要创建一个jQuery项目,我通过
npm install jquery
将jquery安装在本地。现在我在配置文件中配置了一个HtmlWebpackPlugin自动生成一个html页面,可以将打包好的js文件直接引入到html页面中,非常方便。现在我希望, 可以将jquery直接通过script自动添加到这个自动生成的html页面中,而不需要打包,能否实现呢?
认证0级讲师
文档里不写了吗,你可以基于一个模板生成htmlhttps://github.com/ampedandwi...
plugins: [ new HtmlWebpackPlugin({ title: 'Custom template', template: 'my-index.ejs', // Load a custom template (ejs by default see the FAQ for details) }) ]
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> <title><%= htmlWebpackPlugin.options.title %></title> </head> <body> </body> </html>
在模版里直接通过script标签把jquery引入进来
entry: { page: 'path/to/page.js', jquery: 'node_modules/jquery/dist/jquery.min.js' }
new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html', inject: true, chunks: ['jquery', 'page'] // 按照先后顺序插入script标签 })
文档里不写了吗,你可以基于一个模板生成html
https://github.com/ampedandwi...
在模版里直接通过script标签把jquery引入进来