webpack.config.js 17 KB

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