webpack.config.js 12 KB

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