webpack.config.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const CleanWebpackPlugin = require('clean-webpack-plugin') // 清空打包目录的插件
  4. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  5. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  6. const webpack = require('webpack');
  7. const proxyHost = "http://192.168.2.241:6060";
  8. module.exports = {
  9. entry: {
  10. index: path.resolve(__dirname, 'src/js', 'index.js'),
  11. page: path.resolve(__dirname, 'src', 'page.js'),
  12. information: path.resolve(__dirname, 'src/js', 'information.js'),
  13. informationOut: path.resolve(__dirname, 'src/js', 'informationOut.js'),
  14. disclaimer: path.resolve(__dirname, 'src/js', 'disclaimer.js'),
  15. version: path.resolve(__dirname, 'src/js', 'version.js'),
  16. scale: path.resolve(__dirname, 'src/js', 'scale.js'),
  17. illness: path.resolve(__dirname, 'src/js', 'illness.js'),
  18. treatplan: path.resolve(__dirname, 'src/js', 'treatplan.js'),
  19. indexHorizontal: path.resolve(__dirname, 'src/js', 'indexHorizontal.js'),
  20. staticSearch: path.resolve(__dirname, 'src/js', 'staticSearch.js'),
  21. emergency: path.resolve(__dirname, 'src/js', 'emergency.js'),
  22. icssIndex: path.resolve(__dirname, 'src/js', 'icssIndex.js'),
  23. view: path.resolve(__dirname, 'src/js', 'view.js'),
  24. cdss: path.resolve(__dirname, 'src/js', 'cdss.js'),
  25. cdssHorizontal: path.resolve(__dirname, 'src/js', 'cdssHorizontal.js'),
  26. smartAlert: path.resolve(__dirname, 'src/js', 'smartAlert.js'),
  27. caseWriteStandard: path.resolve(__dirname, 'src/js', 'caseWriteStandard.js'),
  28. generalTreat:path.resolve(__dirname, 'src/js', 'generalTreat.js'),
  29. cdssPlan:path.resolve(__dirname, 'src/js', 'cdssPlan.js'),
  30. check:path.resolve(__dirname, 'src/js', 'check.js'),
  31. homeStatic:path.resolve(__dirname, 'src/js', 'homeStatic.js'),
  32. vendor: 'lodash'// 多个页面所需的公共库文件,防止重复打包带入
  33. },
  34. output: {
  35. publicPath: '/', //这里要放的是静态资源CDN的地址
  36. path: path.resolve(__dirname, 'dist'),
  37. filename: 'js/[name].js'
  38. },
  39. resolve: {
  40. extensions: [".js", ".css", ".json"],
  41. alias: {} //配置别名可以加快webpack查找模块的速度
  42. },
  43. plugins: [// 多入口的html文件用chunks这个参数来区分
  44. new HtmlWebpackPlugin({
  45. title: 'index',
  46. template: path.resolve(__dirname, 'src/html', 'index.html'),
  47. filename: 'index.html',
  48. chunks: ['index', 'vendor', 'common'],
  49. inject: true,
  50. hash: true, //防止缓存
  51. minify: {
  52. removeAttributeQuotes: true, //压缩 去掉引号
  53. removeComments: true, //移除HTML中的注释
  54. collapseWhitespace: true //删除空白符与换行符
  55. }
  56. }),
  57. new HtmlWebpackPlugin({
  58. title: 'homeStatic',
  59. template: path.resolve(__dirname, 'src/html', 'homeStatic.html'),
  60. filename: 'homeStatic.html',
  61. chunks: ['homeStatic', 'vendor', 'common'],
  62. inject: true,
  63. hash: true, //防止缓存
  64. minify: {
  65. removeAttributeQuotes: true, //压缩 去掉引号
  66. removeComments: true, //移除HTML中的注释
  67. collapseWhitespace: true //删除空白符与换行符
  68. }
  69. }),
  70. new HtmlWebpackPlugin({
  71. title: 'index',
  72. template: path.resolve(__dirname, 'src/html', 'check.html'),
  73. filename: 'check.html',
  74. chunks: ['check', 'vendor', 'common'],
  75. inject: true,
  76. hash: true, //防止缓存
  77. minify: {
  78. removeAttributeQuotes: true, //压缩 去掉引号
  79. removeComments: true, //移除HTML中的注释
  80. collapseWhitespace: true //删除空白符与换行符
  81. }
  82. }),
  83. new HtmlWebpackPlugin({
  84. title: '智能警示',
  85. template: path.resolve(__dirname, 'src/html', 'smartAlert.html'),
  86. filename: 'smartAlert.html',
  87. chunks: ['smartAlert', 'vendor', 'common'],
  88. inject: true,
  89. hash: true, //防止缓存
  90. minify: {
  91. removeAttributeQuotes: true, //压缩 去掉引号
  92. removeComments: true, //移除HTML中的注释
  93. collapseWhitespace: true //删除空白符与换行符
  94. }
  95. }),
  96. new HtmlWebpackPlugin({
  97. title: '随访计划',
  98. template: path.resolve(__dirname, 'src/html', 'cdssPlan.html'),
  99. filename: 'cdssPlan.html',
  100. chunks: ['cdssPlan', 'vendor', 'common'],
  101. inject: true,
  102. hash: true, //防止缓存
  103. minify: {
  104. removeAttributeQuotes: true, //压缩 去掉引号
  105. removeComments: true, //移除HTML中的注释
  106. collapseWhitespace: true //删除空白符与换行符
  107. }
  108. }),
  109. new HtmlWebpackPlugin({
  110. title: '病历书写规范提示',
  111. template: path.resolve(__dirname, 'src/html', 'caseWriteStandard.html'),
  112. filename: 'caseWriteStandard.html',
  113. chunks: ['caseWriteStandard', 'vendor', 'common'],
  114. inject: true,
  115. hash: true, //防止缓存
  116. minify: {
  117. removeAttributeQuotes: true, //压缩 去掉引号
  118. removeComments: true, //移除HTML中的注释
  119. collapseWhitespace: true //删除空白符与换行符
  120. }
  121. }),
  122. new HtmlWebpackPlugin({
  123. title: '一般治疗',
  124. template: path.resolve(__dirname, 'src/html', 'generalTreat.html'),
  125. filename: 'generalTreat.html',
  126. chunks: ['generalTreat', 'vendor', 'common'],
  127. inject: true,
  128. hash: true, //防止缓存
  129. minify: {
  130. removeAttributeQuotes: true, //压缩 去掉引号
  131. removeComments: true, //移除HTML中的注释
  132. collapseWhitespace: true //删除空白符与换行符
  133. }
  134. }),
  135. new HtmlWebpackPlugin({
  136. title: '病情提示',
  137. template: path.resolve(__dirname, 'src/html', 'illness.html'),
  138. filename: 'illness.html',
  139. chunks: ['illness', 'vendor', 'common'],
  140. inject: true,
  141. hash: true, //防止缓存
  142. minify: {
  143. removeAttributeQuotes: true, //压缩 去掉引号
  144. removeComments: true, //移除HTML中的注释
  145. collapseWhitespace: true //删除空白符与换行符
  146. }
  147. }),
  148. new HtmlWebpackPlugin({
  149. title: '治疗方案',
  150. template: path.resolve(__dirname, 'src/html', 'treatplan.html'),
  151. filename: 'treatplan.html',
  152. chunks: ['treatplan', 'vendor', 'common'],
  153. inject: true,
  154. hash: true, //防止缓存
  155. minify: {
  156. removeAttributeQuotes: true, //压缩 去掉引号
  157. removeComments: true, //移除HTML中的注释
  158. collapseWhitespace: true //删除空白符与换行符
  159. }
  160. }),
  161. new HtmlWebpackPlugin({
  162. title: 'page',
  163. template: path.resolve(__dirname, 'src/html', 'page.html'),
  164. filename: 'page.html',
  165. chunks: ['page', 'vendor', 'common'],
  166. inject: true,
  167. hash: true, //防止缓存
  168. minify: {
  169. removeAttributeQuotes: true, //压缩 去掉引号
  170. removeComments: true, //移除HTML中的注释
  171. collapseWhitespace: true //删除空白符与换行符
  172. }
  173. }),
  174. new HtmlWebpackPlugin({
  175. title: 'information',
  176. template: path.resolve(__dirname, 'src/html', 'information.html'),
  177. filename: 'information.html',
  178. chunks: ['information', 'vendor', 'common'],
  179. inject: true,
  180. hash: true, //防止缓存
  181. minify: {
  182. removeAttributeQuotes: true, //压缩 去掉引号
  183. removeComments: true, //移除HTML中的注释
  184. collapseWhitespace: true //删除空白符与换行符
  185. }
  186. }),
  187. new HtmlWebpackPlugin({
  188. title: 'informationOut',
  189. template: path.resolve(__dirname, 'src/html', 'informationOut.html'),
  190. filename: 'informationOut.html',
  191. chunks: ['informationOut', 'vendor', 'common'],
  192. inject: true,
  193. hash: true, //防止缓存
  194. minify: {
  195. removeAttributeQuotes: true, //压缩 去掉引号
  196. removeComments: true, //移除HTML中的注释
  197. collapseWhitespace: true //删除空白符与换行符
  198. }
  199. }),
  200. new HtmlWebpackPlugin({
  201. title: 'drugInfo',
  202. template: path.resolve(__dirname, 'src/html', 'drugInfo.html'),
  203. filename: 'drugInfo.html',
  204. chunks: ['information', 'vendor', 'common'],
  205. inject: true,
  206. hash: true, //防止缓存
  207. minify: {
  208. removeAttributeQuotes: true, //压缩 去掉引号
  209. removeComments: true, //移除HTML中的注释
  210. collapseWhitespace: true //删除空白符与换行符
  211. }
  212. }),
  213. new HtmlWebpackPlugin({
  214. title: '免责声明',
  215. template: path.resolve(__dirname, 'src/html', 'disclaimer.html'),
  216. filename: 'disclaimer.html',
  217. chunks: ['vendor', 'common', 'disclaimer'],
  218. inject: true,
  219. hash: true, //防止缓存
  220. minify: {
  221. removeAttributeQuotes: true, //压缩 去掉引号
  222. removeComments: true, //移除HTML中的注释
  223. collapseWhitespace: true //删除空白符与换行符
  224. }
  225. }),
  226. new HtmlWebpackPlugin({
  227. title: '版本信息',
  228. template: path.resolve(__dirname, 'src/html', 'version.html'),
  229. filename: 'version.html',
  230. chunks: ['vendor', 'common', 'version'],
  231. inject: true,
  232. hash: true, //防止缓存
  233. minify: {
  234. removeAttributeQuotes: true, //压缩 去掉引号
  235. removeComments: true, //移除HTML中的注释
  236. collapseWhitespace: true //删除空白符与换行符
  237. }
  238. }),
  239. new HtmlWebpackPlugin({
  240. title: 'scale',
  241. template: path.resolve(__dirname, 'src/html', 'scale.html'),
  242. filename: 'scale.html',
  243. chunks: ['vendor', 'common', 'scale'],
  244. inject: true,
  245. hash: true, //防止缓存
  246. minify: {
  247. removeAttributeQuotes: true, //压缩 去掉引号
  248. removeComments: true, //移除HTML中的注释
  249. collapseWhitespace: true //删除空白符与换行符
  250. }
  251. }),
  252. new HtmlWebpackPlugin({
  253. title: 'indexHorizontal',
  254. template: path.resolve(__dirname, 'src/html', 'indexHorizontal.html'),
  255. filename: 'indexHorizontal.html',
  256. chunks: ['indexHorizontal', 'vendor', 'common'],
  257. inject: true,
  258. hash: true, //防止缓存
  259. minify: {
  260. removeAttributeQuotes: true, //压缩 去掉引号
  261. removeComments: true, //移除HTML中的注释
  262. collapseWhitespace: true //删除空白符与换行符
  263. }
  264. }),
  265. new HtmlWebpackPlugin({
  266. title: 'staticSearch',
  267. template: path.resolve(__dirname, 'src/html', 'staticSearch.html'),
  268. filename: 'staticSearch.html',
  269. chunks: ['staticSearch', 'vendor', 'common'],
  270. inject: true,
  271. hash: true, //防止缓存
  272. minify: {
  273. removeAttributeQuotes: true, //压缩 去掉引号
  274. removeComments: true, //移除HTML中的注释
  275. collapseWhitespace: true //删除空白符与换行符
  276. }
  277. }),
  278. new HtmlWebpackPlugin({
  279. title: 'emergency',
  280. template: path.resolve(__dirname, 'src/html', 'emergency.html'),
  281. filename: 'emergency.html',
  282. chunks: ['emergency', 'vendor', 'common'],
  283. inject: true,
  284. hash: true, //防止缓存
  285. minify: {
  286. removeAttributeQuotes: true, //压缩 去掉引号
  287. removeComments: true, //移除HTML中的注释
  288. collapseWhitespace: true //删除空白符与换行符
  289. }
  290. }),
  291. new HtmlWebpackPlugin({
  292. title: 'icssIndex',
  293. template: path.resolve(__dirname, 'src/html', 'icssIndex.html'),
  294. filename: 'icssIndex.html',
  295. chunks: ['icssIndex', 'vendor', 'common'],
  296. inject: true,
  297. hash: true, //防止缓存
  298. minify: {
  299. removeAttributeQuotes: true, //压缩 去掉引号
  300. removeComments: true, //移除HTML中的注释
  301. collapseWhitespace: true //删除空白符与换行符
  302. }
  303. }),
  304. new HtmlWebpackPlugin({
  305. title: 'cdss',
  306. template: path.resolve(__dirname, 'src/html', 'cdss.html'),
  307. filename: 'cdss.html',
  308. chunks: ['cdss', 'vendor', 'common'],
  309. inject: true,
  310. hash: true, //防止缓存
  311. minify: {
  312. removeAttributeQuotes: true, //压缩 去掉引号
  313. removeComments: true, //移除HTML中的注释
  314. collapseWhitespace: true //删除空白符与换行符
  315. }
  316. }),
  317. new HtmlWebpackPlugin({
  318. title: 'cdss',
  319. template: path.resolve(__dirname, 'src/html', 'cdssHorizontal.html'),
  320. filename: 'cdssHorizontal.html',
  321. chunks: ['cdssHorizontal', 'vendor', 'common'],
  322. inject: true,
  323. hash: true, //防止缓存
  324. minify: {
  325. removeAttributeQuotes: true, //压缩 去掉引号
  326. removeComments: true, //移除HTML中的注释
  327. collapseWhitespace: true //删除空白符与换行符
  328. }
  329. }),
  330. new HtmlWebpackPlugin({
  331. title: 'view',
  332. template: path.resolve(__dirname, 'src/html', 'view.html'),
  333. filename: 'view.html',
  334. chunks: ['view', 'vendor', 'common'],
  335. inject: true,
  336. hash: true, //防止缓存
  337. minify: {
  338. removeAttributeQuotes: true, //压缩 去掉引号
  339. removeComments: true, //移除HTML中的注释
  340. collapseWhitespace: true //删除空白符与换行符
  341. }
  342. }),
  343. new MiniCssExtractPlugin({
  344. filename: 'css/[name].css',
  345. chunkFilename: '[id].css'
  346. }),
  347. new webpack.HotModuleReplacementPlugin(),
  348. new CleanWebpackPlugin()
  349. ],
  350. optimization: { //webpack4.x的最新优化配置项,用于提取公共代码
  351. minimizer: [
  352. new UglifyJsPlugin({
  353. uglifyOptions: {
  354. ie8: true,
  355. compress: {
  356. properties: false,
  357. warnings: false
  358. },
  359. mangle: {
  360. screw_ie8: false,
  361. except: ['e']
  362. },
  363. output: {
  364. beautify: true
  365. },
  366. sourceMap: false
  367. }
  368. })
  369. ],
  370. splitChunks: {
  371. cacheGroups: {
  372. commons: {
  373. chunks: "initial",
  374. name: "common",
  375. minChunks: 2,
  376. maxInitialRequests: 5, // The default limit is too small to showcase the effect
  377. minSize: 0, // This is example is too small to create commons chunks
  378. reuseExistingChunk: true // 可设置是否重用该chunk
  379. }
  380. }
  381. }
  382. },
  383. module: {
  384. rules: [
  385. {
  386. test: /.js$/,
  387. enforce: 'post',
  388. loader: 'es3ify-loader'
  389. },
  390. {
  391. test: /\.m?js$/,
  392. exclude: /(node_modules|bower_components)/,
  393. use: {
  394. loader: 'babel-loader',
  395. options: {
  396. presets:['@babel/preset-env']
  397. }
  398. }
  399. },
  400. {
  401. test: /\.css$/,
  402. use: [{
  403. loader: MiniCssExtractPlugin.loader
  404. },
  405. 'css-loader'
  406. ]
  407. },
  408. {
  409. test: /\.less$/,
  410. use : [
  411. MiniCssExtractPlugin.loader,
  412. { loader: "css-loader" },
  413. { loader: "less-loader" }
  414. ]},
  415. {
  416. test: /\.(png|jpg|jpeg|gif|svg)$/,
  417. use: {
  418. loader: 'file-loader',
  419. options: {
  420. outputPath: 'images/', // 图片输出的路径和存储路径保持一致
  421. limit: 10000,
  422. name: '[name].[ext]'
  423. }
  424. }
  425. }
  426. ]
  427. },
  428. // devtool: 'cheap-module-eval-source-map', //开发环境cheap-module-eval-source-map //生产环境cheap-module-source-map
  429. mode: 'development',
  430. devServer: {
  431. contentBase: "./dist", //静态文件根目录
  432. proxy: {
  433. '*': proxyHost
  434. },
  435. hot: true,
  436. // openPage:'index.html?age=28&tipsName=血常规&tipsType=12&diseaseId=280&lisJson=&diagJson=急性胰腺炎&diseaseName=糖尿病&pastJson=无心脏病&otherJson=无高血压&pacsJson=腹部B超:无异常,%20报告日期:2019-05-07&sex=男&symptomJson=恶心呕吐腰痛&vitalJson=血压左上肢13/12mmHg&hospitalCode=A001',
  437. openPage:'homeStatic.html?mrId=200821362618001909&hospitalId=1&planCode=plan_default'
  438. },
  439. stats: { children: false }
  440. }