webpack.config.js 15 KB

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