webpack.config.js 13 KB

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