webpack.config.js 18 KB

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