pages.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. const projectName = require('./project');
  2. const path = require('path');
  3. const CompressionWebpackPlugin = require("compression-webpack-plugin")
  4. const productionGzipExtensions = ['js', 'css']
  5. function resolve(dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. let title = '';
  9. if (process.env.VUE_APP_NODE_NAME == 'production') {
  10. title = ''
  11. } else if (process.env.VUE_APP_NODE_NAME == 'test') {
  12. title = '(测试)'
  13. } else {
  14. title = '(开发)'
  15. }
  16. const Timestamp = new Date().getTime();
  17. const config = {
  18. //商业园区
  19. business: {
  20. pages: {
  21. index: {
  22. entry: 'src/projects/business/main.js',
  23. template: 'index/business/index.html',
  24. filename: 'index.html',
  25. title: '小鹏管家' + title,
  26. }
  27. },
  28. outputDir: 'dist/business',
  29. devServer: {
  30. host: '0.0.0.0',
  31. port: 80,
  32. //解析缓存
  33. disableHostCheck: true,
  34. //支持gzip
  35. compress: true,
  36. },
  37. chainWebpack: (config) => {
  38. config.entry.app = ['babel-polyfill', '../src/projects/business/main.js']
  39. config.resolve.alias
  40. .set('@', resolve('../src/projects/business/'))
  41. .set('$project', resolve('../src/'))
  42. .set('$root', resolve('../'))
  43. config.plugins.delete('preload-index');
  44. config.plugins.delete('prefetch-index');
  45. config.optimization.minimize(true);
  46. //打包分析添加
  47. //config.output.filename('js/[name].[hash].js').end();
  48. //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  49. },
  50. configureWebpack: config => {
  51. //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  52. config.plugins.push(
  53. new CompressionWebpackPlugin({
  54. algorithm: 'gzip', //开启gzip
  55. test: /\.js$|\.html$|.\css/, // 匹配文件名
  56. threshold: 10240, // 对超过10k的数据压缩
  57. deleteOriginalAssets: false // 不删除源文件
  58. })
  59. );
  60. config.output.filename = `./static/js/[name].${Timestamp}.js`
  61. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  62. config.performance = {
  63. hints: 'warning',
  64. //入口起点的最大体积 整数类型(以字节为单位)
  65. maxEntrypointSize: 50000000,
  66. //生成文件的最大体积 整数类型(以字节为单位 300k)
  67. maxAssetSize: 30000000,
  68. //只给出 js 文件的性能提示
  69. assetFilter: function(assetFilename) {
  70. return assetFilename.endsWith('.js');
  71. }
  72. }
  73. },
  74. },
  75. //住宅小区
  76. residence: {
  77. pages: {
  78. index: {
  79. entry: 'src/projects/residence/main.js',
  80. template: 'index/residence/index.html',
  81. filename: 'index.html',
  82. title: '小鹏管家' + title,
  83. }
  84. },
  85. outputDir: 'dist/residence',
  86. devServer: {
  87. host: '0.0.0.0',
  88. port: 8080,
  89. //解析缓存
  90. disableHostCheck: true,
  91. //支持gzip
  92. compress: true,
  93. },
  94. chainWebpack: (config) => {
  95. config.entry.app = ['babel-polyfill', '../src/projects/residence/main.js']
  96. config.resolve.alias
  97. .set('@', resolve('../src/projects/residence/'))
  98. .set('$project', resolve('../src/'))
  99. .set('$root', resolve('../'))
  100. config.plugins.delete('preload-index');
  101. config.plugins.delete('prefetch-index');
  102. config.optimization.minimize(true);
  103. //打包分析添加
  104. //config.output.filename('js/[name].[hash].js').end();
  105. //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  106. },
  107. configureWebpack: (config) => {
  108. //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  109. config.plugins.push(
  110. new CompressionWebpackPlugin({
  111. algorithm: 'gzip', //开启gzip
  112. test: /\.js$|\.html$|.\css/, // 匹配文件名
  113. threshold: 10240, // 对超过10k的数据压缩
  114. deleteOriginalAssets: false // 不删除源文件
  115. })
  116. );
  117. config.output.filename = `./static/js/[name].${Timestamp}.js`
  118. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  119. config.performance = {
  120. hints: 'warning',
  121. //入口起点的最大体积 整数类型(以字节为单位)
  122. maxEntrypointSize: 50000000,
  123. //生成文件的最大体积 整数类型(以字节为单位 300k)
  124. maxAssetSize: 30000000,
  125. //只给出 js 文件的性能提示
  126. assetFilter: function(assetFilename) {
  127. return assetFilename.endsWith('.js');
  128. }
  129. }
  130. },
  131. },
  132. //机构/居家养老
  133. pension: {
  134. pages: {
  135. index: {
  136. entry: 'src/projects/pension/main.js',
  137. template: 'index/pension/index.html',
  138. filename: 'index.html',
  139. title: '小鹏管家' + title,
  140. }
  141. },
  142. outputDir: 'dist/pension',
  143. devServer: {
  144. host: '0.0.0.0',
  145. port: 8080,
  146. //解析缓存
  147. disableHostCheck: true,
  148. //支持gzip
  149. compress: true,
  150. },
  151. chainWebpack: (config) => {
  152. config.entry.app = ['babel-polyfill', '../src/projects/pension/main.js']
  153. config.resolve.alias
  154. .set('@', resolve('../src/projects/pension/'))
  155. .set('$project', resolve('../src/'))
  156. .set('$root', resolve('../'))
  157. config.plugins.delete('preload-index');
  158. config.plugins.delete('prefetch-index');
  159. config.optimization.minimize(true);
  160. //打包分析添加
  161. //config.output.filename('js/[name].[hash].js').end();
  162. //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  163. },
  164. configureWebpack: (config) => {
  165. //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  166. config.plugins.push(
  167. new CompressionWebpackPlugin({
  168. algorithm: 'gzip', //开启gzip
  169. test: /\.js$|\.html$|.\css/, // 匹配文件名
  170. threshold: 10240, // 对超过10k的数据压缩
  171. deleteOriginalAssets: false // 不删除源文件
  172. })
  173. );
  174. config.output.filename = `./static/js/[name].${Timestamp}.js`
  175. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  176. config.performance = {
  177. hints: 'warning',
  178. //入口起点的最大体积 整数类型(以字节为单位)
  179. maxEntrypointSize: 50000000,
  180. //生成文件的最大体积 整数类型(以字节为单位 300k)
  181. maxAssetSize: 30000000,
  182. //只给出 js 文件的性能提示
  183. assetFilter: function(assetFilename) {
  184. return assetFilename.endsWith('.js');
  185. }
  186. }
  187. },
  188. },
  189. //入口
  190. home: {
  191. pages: {
  192. index: {
  193. entry: 'src/projects/home/main.js',
  194. template: 'index/home/index.html',
  195. filename: 'index.html',
  196. title: '小鹏管家' + title,
  197. }
  198. },
  199. outputDir: 'dist/home',
  200. devServer: {
  201. host: '0.0.0.0',
  202. port: 8080,
  203. //解析缓存
  204. disableHostCheck: true,
  205. //支持gzip
  206. compress: true,
  207. },
  208. chainWebpack: (config) => {
  209. config.entry.app = ['babel-polyfill', '../src/projects/home/main.js']
  210. config.resolve.alias
  211. .set('@', resolve('../src/projects/home/'))
  212. .set('$project', resolve('../src/'))
  213. .set('$root', resolve('../'))
  214. config.plugins.delete('preload-index');
  215. config.plugins.delete('prefetch-index');
  216. config.optimization.minimize(true);
  217. //打包分析添加
  218. //config.output.filename('js/[name].[hash].js').end();
  219. //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  220. },
  221. configureWebpack: (config) => {
  222. //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  223. config.plugins.push(
  224. new CompressionWebpackPlugin({
  225. algorithm: 'gzip', //开启gzip
  226. test: /\.js$|\.html$|.\css/, // 匹配文件名
  227. threshold: 10240, // 对超过10k的数据压缩
  228. deleteOriginalAssets: false // 不删除源文件
  229. })
  230. );
  231. config.output.filename = `./static/js/[name].${Timestamp}.js`
  232. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  233. config.performance = {
  234. hints: 'warning',
  235. //入口起点的最大体积 整数类型(以字节为单位)
  236. maxEntrypointSize: 50000000,
  237. //生成文件的最大体积 整数类型(以字节为单位 300k)
  238. maxAssetSize: 30000000,
  239. //只给出 js 文件的性能提示
  240. assetFilter: function(assetFilename) {
  241. return assetFilename.endsWith('.js');
  242. }
  243. }
  244. },
  245. },
  246. //停车收费
  247. parking: {
  248. pages: {
  249. index: {
  250. entry: 'src/projects/parking/main.js',
  251. template: 'index/parking/index.html',
  252. filename: 'index.html',
  253. title: '小鹏管家停车收费' + title,
  254. }
  255. },
  256. outputDir: 'dist/parking',
  257. devServer: {
  258. host: '0.0.0.0',
  259. port: 8080,
  260. //解析缓存
  261. disableHostCheck: true,
  262. //支持gzip
  263. compress: true,
  264. },
  265. chainWebpack: (config) => {
  266. config.entry.app = ['babel-polyfill', '../src/projects/parking/main.js']
  267. config.resolve.alias
  268. .set('@', resolve('../src/projects/parking/'))
  269. .set('$project', resolve('../src/'))
  270. .set('$root', resolve('../'))
  271. config.plugins.delete('preload-index');
  272. config.plugins.delete('prefetch-index');
  273. config.optimization.minimize(true);
  274. //打包分析添加
  275. //config.output.filename('js/[name].[hash].js').end();
  276. //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  277. },
  278. configureWebpack: config => {
  279. //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  280. config.plugins.push(
  281. new CompressionWebpackPlugin({
  282. algorithm: 'gzip', //开启gzip
  283. test: /\.js$|\.html$|.\css/, // 匹配文件名
  284. threshold: 10240, // 对超过10k的数据压缩
  285. deleteOriginalAssets: false // 不删除源文件
  286. })
  287. );
  288. config.output.filename = `./static/js/[name].${Timestamp}.js`
  289. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  290. config.performance = {
  291. hints: 'warning',
  292. //入口起点的最大体积 整数类型(以字节为单位)
  293. maxEntrypointSize: 50000000,
  294. //生成文件的最大体积 整数类型(以字节为单位 300k)
  295. maxAssetSize: 30000000,
  296. //只给出 js 文件的性能提示
  297. assetFilter: function(assetFilename) {
  298. return assetFilename.endsWith('.js');
  299. }
  300. }
  301. },
  302. }
  303. }
  304. const configObj = config[projectName.name]
  305. module.exports = configObj