webpack.config.js 17 KB

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