vue.config.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const GitRevisionPlugin = require('git-revision-webpack-plugin')
  4. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  5. const GitRevision = new GitRevisionPlugin()
  6. const buildDate = JSON.stringify(new Date().toLocaleString())
  7. const createThemeColorReplacerPlugin = require('./config/plugin.config')
  8. const theme = require('./src/config/theme.config')
  9. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
  10. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  11. const productionGzipExtensions = ['js', 'css']
  12. const webpackPlatformSetting = require('plg-platform-setting/webpack-plugin')
  13. const tmsScript = require('./script.js')
  14. const baseTarget = 'http://tms-jxqn.upcloud.plg.com/api'//标准版环境
  15. const textBaseTarget = 'http://192.168.1.88:30875' // 逸飞
  16. //target: 'http://192.168.1.206:7002', // 正方体
  17. function resolve(dir) {
  18. return path.join(__dirname, dir)
  19. }
  20. // check Git
  21. function getGitHash() {
  22. try {
  23. return GitRevision.version()
  24. } catch (e) {}
  25. return 'unknown'
  26. }
  27. const isProd = process.env.NODE_ENV === 'production'
  28. //const isProd = true
  29. const assetsCDN = {
  30. // webpack build externals
  31. externals: {
  32. vue: 'Vue',
  33. 'vue-router': 'VueRouter',
  34. vuex: 'Vuex',
  35. axios: 'axios',
  36. echarts: 'echarts',
  37. 'ant-design-vue': 'antd',
  38. plglib: 'plglib',
  39. moment: 'moment',
  40. },
  41. css: [],
  42. // https://unpkg.com/browse/vue@2.6.10/
  43. js: [
  44. '//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js',
  45. '//cdn.jsdelivr.net/npm/vue-router@3.5.2/dist/vue-router.min.js',
  46. '//cdn.jsdelivr.net/npm/vuex@3.6.2/dist/vuex.min.js',
  47. '//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js',
  48. '//cdn.jsdelivr.net/npm/moment@2.29.1/moment.min.js',
  49. '//cdn.jsdelivr.net/npm/moment@2.29.1/locale/zh-cn.js',
  50. '//cdn.jsdelivr.net/npm/ant-design-vue@1.7.8/dist/antd.min.js',
  51. '//prolog0212.vicp.cc:36872/plglib.umd.min.0.0.69.js',
  52. '//cdn.jsdelivr.net/npm/echarts@5.1.1/dist/echarts.min.js',
  53. ],
  54. }
  55. const defaultPlugins = [
  56. // Ignore all locale files of moment.js
  57. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  58. new webpack.DefinePlugin({
  59. APP_VERSION: `"${require('./package.json').version}"`,
  60. GIT_HASH: JSON.stringify(getGitHash()),
  61. BUILD_DATE: buildDate,
  62. }),
  63. new MonacoWebpackPlugin({
  64. languages: ['javascript', 'css', 'html', 'json', 'sql'],
  65. features: ['coreCommands', 'find'],
  66. }),
  67. // 下面是下载的插件的配置
  68. new CompressionWebpackPlugin({
  69. algorithm: 'gzip',
  70. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  71. threshold: 10240,
  72. minRatio: 0.6,
  73. }),
  74. new webpackPlatformSetting(),
  75. ]
  76. if (process.env.NODE_ENV === 'production') {
  77. defaultPlugins.push(createThemeColorReplacerPlugin())
  78. // defaultPlugins.push(
  79. // new webpack.optimize.LimitChunkCountPlugin({
  80. // maxChunks: 5,
  81. // minChunkSize: 100,
  82. // })
  83. // )
  84. }
  85. /**依赖大小分析工具 npm run build:preview */
  86. process.env.MODE == 'preview' ? defaultPlugins.push(new BundleAnalyzerPlugin()) : null
  87. // defaultPlugins.push( new MonacoWebpackPlugin({
  88. // languages: ['sql'],
  89. // features: [],
  90. // publicPath: '/'}
  91. // ));
  92. // vue.config.js
  93. const vueConfig = {
  94. configureWebpack: {
  95. optimization: {
  96. splitChunks: {
  97. cacheGroups: {
  98. JQPage: {
  99. name: 'JQPage',
  100. priority: -100,
  101. chunks:'initial',
  102. test: /(.*([\\/]JQ_Page[\\/]js)+?.*).js$/,
  103. enforce: true,
  104. reuseExistingChunk:true
  105. }
  106. }
  107. }
  108. },
  109. // webpack plugins
  110. devtool:!isProd&&'source-map',
  111. plugins: defaultPlugins,
  112. // if prod, add externals
  113. externals: process.env.MODE == 'cdn' ? assetsCDN.externals : {},
  114. },
  115. filenameHashing: true, //去掉文件名后的hash
  116. chainWebpack: (config) => {
  117. config.resolve.alias.set('@$', resolve('src')).set('jq', resolve('public/jq')).set('@plglib', resolve('__plglib/packages'))
  118. // console.log('NODE_ENV', process.env)
  119. if (process.env.NODE_ENV == 'plglib') {
  120. /**用于联调测试组件库的开发模式 */
  121. //console.log('PLGLIB_PATH', process.env.PLGLIB_PATH)
  122. config.resolve.alias.set('plglib', resolve('_plglib'))
  123. }
  124. // config.plugin('monaco').use(new MonacoWebpackPlugin())
  125. // /\.(html)(\?.*)?$/
  126. const svgRule = config.module.rule('svg');
  127. svgRule.uses.clear();
  128. svgRule
  129. .oneOf('inline')
  130. .resourceQuery(/inline/)
  131. .use('vue-svg-icon-loader')
  132. .loader('vue-svg-icon-loader')
  133. .end()
  134. .end()
  135. .oneOf('external')
  136. .use('file-loader')
  137. .loader('file-loader')
  138. .options({
  139. name: 'assets/[name].[hash:8].[ext]',
  140. })
  141. // if prod is on
  142. // assets require on cdn`
  143. if (process.env.MODE == 'cdn') {
  144. config.plugin('html').tap((args) => {
  145. args[0].cdn = assetsCDN
  146. return args
  147. })
  148. }
  149. config.plugin('html').tap((args) => {
  150. args[0].scripts = tmsScript.scripts
  151. args[0].links = tmsScript.links
  152. return args
  153. })
  154. config.plugins.delete('prefetch')
  155. // 去除生产环境下的 console
  156. if (isProd) {
  157. // config.optimization.minimizer('terser').tap((options) => {
  158. // options[0].terserOptions.compress.drop_console = true
  159. // return options
  160. // })
  161. }
  162. config.module
  163. .rule('jqhtml')
  164. .test(/(.*([\\/]JQ_Page[\\/]pages)+?.*).html$/)
  165. .use('html-loader')
  166. .loader('html-loader')
  167. .end();
  168. //config.optimization.splitChunks
  169. },
  170. css: {
  171. sourceMap: !isProd,
  172. loaderOptions: {
  173. less: {
  174. sourceMap: !isProd,
  175. modifyVars: {
  176. // less vars,customize ant design theme
  177. // 'primary-color': '#F5222D',
  178. // 'link-color': '#F5222D',
  179. 'border-radius-base': '2px',
  180. ...theme,
  181. },
  182. // DO NOT REMOVE THIS LINE
  183. javascriptEnabled: true,
  184. },
  185. },
  186. },
  187. devServer: {
  188. // development server port 8000
  189. port: 8001,
  190. proxy: {
  191. '/api': {
  192. target: baseTarget, // 云仓
  193. pathRewrite: {
  194. '^/api': '',
  195. },
  196. },
  197. '/images-host': {
  198. target: 'http://fe-file.upcloud.plg.com/files/', //图片host
  199. pathRewrite: {
  200. '^/images-host': '',
  201. },
  202. },
  203. '/textApi': {
  204. target: textBaseTarget, //测试代理
  205. pathRewrite: {
  206. '^/textApi': '',
  207. },
  208. },
  209. // UPCLOUD_RDC_TMS_MAINDATA_SERVICE:'/api/upcloud-rdc-tms-maindata-service',
  210. // UPCLOUD_RDC_TMS_BUSINESS_SERVICE:'/api/upcloud-rdc-tms-business-service'
  211. '/business': {
  212. target: baseTarget + '/upcloud-rdc-tms-business-service',
  213. pathRewrite: {
  214. '^/business': '',
  215. },
  216. },
  217. '/maindata': {
  218. target: baseTarget + '/upcloud-rdc-tms-maindata-service',
  219. pathRewrite: {
  220. '^/maindata': '',
  221. },
  222. }
  223. },
  224. },
  225. // disable source map in production
  226. productionSourceMap: !isProd,
  227. lintOnSave: false,
  228. // babel-loader no-ignore node_modules/*
  229. transpileDependencies: [],
  230. /* 设计器运行时编译需要 */
  231. runtimeCompiler: true,
  232. }
  233. module.exports = vueConfig