webpack.config.js 15 KB

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