webpack.config.js 14 KB

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