webpack.config.js 12 KB

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