const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); /*const HtmlWebpackInlineSourcePlugin=require('html-webpack-inline-source-plugin');*/ const CleanWebpackPlugin = require('clean-webpack-plugin') // 清空打包目录的插件 const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); const webpack = require('webpack'); // const proxyHost = "http://192.168.2.236:5858"; const proxyHost = "http://192.168.2.241:5858"; // const proxyHost = "http://192.168.3.117:5858";//铁钢 // const proxyHost = "http://192.168.3.113:5858";//王峰 module.exports = { entry: { index: path.resolve(__dirname, 'src/js', 'index.js'), qcScore:path.resolve(__dirname, 'src/js', 'qcScore.js'), login:path.resolve(__dirname, 'src/js', 'login.js'), console:path.resolve(__dirname, 'src/js', 'console.js'), deptConsole:path.resolve(__dirname, 'src/js', 'deptConsole.js'), moduleManager: path.resolve(__dirname, 'src/js', 'moduleManager.js'), itemManager: path.resolve(__dirname, 'src/js', 'itemManager.js'), qcList: path.resolve(__dirname, 'src/js', 'qcList.js'), qcListDocteam:path.resolve(__dirname, 'src/js', 'qcListDocteam.js'), qcListDept:path.resolve(__dirname, 'src/js', 'qcListDept.js'), qcListPerson:path.resolve(__dirname, 'src/js', 'qcListPerson.js'), userManager: path.resolve(__dirname, 'src/js', 'userManager.js'), roleManager: path.resolve(__dirname, 'src/js', 'roleManager.js'), tiaomu: path.resolve(__dirname, 'src/js', 'tiaomu.js'), mukuai: path.resolve(__dirname, 'src/js', 'mukuai.js'), abnormal: path.resolve(__dirname, 'src/js', 'abnormal.js'), partDetail: path.resolve(__dirname, 'src/js', 'partDetail.js'), dayDetail: path.resolve(__dirname, 'src/js', 'dayDetail.js'), payDetail: path.resolve(__dirname, 'src/js', 'payDetail.js'), deptScoreDetail: path.resolve(__dirname, 'src/js', 'deptScoreDetail.js'), deptScoreDetailControl: path.resolve(__dirname, 'src/js', 'deptScoreDetailControl.js'), jiaji: path.resolve(__dirname, 'src/js', 'jiaji.js'), partDetailControl: path.resolve(__dirname, 'src/js', 'partDetailControl.js'), quexianXQ: path.resolve(__dirname, 'src/js', 'quexianXQ.js'), quexianDetail: path.resolve(__dirname, 'src/js', 'quexianDetail.js'), quexianDetailControl: path.resolve(__dirname, 'src/js', 'quexianDetailControl.js'), quexianDetailHome: path.resolve(__dirname, 'src/js', 'quexianDetailHome.js'), quexianDetailControlHome: path.resolve(__dirname, 'src/js', 'quexianDetailControlHome.js'), mukuaiControl: path.resolve(__dirname, 'src/js', 'mukuaiControl.js'), tiaomuControl: path.resolve(__dirname, 'src/js', 'tiaomuControl.js'), assertType: path.resolve(__dirname, 'src/js', 'assertType.js'), assertTypeDetail: path.resolve(__dirname, 'src/js', 'assertTypeDetail.js'), singleVeto:path.resolve(__dirname, 'src/js', 'singleVeto.js'), itemDefectDetail:path.resolve(__dirname, 'src/js', 'itemDefectDetail.js'), vendor: 'lodash'// 多个页面所需的公共库文件,防止重复打包带入 }, output: { publicPath: '/', //这里要放的是静态资源CDN的地址 path: path.resolve(__dirname, 'dist'), filename: 'js/[name].js' }, resolve: { extensions: [".js", ".css", ".json"], alias: {} //配置别名可以加快webpack查找模块的速度 }, plugins: [//多入口的html文件用chunks这个参数来区分 new HtmlWebpackPlugin({ title: 'index', template: path.resolve(__dirname, 'src/html', 'index.html'), filename: 'index.html', chunks: ['index', 'vendor', 'common','scrollBar'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'console.html', template: path.resolve(__dirname, 'src/html', 'console.html'), filename: 'console.html', chunks: ['console', 'vendor', 'common','scrollBar'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'tiaomuControl.html', template: path.resolve(__dirname, 'src/html', 'tiaomuControl.html'), filename: 'tiaomuControl.html', chunks: ['tiaomuControl', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'assertTypeDetail.html', template: path.resolve(__dirname, 'src/html', 'assertTypeDetail.html'), filename: 'assertTypeDetail.html', chunks: ['assertTypeDetail', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'assertType.html', template: path.resolve(__dirname, 'src/html', 'assertType.html'), filename: 'assertType.html', chunks: ['assertType', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'mukuaiControl.html', template: path.resolve(__dirname, 'src/html', 'mukuaiControl.html'), filename: 'mukuaiControl.html', chunks: ['mukuaiControl', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'quexianDetail.html', template: path.resolve(__dirname, 'src/html', 'quexianDetail.html'), filename: 'quexianDetail.html', chunks: ['quexianDetail', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'quexianDetailHome.html', template: path.resolve(__dirname, 'src/html', 'quexianDetailHome.html'), filename: 'quexianDetailHome.html', chunks: ['quexianDetailHome', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'quexianDetailControl.html', template: path.resolve(__dirname, 'src/html', 'quexianDetailControl.html'), filename: 'quexianDetailControl.html', chunks: ['quexianDetailControl', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'quexianDetailControlHome.html', template: path.resolve(__dirname, 'src/html', 'quexianDetailControlHome.html'), filename: 'quexianDetailControlHome.html', chunks: ['quexianDetailControlHome', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'quexianXQ.html', template: path.resolve(__dirname, 'src/html', 'quexianXQ.html'), filename: 'quexianXQ.html', chunks: ['quexianXQ', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'partDetailControl.html', template: path.resolve(__dirname, 'src/html', 'partDetailControl.html'), filename: 'partDetailControl.html', chunks: ['partDetailControl', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'jiaji.html', template: path.resolve(__dirname, 'src/html', 'jiaji.html'), filename: 'jiaji.html', chunks: ['jiaji', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'abnormal.html', template: path.resolve(__dirname, 'src/html', 'abnormal.html'), filename: 'abnormal.html', chunks: ['abnormal', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'deptScoreDetailControl.html', template: path.resolve(__dirname, 'src/html', 'deptScoreDetailControl.html'), filename: 'deptScoreDetailControl.html', chunks: ['deptScoreDetailControl', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'payDetail.html', template: path.resolve(__dirname, 'src/html', 'payDetail.html'), filename: 'payDetail.html', chunks: ['payDetail', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'partDetail.html', template: path.resolve(__dirname, 'src/html', 'partDetail.html'), filename: 'partDetail.html', chunks: ['partDetail', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'dayDetail.html', template: path.resolve(__dirname, 'src/html', 'dayDetail.html'), filename: 'dayDetail.html', chunks: ['dayDetail', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'deptScoreDetail.html', template: path.resolve(__dirname, 'src/html', 'deptScoreDetail.html'), filename: 'deptScoreDetail.html', chunks: ['deptScoreDetail', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'deptConsole.html', template: path.resolve(__dirname, 'src/html', 'deptConsole.html'), filename: 'deptConsole.html', chunks: ['deptConsole', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'itemManager.html', template: path.resolve(__dirname, 'src/html', 'itemManager.html'), filename: 'itemManager.html', chunks: ['itemManager', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'moduleManager.html', template: path.resolve(__dirname, 'src/html', 'moduleManager.html'), filename: 'moduleManager.html', chunks: ['moduleManager', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'tiaomu.html', template: path.resolve(__dirname, 'src/html', 'tiaomu.html'), filename: 'tiaomu.html', chunks: ['tiaomu', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'mukuai.html', template: path.resolve(__dirname, 'src/html', 'mukuai.html'), filename: 'mukuai.html', chunks: ['mukuai', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'login.html', template: path.resolve(__dirname, 'src/html', 'login.html'), filename: 'login.html', chunks: ['login', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'qcList.html', template: path.resolve(__dirname, 'src/html', 'qcList.html'), filename: 'qcList.html', chunks: ['qcList', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'qcListDocteam.html', template: path.resolve(__dirname, 'src/html', 'qcListDocteam.html'), filename: 'qcListDocteam.html', chunks: ['qcListDocteam', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'qcListPerson.html', template: path.resolve(__dirname, 'src/html', 'qcListPerson.html'), filename: 'qcListPerson.html', chunks: ['qcListPerson', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'qcListDept.html', template: path.resolve(__dirname, 'src/html', 'qcListDept.html'), filename: 'qcListDept.html', chunks: ['qcListDept', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'qcScore.html', template: path.resolve(__dirname, 'src/html', 'qcScore.html'), filename: 'qcScore.html', chunks: [ 'qcScore','vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'statistics.html', template: path.resolve(__dirname, 'src/html', 'statistics.html'), filename: 'statistics.html', chunks: ['index', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'userManager.html', template: path.resolve(__dirname, 'src/html', 'userManager.html'), filename: 'userManager.html', chunks: ['userManager', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'roleManager.html', template: path.resolve(__dirname, 'src/html', 'roleManager.html'), filename: 'roleManager.html', chunks: ['roleManager', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'singleVeto.html', //单项否决详情页 template: path.resolve(__dirname, 'src/html', 'singleVeto.html'), filename: 'singleVeto.html', chunks: ['singleVeto', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new HtmlWebpackPlugin({ title: 'itemDefectDetail.html', //单项否决详情页 template: path.resolve(__dirname, 'src/html', 'itemDefectDetail.html'), filename: 'itemDefectDetail.html', chunks: ['itemDefectDetail', 'vendor', 'common'], hash: true, //防止缓存 inject: true, minify: { removeAttributeQuotes: true, //压缩 去掉引号 removeComments: true, //移除HTML中的注释 collapseWhitespace: true //删除空白符与换行符 } }), new CopyWebpackPlugin([ { from:'src/resource', to:path.resolve(__dirname,'dist','resource'), flatten:true, //false会拷贝原始文件夹路径 } ]), new MiniCssExtractPlugin({ filename: 'css/[name].css', chunkFilename: '[id].css' }), new webpack.HotModuleReplacementPlugin(), new CleanWebpackPlugin() ], optimization: { //webpack4.x的最新优化配置项,用于提取公共代码 minimizer: [ new UglifyJsPlugin({ uglifyOptions: { ie8: true, compress: { properties: false, warnings: false }, mangle: { screw_ie8: false, except: ['e'] }, output: { beautify: true }, sourceMap: false } }) ], splitChunks: { cacheGroups: { commons: { chunks: "initial", name: "common", minChunks: 2, maxInitialRequests: 5, // The default limit is too small to showcase the effect minSize: 0, // This is example is too small to create commons chunks reuseExistingChunk: true // 可设置是否重用该chunk } } } }, module: { noParse: /WdatePicker/, rules: [ { test: /.js$/, enforce: 'post', loader: 'es3ify-loader' }, { test: /\.m?js$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets:['@babel/preset-env'] } } }, { test: /\.css$/, use: [{ loader: MiniCssExtractPlugin.loader }, 'css-loader' ] }, { test: /\.less$/, use: [{ loader: MiniCssExtractPlugin.loader }, 'css-loader', 'less-loader' ] }, { test:/\.(png|gif|jpg|jpeg|svg|eot|ttf|woff|woff2)$/, use:[{ loader:'url-loader', options:{ limit:10240, esModule:false, name:'[name]_[hash:6].[ext]', outputPath:'images/' } }], exclude:/node_modules/ },{ test:/.html$/, use:'html-withimg-loader' } ] }, // devtool: 'cheap-module-eval-source-map', //开发环境cheap-module-eval-source-map //生产环境cheap-module-source-map mode: 'development', devServer: { contentBase: "./dist", //静态文件根目录 proxy: { '/': proxyHost }, hot: true, openPage:'login.html' } }