webpack.config.js 12 KB

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