var path = require('path') var webpack = require('webpack') var HtmlwebpackPlugin = require('html-webpack-plugin'); //引入happypack 实现多线程打包 var HappyPack = require('happypack'); var os = require('os'); var happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length }); let BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; function date(){ let nowDate = new Date(); let year = nowDate.getFullYear(); let month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1; let day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate(); let hours = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours(); let dateStr = year + '_' + month + day +'_'+ hours; return dateStr; } module.exports = { // entry: { // // 'vueExample': './src/main.js', // 'gwDdIndex': './src/pages/gwDdIndex.js', // // 'apkUpLoadIndex': './src/pages/apkUploadIndex.js', // "babel-polyfill": "babel-polyfill" // }, // productionSourceMap:false, // configureWebpack: { // devtool:false // }, entry:{ 'gwDdIndex': './src/pages/gwDdIndex.js', "babel-polyfill": "babel-polyfill", "jobAccount": "./src/pages/jobAccount.js", "problemSeeXsk": "./src/pages/problemSeeXsk.js", "problemSeeRy": "./src/pages/problemSeeRy.js", "problemSeeSh": "./src/pages/problemSeeSh.js", "problemSeeDxs": "./src/pages/problemSeeDxs.js", "problemSeeSz": "./src/pages/problemSeeSz.js", "home": "./src/pages/home.js", "map3D": "./src/pages/map3D.js", "inspectionPlanQuery": "./src/pages/inspectionPlanQuery.js", }, optimization: { minimize: false }, output: { path: path.resolve(__dirname, './dist'), publicPath: '/dist/', filename: '[name]_build.js', chunkFilename: 'chunk_[name].js?[chunkhash]', }, plugins: [ new webpack.HotModuleReplacementPlugin(), // new webpack.optimize.CommonsChunkPlugin({ // name:['vue','echarts'], // minChunks:Infinity // }), // new webpack.optimize.UglifyJsPlugin({ // sourceMap: true, // parallel: true, // compress: { // warnings: false // } // }), new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", jquery: "jquery", "window.jQuery": "jquery" }), new webpack.LoaderOptionsPlugin({ minimize: false }), new HappyPack({ id: 'happybabel', loaders: [ { loader:'babel-loader', options: { presets: ['es2015'], plugins: ['syntax-dynamic-import'], cacheDirectory:true }, }], threadPool: happyThreadPool, // cache: true, verbose: true }), new HappyPack({ id: 'happyvue', loaders: ['vue-loader'], threadPool: happyThreadPool, // cache: true, verbose: true }), new BundleAnalyzerPlugin() ], module: { rules: [ { test: /\.css$/, use: [ 'vue-style-loader', 'css-loader' ], }, { test: /\.(woff|svg|eot|ttf)\??.*$/, loader: 'url-loader' }, { test: /\.vue$/, // loader: 'vue-loader', use: 'happypack/loader?id=happyvue', }, { test: /\.js$/, use: 'happypack/loader?id=happybabel', exclude: /(node_modules|dist|static)/ }, { test: /\.(png|jpg|gif|svg)$/, loader: 'file-loader', options: { name: '[name].[ext]?[hash]' } } ] }, resolve: { alias: { 'vue$': 'vue/dist/vue.esm.js', '@api':path.resolve('src/api'), '@widget':path.resolve('src/widgets'), '@util':path.resolve('src/utils'), '@baseWidget':path.resolve('src/widgets/baseWidget'), '@scss':path.resolve('src/assets/sass'), }, extensions: ['.html', '.js', '.vue', '.json','.scss'], modules: [ path.resolve('src'), path.resolve('node_modules') ], }, devServer: { proxy: { '/pdcApi': { // target: "http://localhost:8500", // target: "http://61.154.12.112:9900/pdcApi", target: "http://127.0.0.1:8500", // target: "http://192.168.1.136:8400", // target: "http://pdc.goldenwater.com.cn/pdcApi", // target: "http://60.208.113.79:8000/pdcApi/", changeOrigin: true, pathRewrite: { '^/pdcApi': '' } }, '/trs': { target: "http://10.1.194.19:8080", changeOrigin: true, pathRewrite: { '^/trs': '' } }, '/arcgisApi/': { target: "http://hzz-pad.goldenwater.com.cn/arcgisApi/", changeOrigin: true, pathRewrite: { '^/arcgisApi/': '' } }, '/JsReport/': { target: "http://pdc.goldenwater.com.cn/JsReport/", changeOrigin: true, pathRewrite: { '^/JsReport/': '' } }, '/demo/': { target: "http://10.1.102.136:8888/demo/", changeOrigin: true, pathRewrite: { '^/demo/': '' } }, '/pageofficePath/': { target: "http://pdc.goldenwater.com.cn/pageofficePath/", // target: "http://10.1.102.169:9002/", changeOrigin: true, pathRewrite: { '^/pageofficePath/': '' } }, }, host:'0.0.0.0', port:'8082', open:true,//自动拉起浏览器 hot:true,//热加载 historyApiFallback: true, noInfo: true, overlay: true }, performance: { hints: false }, devtool: false } if (process.env.NODE_ENV === 'production') { module.exports.devtool = false; module.exports.optimization = { minimize: true }, module.exports.output = { path: path.resolve(__dirname, './dist'), publicPath: '/dist/', filename: '[name]_build_v'+date()+'_.js', chunkFilename: 'chunk_[name]_v'+date()+'_[chunkhash].js?', }; // http://vue-loader.vuejs.org/en/workflow/production.html module.exports.plugins = (module.exports.plugins || []).concat([ new webpack.DefinePlugin({ 'process.env': { NODE_ENV: '"production"' } }), // new webpack.optimize.UglifyJsPlugin({ // sourceMap: true, // compress: { // warnings: false // } // }), new webpack.LoaderOptionsPlugin({ minimize: true }), new HtmlwebpackPlugin({ filename: 'gwDdindex.html', template: __dirname + '/src/pages/gwDdIndex.html',//src\pages\gwDdIndex.html chunks:['gwDdIndex'], inject:true, versionPath: date(), // chunksSortMode:'none', }), //工作统计 new HtmlwebpackPlugin({ title:'jobAccountPage', template:__dirname + '/src/pages/jobAccount.html', filename:'jobAccount.html', templateParameters:{ param1:'tony stark', param2:'bruce banner' }, chunks:['jobAccount'], }), //问题查看小水库 new HtmlwebpackPlugin({ title:'problemSeeXsk', template:__dirname + '/src/pages/problemSeeXsk.html', filename:'problemSeeXsk.html', templateParameters:{ param1:'tony stark', param2:'bruce banner' }, chunks:['problemSeeXsk'], }), //问题查看人饮 new HtmlwebpackPlugin({ title:'problemSeeRy', template:__dirname + '/src/pages/problemSeeRy.html', filename:'problemSeeRy.html', templateParameters:{ param1:'tony stark', param2:'bruce banner' }, chunks:['problemSeeRy'], }), //问题查看水毁 new HtmlwebpackPlugin({ title:'problemSeeSh', template:__dirname + '/src/pages/problemSeeSh.html', filename:'problemSeeSh.html', templateParameters:{ param1:'tony stark', param2:'bruce banner' }, chunks:['problemSeeSh'], }), //问题查看地下水 new HtmlwebpackPlugin({ title:'problemSeeDxs', template:__dirname + '/src/pages/problemSeeDxs.html', filename:'problemSeeDxs.html', templateParameters:{ param1:'tony stark', param2:'bruce banner' }, chunks:['problemSeeDxs'], }), //问题查看水闸 new HtmlwebpackPlugin({ title:'problemSeeSz', template:__dirname + '/src/pages/problemSeeSz.html', filename:'problemSeeSz.html', templateParameters:{ param1:'tony stark', param2:'bruce banner' }, chunks:['problemSeeSz'], }), //督查计划查询 new HtmlwebpackPlugin({ title:'inspectionPlanQuery', template:__dirname + '/src/pages/inspectionPlanQuery.html', filename:'inspectionPlanQuery.html', templateParameters:{ param1:'tony stark', param2:'bruce banner' }, chunks:['inspectionPlanQuery'], }), new HtmlwebpackPlugin({ title:'home', template:__dirname + '/src/pages/home.html', filename:'home.html', chunks:['home'], }), new HtmlwebpackPlugin({ title:'map3D', template:__dirname + '/src/pages/map3D.html', filename:'map3D.html', chunks:['map3D'], }) ]); }