webpack.config.js 12 KB

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