webpack.config.js 13 KB

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