webpack
来源:互联网 发布:csgo网络不稳定 编辑:程序博客网 时间:2024/06/06 00:08
1:webpack安装和命令行
npm initnpm install webpack --save-devwebpack hello.js hello.bundle.js //hello.js 需要打包的文件名称 hello.bundle.js 打包完成之后的名称//模块化引入js文件require('./world.js');//引入css-loader style-loadernpm install --save css-loader style-loader//js文件中引入css文件需要这样引入css才能生效require('style-loader!css-loader!./style.css');webpack hello.js hello.bundle.js //自动监听文件改变
2: webpack.config.js
const path = require('path');const HtmlWebpackPlugin = require('html-webpack-plugin');module.exports = { // entry: ['./src/script/main.js', './src/script/a.js'], //入口文件 entry: { main: './src/script/main.js', a: './src/script/a.js', b: './src/script/b.js', c: './src/script/c.js' }, devServer: { contentBase: './dist' }, output: { path: path.resolve(__dirname, 'dist'), //打包以后的文件路径 filename: 'js/[name].js', //打包以后的文件名称 publicPath: '/' //项目上线时添加的域名路径 }, plugins: [ new HtmlWebpackPlugin({ title: 'Output management', template: 'index.html', filename:'a.html', // 设置生成文件的名称 inject: 'head', //指定生成的脚本 放置在head区域 chunks:['main','a'], // 生成的html文件只引入main a 文件 minify: { removeComments: true, // 去除注释 collapseWhitespace: true //去除空格 更多参数看官方配置 } }), new HtmlWebpackPlugin({ title: 'Output management', template: 'index.html', filename:'b.html', // 设置生成文件的名称 inject: 'head', //指定生成的脚本 放置在head区域 excludeChunks:['a','c'], //除了这里的文件其他的都引入 minify: { removeComments: true, // 去除注释 collapseWhitespace: true //去除空格 更多参数看官方配置 } }), new HtmlWebpackPlugin({ title: 'Output management', template: 'index.html', filename:'c.html', // 设置生成文件的名称 inject: 'head', //指定生成的脚本 放置在head区域 chunks:['c'], minify: { removeComments: true, // 去除注释 collapseWhitespace: true //去除空格 更多参数看官方配置 } }), new HtmlWebpackPlugin({ template: 'about.html', filename: 'about.html' }), ]}
阅读全文
0 0
- WebPack
- webpack
- webpack
- webpack
- webpack
- Webpack
- webpack
- webpack
- Webpack
- webpack
- webpack
- webpack
- webpack
- webpack
- Webpack
- webpack
- webpack
- webpack
- servlet session
- both methods have same erasure, yet neither overrides the other 【泛型类型擦除与重载和覆盖问题】
- 【 Hibernate4】二级缓存详解
- Java并发编程艺术 8 Java中的并发工具类
- 机房收费系统(四)MDI窗体
- webpack
- XUtils BitmapUtils 源码分析
- 2th integer_to_roman
- c++虚基类
- Python学习笔记 8
- Hibernate缓存详解
- 正则表达式符号大全
- spoj2666 Qtree4(类似于bzoj1095: [ZJOI2007]Hide 捉迷藏)详解
- (十七)bufferevent的管理