webpack.config.js 12 KB

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