webpack.config.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. /*const HtmlWebpackInlineSourcePlugin=require('html-webpack-inline-source-plugin');*/
  4. const CleanWebpackPlugin = require('clean-webpack-plugin') // 清空打包目录的插件
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const CopyWebpackPlugin = require('copy-webpack-plugin');
  7. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  8. const webpack = require('webpack');
  9. const proxyHost = "http://192.168.2.236:5858";
  10. // const proxyHost = "http://192.168.2.241:5858";
  11. // const proxyHost = "http://192.168.3.117:5858";//铁钢
  12. // const proxyHost = "http://192.168.3.113:5858";//王峰
  13. module.exports = {
  14. entry: {
  15. index: path.resolve(__dirname, 'src/js', 'index.js'),
  16. qcScore:path.resolve(__dirname, 'src/js', 'qcScore.js'),
  17. login:path.resolve(__dirname, 'src/js', 'login.js'),
  18. console:path.resolve(__dirname, 'src/js', 'console.js'),
  19. deptConsole:path.resolve(__dirname, 'src/js', 'deptConsole.js'),
  20. moduleManager: path.resolve(__dirname, 'src/js', 'moduleManager.js'),
  21. itemManager: path.resolve(__dirname, 'src/js', 'itemManager.js'),
  22. qcList: path.resolve(__dirname, 'src/js', 'qcList.js'),
  23. qcListDept:path.resolve(__dirname, 'src/js', 'qcListDept.js'),
  24. qcListPerson:path.resolve(__dirname, 'src/js', 'qcListPerson.js'),
  25. userManager: path.resolve(__dirname, 'src/js', 'userManager.js'),
  26. roleManager: path.resolve(__dirname, 'src/js', 'roleManager.js'),
  27. tiaomu: path.resolve(__dirname, 'src/js', 'tiaomu.js'),
  28. mukuai: path.resolve(__dirname, 'src/js', 'mukuai.js'),
  29. abnormal: path.resolve(__dirname, 'src/js', 'abnormal.js'),
  30. partDetail: path.resolve(__dirname, 'src/js', 'partDetail.js'),
  31. dayDetail: path.resolve(__dirname, 'src/js', 'dayDetail.js'),
  32. payDetail: path.resolve(__dirname, 'src/js', 'payDetail.js'),
  33. deptScoreDetail: path.resolve(__dirname, 'src/js', 'deptScoreDetail.js'),
  34. deptScoreDetailControl: path.resolve(__dirname, 'src/js', 'deptScoreDetailControl.js'),
  35. jiaji: path.resolve(__dirname, 'src/js', 'jiaji.js'),
  36. partDetailControl: path.resolve(__dirname, 'src/js', 'partDetailControl.js'),
  37. quexianXQ: path.resolve(__dirname, 'src/js', 'quexianXQ.js'),
  38. vendor: 'lodash'// 多个页面所需的公共库文件,防止重复打包带入
  39. },
  40. output: {
  41. publicPath: '/', //这里要放的是静态资源CDN的地址
  42. path: path.resolve(__dirname, 'dist'),
  43. filename: 'js/[name].js'
  44. },
  45. resolve: {
  46. extensions: [".js", ".css", ".json"],
  47. alias: {} //配置别名可以加快webpack查找模块的速度
  48. },
  49. plugins: [//多入口的html文件用chunks这个参数来区分
  50. new HtmlWebpackPlugin({
  51. title: 'index',
  52. template: path.resolve(__dirname, 'src/html', 'index.html'),
  53. filename: 'index.html',
  54. chunks: ['index', 'vendor', 'common'],
  55. hash: true, //防止缓存
  56. inject: true,
  57. minify: {
  58. removeAttributeQuotes: true, //压缩 去掉引号
  59. removeComments: true, //移除HTML中的注释
  60. collapseWhitespace: true //删除空白符与换行符
  61. }
  62. }),
  63. new HtmlWebpackPlugin({
  64. title: 'console.html',
  65. template: path.resolve(__dirname, 'src/html', 'console.html'),
  66. filename: 'console.html',
  67. chunks: ['console', 'vendor', 'common'],
  68. hash: true, //防止缓存
  69. inject: true,
  70. minify: {
  71. removeAttributeQuotes: true, //压缩 去掉引号
  72. removeComments: true, //移除HTML中的注释
  73. collapseWhitespace: true //删除空白符与换行符
  74. }
  75. }),
  76. new HtmlWebpackPlugin({
  77. title: 'quexianXQ.html',
  78. template: path.resolve(__dirname, 'src/html', 'quexianXQ.html'),
  79. filename: 'quexianXQ.html',
  80. chunks: ['quexianXQ', 'vendor', 'common'],
  81. hash: true, //防止缓存
  82. inject: true,
  83. minify: {
  84. removeAttributeQuotes: true, //压缩 去掉引号
  85. removeComments: true, //移除HTML中的注释
  86. collapseWhitespace: true //删除空白符与换行符
  87. }
  88. }),
  89. new HtmlWebpackPlugin({
  90. title: 'partDetailControl.html',
  91. template: path.resolve(__dirname, 'src/html', 'partDetailControl.html'),
  92. filename: 'partDetailControl.html',
  93. chunks: ['partDetailControl', 'vendor', 'common'],
  94. hash: true, //防止缓存
  95. inject: true,
  96. minify: {
  97. removeAttributeQuotes: true, //压缩 去掉引号
  98. removeComments: true, //移除HTML中的注释
  99. collapseWhitespace: true //删除空白符与换行符
  100. }
  101. }),
  102. new HtmlWebpackPlugin({
  103. title: 'jiaji.html',
  104. template: path.resolve(__dirname, 'src/html', 'jiaji.html'),
  105. filename: 'jiaji.html',
  106. chunks: ['jiaji', 'vendor', 'common'],
  107. hash: true, //防止缓存
  108. inject: true,
  109. minify: {
  110. removeAttributeQuotes: true, //压缩 去掉引号
  111. removeComments: true, //移除HTML中的注释
  112. collapseWhitespace: true //删除空白符与换行符
  113. }
  114. }),
  115. new HtmlWebpackPlugin({
  116. title: 'abnormal.html',
  117. template: path.resolve(__dirname, 'src/html', 'abnormal.html'),
  118. filename: 'abnormal.html',
  119. chunks: ['abnormal', 'vendor', 'common'],
  120. hash: true, //防止缓存
  121. inject: true,
  122. minify: {
  123. removeAttributeQuotes: true, //压缩 去掉引号
  124. removeComments: true, //移除HTML中的注释
  125. collapseWhitespace: true //删除空白符与换行符
  126. }
  127. }),
  128. new HtmlWebpackPlugin({
  129. title: 'deptScoreDetailControl.html',
  130. template: path.resolve(__dirname, 'src/html', 'deptScoreDetailControl.html'),
  131. filename: 'deptScoreDetailControl.html',
  132. chunks: ['deptScoreDetailControl', 'vendor', 'common'],
  133. hash: true, //防止缓存
  134. inject: true,
  135. minify: {
  136. removeAttributeQuotes: true, //压缩 去掉引号
  137. removeComments: true, //移除HTML中的注释
  138. collapseWhitespace: true //删除空白符与换行符
  139. }
  140. }),
  141. new HtmlWebpackPlugin({
  142. title: 'payDetail.html',
  143. template: path.resolve(__dirname, 'src/html', 'payDetail.html'),
  144. filename: 'payDetail.html',
  145. chunks: ['payDetail', 'vendor', 'common'],
  146. hash: true, //防止缓存
  147. inject: true,
  148. minify: {
  149. removeAttributeQuotes: true, //压缩 去掉引号
  150. removeComments: true, //移除HTML中的注释
  151. collapseWhitespace: true //删除空白符与换行符
  152. }
  153. }),
  154. new HtmlWebpackPlugin({
  155. title: 'partDetail.html',
  156. template: path.resolve(__dirname, 'src/html', 'partDetail.html'),
  157. filename: 'partDetail.html',
  158. chunks: ['partDetail', 'vendor', 'common'],
  159. hash: true, //防止缓存
  160. inject: true,
  161. minify: {
  162. removeAttributeQuotes: true, //压缩 去掉引号
  163. removeComments: true, //移除HTML中的注释
  164. collapseWhitespace: true //删除空白符与换行符
  165. }
  166. }),
  167. new HtmlWebpackPlugin({
  168. title: 'dayDetail.html',
  169. template: path.resolve(__dirname, 'src/html', 'dayDetail.html'),
  170. filename: 'dayDetail.html',
  171. chunks: ['dayDetail', 'vendor', 'common'],
  172. hash: true, //防止缓存
  173. inject: true,
  174. minify: {
  175. removeAttributeQuotes: true, //压缩 去掉引号
  176. removeComments: true, //移除HTML中的注释
  177. collapseWhitespace: true //删除空白符与换行符
  178. }
  179. }),
  180. new HtmlWebpackPlugin({
  181. title: 'deptScoreDetail.html',
  182. template: path.resolve(__dirname, 'src/html', 'deptScoreDetail.html'),
  183. filename: 'deptScoreDetail.html',
  184. chunks: ['deptScoreDetail', 'vendor', 'common'],
  185. hash: true, //防止缓存
  186. inject: true,
  187. minify: {
  188. removeAttributeQuotes: true, //压缩 去掉引号
  189. removeComments: true, //移除HTML中的注释
  190. collapseWhitespace: true //删除空白符与换行符
  191. }
  192. }),
  193. new HtmlWebpackPlugin({
  194. title: 'deptConsole.html',
  195. template: path.resolve(__dirname, 'src/html', 'deptConsole.html'),
  196. filename: 'deptConsole.html',
  197. chunks: ['deptConsole', 'vendor', 'common'],
  198. hash: true, //防止缓存
  199. inject: true,
  200. minify: {
  201. removeAttributeQuotes: true, //压缩 去掉引号
  202. removeComments: true, //移除HTML中的注释
  203. collapseWhitespace: true //删除空白符与换行符
  204. }
  205. }),
  206. new HtmlWebpackPlugin({
  207. title: 'itemManager.html',
  208. template: path.resolve(__dirname, 'src/html', 'itemManager.html'),
  209. filename: 'itemManager.html',
  210. chunks: ['itemManager', 'vendor', 'common'],
  211. hash: true, //防止缓存
  212. inject: true,
  213. minify: {
  214. removeAttributeQuotes: true, //压缩 去掉引号
  215. removeComments: true, //移除HTML中的注释
  216. collapseWhitespace: true //删除空白符与换行符
  217. }
  218. }),
  219. new HtmlWebpackPlugin({
  220. title: 'moduleManager.html',
  221. template: path.resolve(__dirname, 'src/html', 'moduleManager.html'),
  222. filename: 'moduleManager.html',
  223. chunks: ['moduleManager', 'vendor', 'common'],
  224. hash: true, //防止缓存
  225. inject: true,
  226. minify: {
  227. removeAttributeQuotes: true, //压缩 去掉引号
  228. removeComments: true, //移除HTML中的注释
  229. collapseWhitespace: true //删除空白符与换行符
  230. }
  231. }),
  232. new HtmlWebpackPlugin({
  233. title: 'tiaomu.html',
  234. template: path.resolve(__dirname, 'src/html', 'tiaomu.html'),
  235. filename: 'tiaomu.html',
  236. chunks: ['tiaomu', 'vendor', 'common'],
  237. hash: true, //防止缓存
  238. inject: true,
  239. minify: {
  240. removeAttributeQuotes: true, //压缩 去掉引号
  241. removeComments: true, //移除HTML中的注释
  242. collapseWhitespace: true //删除空白符与换行符
  243. }
  244. }),
  245. new HtmlWebpackPlugin({
  246. title: 'mukuai.html',
  247. template: path.resolve(__dirname, 'src/html', 'mukuai.html'),
  248. filename: 'mukuai.html',
  249. chunks: ['mukuai', 'vendor', 'common'],
  250. hash: true, //防止缓存
  251. inject: true,
  252. minify: {
  253. removeAttributeQuotes: true, //压缩 去掉引号
  254. removeComments: true, //移除HTML中的注释
  255. collapseWhitespace: true //删除空白符与换行符
  256. }
  257. }),
  258. new HtmlWebpackPlugin({
  259. title: 'login.html',
  260. template: path.resolve(__dirname, 'src/html', 'login.html'),
  261. filename: 'login.html',
  262. chunks: ['login', 'vendor', 'common'],
  263. hash: true, //防止缓存
  264. inject: true,
  265. minify: {
  266. removeAttributeQuotes: true, //压缩 去掉引号
  267. removeComments: true, //移除HTML中的注释
  268. collapseWhitespace: true //删除空白符与换行符
  269. }
  270. }),
  271. new HtmlWebpackPlugin({
  272. title: 'qcList.html',
  273. template: path.resolve(__dirname, 'src/html', 'qcList.html'),
  274. filename: 'qcList.html',
  275. chunks: ['qcList', 'vendor', 'common'],
  276. hash: true, //防止缓存
  277. inject: true,
  278. minify: {
  279. removeAttributeQuotes: true, //压缩 去掉引号
  280. removeComments: true, //移除HTML中的注释
  281. collapseWhitespace: true //删除空白符与换行符
  282. }
  283. }),
  284. new HtmlWebpackPlugin({
  285. title: 'qcListPerson.html',
  286. template: path.resolve(__dirname, 'src/html', 'qcListPerson.html'),
  287. filename: 'qcListPerson.html',
  288. chunks: ['qcListPerson', 'vendor', 'common'],
  289. hash: true, //防止缓存
  290. inject: true,
  291. minify: {
  292. removeAttributeQuotes: true, //压缩 去掉引号
  293. removeComments: true, //移除HTML中的注释
  294. collapseWhitespace: true //删除空白符与换行符
  295. }
  296. }),
  297. new HtmlWebpackPlugin({
  298. title: 'qcListDept.html',
  299. template: path.resolve(__dirname, 'src/html', 'qcListDept.html'),
  300. filename: 'qcListDept.html',
  301. chunks: ['qcListDept', 'vendor', 'common'],
  302. hash: true, //防止缓存
  303. inject: true,
  304. minify: {
  305. removeAttributeQuotes: true, //压缩 去掉引号
  306. removeComments: true, //移除HTML中的注释
  307. collapseWhitespace: true //删除空白符与换行符
  308. }
  309. }),
  310. new HtmlWebpackPlugin({
  311. title: 'qcScore.html',
  312. template: path.resolve(__dirname, 'src/html', 'qcScore.html'),
  313. filename: 'qcScore.html',
  314. chunks: [ 'qcScore','vendor', 'common'],
  315. hash: true, //防止缓存
  316. inject: true,
  317. minify: {
  318. removeAttributeQuotes: true, //压缩 去掉引号
  319. removeComments: true, //移除HTML中的注释
  320. collapseWhitespace: true //删除空白符与换行符
  321. }
  322. }),
  323. new HtmlWebpackPlugin({
  324. title: 'statistics.html',
  325. template: path.resolve(__dirname, 'src/html', 'statistics.html'),
  326. filename: 'statistics.html',
  327. chunks: ['index', 'vendor', 'common'],
  328. hash: true, //防止缓存
  329. inject: true,
  330. minify: {
  331. removeAttributeQuotes: true, //压缩 去掉引号
  332. removeComments: true, //移除HTML中的注释
  333. collapseWhitespace: true //删除空白符与换行符
  334. }
  335. }),
  336. new HtmlWebpackPlugin({
  337. title: 'userManager.html',
  338. template: path.resolve(__dirname, 'src/html', 'userManager.html'),
  339. filename: 'userManager.html',
  340. chunks: ['userManager', 'vendor', 'common'],
  341. hash: true, //防止缓存
  342. inject: true,
  343. minify: {
  344. removeAttributeQuotes: true, //压缩 去掉引号
  345. removeComments: true, //移除HTML中的注释
  346. collapseWhitespace: true //删除空白符与换行符
  347. }
  348. }),
  349. new HtmlWebpackPlugin({
  350. title: 'roleManager.html',
  351. template: path.resolve(__dirname, 'src/html', 'roleManager.html'),
  352. filename: 'roleManager.html',
  353. chunks: ['roleManager', 'vendor', 'common'],
  354. hash: true, //防止缓存
  355. inject: true,
  356. minify: {
  357. removeAttributeQuotes: true, //压缩 去掉引号
  358. removeComments: true, //移除HTML中的注释
  359. collapseWhitespace: true //删除空白符与换行符
  360. }
  361. }),
  362. new CopyWebpackPlugin([
  363. {
  364. from:'src/resource',
  365. to:path.resolve(__dirname,'dist','resource'),
  366. flatten:true, //false会拷贝原始文件夹路径
  367. }
  368. ]),
  369. new MiniCssExtractPlugin({
  370. filename: 'css/[name].css',
  371. chunkFilename: '[id].css'
  372. }),
  373. new webpack.HotModuleReplacementPlugin(),
  374. new CleanWebpackPlugin()
  375. ],
  376. optimization: { //webpack4.x的最新优化配置项,用于提取公共代码
  377. minimizer: [
  378. new UglifyJsPlugin({
  379. uglifyOptions: {
  380. ie8: true,
  381. compress: {
  382. properties: false,
  383. warnings: false
  384. },
  385. mangle: {
  386. screw_ie8: false,
  387. except: ['e']
  388. },
  389. output: {
  390. beautify: true
  391. },
  392. sourceMap: false
  393. }
  394. })
  395. ],
  396. splitChunks: {
  397. cacheGroups: {
  398. commons: {
  399. chunks: "initial",
  400. name: "common",
  401. minChunks: 2,
  402. maxInitialRequests: 5, // The default limit is too small to showcase the effect
  403. minSize: 0, // This is example is too small to create commons chunks
  404. reuseExistingChunk: true // 可设置是否重用该chunk
  405. }
  406. }
  407. }
  408. },
  409. module: {
  410. noParse: /WdatePicker/,
  411. rules: [
  412. {
  413. test: /.js$/,
  414. enforce: 'post',
  415. loader: 'es3ify-loader'
  416. },
  417. {
  418. test: /\.m?js$/,
  419. exclude: /(node_modules|bower_components)/,
  420. use: {
  421. loader: 'babel-loader',
  422. options: {
  423. presets:['@babel/preset-env']
  424. }
  425. }
  426. },
  427. {
  428. test: /\.css$/,
  429. use: [{
  430. loader: MiniCssExtractPlugin.loader
  431. },
  432. 'css-loader'
  433. ]
  434. },
  435. {
  436. test: /\.less$/,
  437. use: [{
  438. loader: MiniCssExtractPlugin.loader
  439. },
  440. 'css-loader', 'less-loader'
  441. ]
  442. },
  443. {
  444. test:/\.(png|gif|jpg|jpeg|svg|eot|ttf|woff|woff2)$/,
  445. use:[{
  446. loader:'url-loader',
  447. options:{
  448. limit:10240,
  449. esModule:false,
  450. name:'[name]_[hash:6].[ext]',
  451. outputPath:'images/'
  452. }
  453. }],
  454. exclude:/node_modules/
  455. },{
  456. test:/.html$/,
  457. use:'html-withimg-loader'
  458. }
  459. ]
  460. },
  461. // devtool: 'cheap-module-eval-source-map', //开发环境cheap-module-eval-source-map //生产环境cheap-module-source-map
  462. mode: 'development',
  463. devServer: {
  464. contentBase: "./dist", //静态文件根目录
  465. proxy: {
  466. '/': proxyHost
  467. },
  468. hot: true,
  469. openPage:'login.html'
  470. }
  471. }