webpack.config.js 13 KB

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