webpack.config.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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://173.18.12.195:6060";
  8. //const proxyHost = "http://173.18.12.192:6060";
  9. module.exports = {
  10. entry: {
  11. //index: path.resolve(__dirname, 'src/js', 'index.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. //staticSearch: path.resolve(__dirname, 'src/js', 'staticSearch.js'),
  18. emergency: path.resolve(__dirname, 'src/js', 'emergency.js'),
  19. cdss: path.resolve(__dirname, 'src/js', 'cdss.js'),
  20. cdssHorizontal: path.resolve(__dirname, 'src/js', 'cdssHorizontal.js'),
  21. smartAlert: path.resolve(__dirname, 'src/js', 'smartAlert.js'),
  22. caseWriteStandard: path.resolve(__dirname, 'src/js', 'caseWriteStandard.js'),
  23. generalTreat: path.resolve(__dirname, 'src/js', 'generalTreat.js'),
  24. cdssPlan: path.resolve(__dirname, 'src/js', 'cdssPlan.js'),
  25. homeStatic: path.resolve(__dirname, 'src/js', 'homeStatic.js'),
  26. searchStaticList: path.resolve(__dirname, 'src/js', 'searchStaticList.js'),
  27. staticInfo: path.resolve(__dirname, 'src/js', 'staticInfo.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', 'cdssPlan.html'),
  96. filename: 'cdssPlan.html',
  97. chunks: ['cdssPlan', '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', 'caseWriteStandard.html'),
  109. filename: 'caseWriteStandard.html',
  110. chunks: ['caseWriteStandard', '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', 'generalTreat.html'),
  122. filename: 'generalTreat.html',
  123. chunks: ['generalTreat', '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: 'information',
  134. template: path.resolve(__dirname, 'src/html', 'information.html'),
  135. filename: 'information.html',
  136. chunks: ['information', '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: 'informationOut',
  147. template: path.resolve(__dirname, 'src/html', 'informationOut.html'),
  148. filename: 'informationOut.html',
  149. chunks: ['informationOut', '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: '免责声明',
  160. template: path.resolve(__dirname, 'src/html', 'disclaimer.html'),
  161. filename: 'disclaimer.html',
  162. chunks: ['vendor', 'common', 'disclaimer'],
  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', 'version.html'),
  174. filename: 'version.html',
  175. chunks: ['vendor', 'common', 'version'],
  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: 'scale',
  186. template: path.resolve(__dirname, 'src/html', 'scale.html'),
  187. filename: 'scale.html',
  188. chunks: ['vendor', 'common', 'scale'],
  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: 'emergency',
  199. template: path.resolve(__dirname, 'src/html', 'emergency.html'),
  200. filename: 'emergency.html',
  201. chunks: ['emergency', 'vendor', 'common'],
  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: 'cdss',
  212. template: path.resolve(__dirname, 'src/html', 'cdss.html'),
  213. filename: 'cdss.html',
  214. chunks: ['cdss', '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: 'cdssHorizontal',
  225. template: path.resolve(__dirname, 'src/html', 'cdssHorizontal.html'),
  226. filename: 'cdssHorizontal.html',
  227. chunks: ['cdssHorizontal', '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: 'view',
  238. template: path.resolve(__dirname, 'src/html', 'view.html'),
  239. filename: 'view.html',
  240. chunks: ['view', 'vendor', 'common'],
  241. inject: true,
  242. hash: true, //防止缓存
  243. minify: {
  244. removeAttributeQuotes: true, //压缩 去掉引号
  245. removeComments: true, //移除HTML中的注释
  246. collapseWhitespace: true //删除空白符与换行符
  247. }
  248. }),
  249. new MiniCssExtractPlugin({
  250. filename: 'css/[name].css',
  251. chunkFilename: '[id].css'
  252. }),
  253. new webpack.HotModuleReplacementPlugin(),
  254. new CleanWebpackPlugin()
  255. ],
  256. optimization: { //webpack4.x的最新优化配置项,用于提取公共代码
  257. minimizer: [
  258. new UglifyJsPlugin({
  259. uglifyOptions: {
  260. ie8: true,
  261. compress: {
  262. properties: false,
  263. warnings: false
  264. },
  265. mangle: {
  266. screw_ie8: false,
  267. except: ['e']
  268. },
  269. output: {
  270. beautify: true
  271. },
  272. sourceMap: false
  273. }
  274. })
  275. ],
  276. splitChunks: {
  277. cacheGroups: {
  278. commons: {
  279. chunks: "initial",
  280. name: "common",
  281. minChunks: 2,
  282. maxInitialRequests: 5, // The default limit is too small to showcase the effect
  283. minSize: 0, // This is example is too small to create commons chunks
  284. reuseExistingChunk: true // 可设置是否重用该chunk
  285. }
  286. }
  287. }
  288. },
  289. module: {
  290. rules: [
  291. {
  292. test: /.js$/,
  293. enforce: 'post',
  294. loader: 'es3ify-loader'
  295. },
  296. {
  297. test: /\.m?js$/,
  298. exclude: /(node_modules|bower_components)/,
  299. use: {
  300. loader: 'babel-loader',
  301. options: {
  302. presets: ['@babel/preset-env']
  303. }
  304. }
  305. },
  306. {
  307. test: /\.css$/,
  308. use: [{
  309. loader: MiniCssExtractPlugin.loader
  310. },
  311. 'css-loader'
  312. ]
  313. },
  314. {
  315. test: /\.less$/,
  316. use: [
  317. MiniCssExtractPlugin.loader,
  318. { loader: "css-loader" },
  319. { loader: "less-loader" }
  320. ]
  321. },
  322. {
  323. test: /\.(png|jpg|jpeg|gif|svg)$/,
  324. use: {
  325. loader: 'file-loader',
  326. options: {
  327. outputPath: 'images/', // 图片输出的路径和存储路径保持一致
  328. limit: 15000,
  329. name: '[name].[ext]'
  330. }
  331. }
  332. }
  333. ]
  334. },
  335. // devtool: 'cheap-module-eval-source-map', //开发环境cheap-module-eval-source-map //生产环境cheap-module-source-map
  336. mode: 'development',
  337. devServer: {
  338. contentBase: "./dist", //静态文件根目录
  339. proxy: {
  340. '/sys': proxyHost,
  341. '/lantone': "http://114.55.109.16:81",
  342. '/kl': proxyHost,
  343. },
  344. hot: true,
  345. // 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',
  346. openPage: 'homeStatic.html?mrId=200821362618001909&hospitalId=1&planCode=plan_default',
  347. disableHostCheck: true
  348. },
  349. stats: { children: false },
  350. }