webpack.config.js.buildconfig 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. var path = require('path')
  2. var webpack = require('webpack')
  3. var HtmlwebpackPlugin = require('html-webpack-plugin');
  4. //引入happypack 实现多线程打包
  5. var HappyPack = require('happypack');
  6. var os = require('os');
  7. var happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
  8. let BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  9. function date(){
  10. let nowDate = new Date();
  11. let year = nowDate.getFullYear();
  12. let month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1;
  13. let day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
  14. let hours = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
  15. let dateStr = year + '_' + month + day +'_'+ hours;
  16. return dateStr;
  17. }
  18. module.exports = {
  19. // entry: {
  20. // // 'vueExample': './src/main.js',
  21. // 'gwDdIndex': './src/pages/gwDdIndex.js',
  22. // // 'apkUpLoadIndex': './src/pages/apkUploadIndex.js',
  23. // "babel-polyfill": "babel-polyfill"
  24. // },
  25. // productionSourceMap:false,
  26. // configureWebpack: {
  27. // devtool:false
  28. // },
  29. entry:{
  30. 'gwDdIndex': './src/pages/gwDdIndex.js',
  31. "babel-polyfill": "babel-polyfill",
  32. "jobAccount": "./src/pages/jobAccount.js",
  33. "problemSeeXsk": "./src/pages/problemSeeXsk.js",
  34. "problemSeeRy": "./src/pages/problemSeeRy.js",
  35. "problemSeeSh": "./src/pages/problemSeeSh.js",
  36. "problemSeeDxs": "./src/pages/problemSeeDxs.js",
  37. "problemSeeSz": "./src/pages/problemSeeSz.js",
  38. "home": "./src/pages/home.js",
  39. "map3D": "./src/pages/map3D.js",
  40. "inspectionPlanQuery": "./src/pages/inspectionPlanQuery.js",
  41. },
  42. optimization: {
  43. minimize: false
  44. },
  45. output: {
  46. path: path.resolve(__dirname, './dist'),
  47. publicPath: '/dist/',
  48. filename: '[name]_build.js',
  49. chunkFilename: 'chunk_[name].js?[chunkhash]',
  50. },
  51. plugins: [
  52. new webpack.HotModuleReplacementPlugin(),
  53. // new webpack.optimize.CommonsChunkPlugin({
  54. // name:['vue','echarts'],
  55. // minChunks:Infinity
  56. // }),
  57. // new webpack.optimize.UglifyJsPlugin({
  58. // sourceMap: true,
  59. // parallel: true,
  60. // compress: {
  61. // warnings: false
  62. // }
  63. // }),
  64. new webpack.ProvidePlugin({
  65. $: "jquery",
  66. jQuery: "jquery",
  67. jquery: "jquery",
  68. "window.jQuery": "jquery"
  69. }),
  70. new webpack.LoaderOptionsPlugin({
  71. minimize: false
  72. }),
  73. new HappyPack({
  74. id: 'happybabel',
  75. loaders: [
  76. {
  77. loader:'babel-loader',
  78. options: {
  79. presets: ['es2015'],
  80. plugins: ['syntax-dynamic-import'],
  81. cacheDirectory:true
  82. },
  83. }],
  84. threadPool: happyThreadPool,
  85. // cache: true,
  86. verbose: true
  87. }),
  88. new HappyPack({
  89. id: 'happyvue',
  90. loaders: ['vue-loader'],
  91. threadPool: happyThreadPool,
  92. // cache: true,
  93. verbose: true
  94. }),
  95. new BundleAnalyzerPlugin()
  96. ],
  97. module: {
  98. rules: [
  99. {
  100. test: /\.css$/,
  101. use: [
  102. 'vue-style-loader',
  103. 'css-loader'
  104. ],
  105. },
  106. {
  107. test: /\.(woff|svg|eot|ttf)\??.*$/,
  108. loader: 'url-loader'
  109. },
  110. {
  111. test: /\.vue$/,
  112. // loader: 'vue-loader',
  113. use: 'happypack/loader?id=happyvue',
  114. },
  115. {
  116. test: /\.js$/,
  117. use: 'happypack/loader?id=happybabel',
  118. exclude: /(node_modules|dist|static)/
  119. },
  120. {
  121. test: /\.(png|jpg|gif|svg)$/,
  122. loader: 'file-loader',
  123. options: {
  124. name: '[name].[ext]?[hash]'
  125. }
  126. }
  127. ]
  128. },
  129. resolve: {
  130. alias: {
  131. 'vue$': 'vue/dist/vue.esm.js',
  132. '@api':path.resolve('src/api'),
  133. '@widget':path.resolve('src/widgets'),
  134. '@util':path.resolve('src/utils'),
  135. '@baseWidget':path.resolve('src/widgets/baseWidget'),
  136. '@scss':path.resolve('src/assets/sass'),
  137. },
  138. extensions: ['.html', '.js', '.vue', '.json','.scss'],
  139. modules: [
  140. path.resolve('src'),
  141. path.resolve('node_modules')
  142. ],
  143. },
  144. devServer: {
  145. proxy: {
  146. '/pdcApi': {
  147. // target: "http://localhost:8500",
  148. // target: "http://61.154.12.112:9900/pdcApi",
  149. target: "http://127.0.0.1:8500",
  150. // target: "http://192.168.1.136:8400",
  151. // target: "http://pdc.goldenwater.com.cn/pdcApi",
  152. // target: "http://60.208.113.79:8000/pdcApi/",
  153. changeOrigin: true,
  154. pathRewrite: {
  155. '^/pdcApi': ''
  156. }
  157. },
  158. '/trs': {
  159. target: "http://10.1.194.19:8080",
  160. changeOrigin: true,
  161. pathRewrite: {
  162. '^/trs': ''
  163. }
  164. },
  165. '/arcgisApi/': {
  166. target: "http://hzz-pad.goldenwater.com.cn/arcgisApi/",
  167. changeOrigin: true,
  168. pathRewrite: {
  169. '^/arcgisApi/': ''
  170. }
  171. },
  172. '/JsReport/': {
  173. target: "http://pdc.goldenwater.com.cn/JsReport/",
  174. changeOrigin: true,
  175. pathRewrite: {
  176. '^/JsReport/': ''
  177. }
  178. },
  179. '/demo/': {
  180. target: "http://10.1.102.136:8888/demo/",
  181. changeOrigin: true,
  182. pathRewrite: {
  183. '^/demo/': ''
  184. }
  185. },
  186. '/pageofficePath/': {
  187. target: "http://pdc.goldenwater.com.cn/pageofficePath/",
  188. // target: "http://10.1.102.169:9002/",
  189. changeOrigin: true,
  190. pathRewrite: {
  191. '^/pageofficePath/': ''
  192. }
  193. },
  194. },
  195. host:'0.0.0.0',
  196. port:'8082',
  197. open:true,//自动拉起浏览器
  198. hot:true,//热加载
  199. historyApiFallback: true,
  200. noInfo: true,
  201. overlay: true
  202. },
  203. performance: {
  204. hints: false
  205. },
  206. devtool: false
  207. }
  208. if (process.env.NODE_ENV === 'production') {
  209. module.exports.devtool = false;
  210. module.exports.optimization = {
  211. minimize: true
  212. },
  213. module.exports.output = {
  214. path: path.resolve(__dirname, './dist'),
  215. publicPath: '/dist/',
  216. filename: '[name]_build_v'+date()+'_.js',
  217. chunkFilename: 'chunk_[name]_v'+date()+'_[chunkhash].js?',
  218. };
  219. // http://vue-loader.vuejs.org/en/workflow/production.html
  220. module.exports.plugins = (module.exports.plugins || []).concat([
  221. new webpack.DefinePlugin({
  222. 'process.env': {
  223. NODE_ENV: '"production"'
  224. }
  225. }),
  226. // new webpack.optimize.UglifyJsPlugin({
  227. // sourceMap: true,
  228. // compress: {
  229. // warnings: false
  230. // }
  231. // }),
  232. new webpack.LoaderOptionsPlugin({
  233. minimize: true
  234. }),
  235. new HtmlwebpackPlugin({
  236. filename: 'gwDdindex.html',
  237. template: __dirname + '/src/pages/gwDdIndex.html',//src\pages\gwDdIndex.html
  238. chunks:['gwDdIndex'],
  239. inject:true,
  240. versionPath: date(),
  241. // chunksSortMode:'none',
  242. }),
  243. //工作统计
  244. new HtmlwebpackPlugin({
  245. title:'jobAccountPage',
  246. template:__dirname + '/src/pages/jobAccount.html',
  247. filename:'jobAccount.html',
  248. templateParameters:{
  249. param1:'tony stark',
  250. param2:'bruce banner'
  251. },
  252. chunks:['jobAccount'],
  253. }),
  254. //问题查看小水库
  255. new HtmlwebpackPlugin({
  256. title:'problemSeeXsk',
  257. template:__dirname + '/src/pages/problemSeeXsk.html',
  258. filename:'problemSeeXsk.html',
  259. templateParameters:{
  260. param1:'tony stark',
  261. param2:'bruce banner'
  262. },
  263. chunks:['problemSeeXsk'],
  264. }),
  265. //问题查看人饮
  266. new HtmlwebpackPlugin({
  267. title:'problemSeeRy',
  268. template:__dirname + '/src/pages/problemSeeRy.html',
  269. filename:'problemSeeRy.html',
  270. templateParameters:{
  271. param1:'tony stark',
  272. param2:'bruce banner'
  273. },
  274. chunks:['problemSeeRy'],
  275. }),
  276. //问题查看水毁
  277. new HtmlwebpackPlugin({
  278. title:'problemSeeSh',
  279. template:__dirname + '/src/pages/problemSeeSh.html',
  280. filename:'problemSeeSh.html',
  281. templateParameters:{
  282. param1:'tony stark',
  283. param2:'bruce banner'
  284. },
  285. chunks:['problemSeeSh'],
  286. }),
  287. //问题查看地下水
  288. new HtmlwebpackPlugin({
  289. title:'problemSeeDxs',
  290. template:__dirname + '/src/pages/problemSeeDxs.html',
  291. filename:'problemSeeDxs.html',
  292. templateParameters:{
  293. param1:'tony stark',
  294. param2:'bruce banner'
  295. },
  296. chunks:['problemSeeDxs'],
  297. }),
  298. //问题查看水闸
  299. new HtmlwebpackPlugin({
  300. title:'problemSeeSz',
  301. template:__dirname + '/src/pages/problemSeeSz.html',
  302. filename:'problemSeeSz.html',
  303. templateParameters:{
  304. param1:'tony stark',
  305. param2:'bruce banner'
  306. },
  307. chunks:['problemSeeSz'],
  308. }),
  309. //督查计划查询
  310. new HtmlwebpackPlugin({
  311. title:'inspectionPlanQuery',
  312. template:__dirname + '/src/pages/inspectionPlanQuery.html',
  313. filename:'inspectionPlanQuery.html',
  314. templateParameters:{
  315. param1:'tony stark',
  316. param2:'bruce banner'
  317. },
  318. chunks:['inspectionPlanQuery'],
  319. }),
  320. new HtmlwebpackPlugin({
  321. title:'home',
  322. template:__dirname + '/src/pages/home.html',
  323. filename:'home.html',
  324. chunks:['home'],
  325. }),
  326. new HtmlwebpackPlugin({
  327. title:'map3D',
  328. template:__dirname + '/src/pages/map3D.html',
  329. filename:'map3D.html',
  330. chunks:['map3D'],
  331. })
  332. ]);
  333. }