webpack.config.js 13 KB

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