vue.config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const { merge } = require('webpack-merge')
  2. const { resolve } = require('path')
  3. const moment = require('moment')
  4. const { defineConfig } = require('@vue/cli-service')
  5. const tsImportPluginFactory = require('ts-import-plugin')
  6. module.exports = defineConfig({
  7. transpileDependencies: true,
  8. productionSourceMap: false, // 打包取消.map
  9. publicPath: './',
  10. pages: {
  11. indexPath: {
  12. entry: process.env.VUE_APP_ROOT + '/main.ts',
  13. template: process.env.VUE_APP_ROOT + '/index.html',
  14. filename: 'index.html',
  15. title: process.env.VUE_APP_TITLE,
  16. meta: {
  17. revised: moment(new Date()).format('v3.0.YYYYMMDDHHmmss') // 打包生成版本号
  18. }
  19. }
  20. },
  21. chainWebpack: (config) => {
  22. config.resolve.alias
  23. .set('@' + process.env.VUE_APP_ENV, resolve(__dirname, process.env.VUE_APP_ROOT))
  24. config.module
  25. .rule('ts')
  26. .use('ts-loader')
  27. .tap((options) => {
  28. options = merge(options, {
  29. transpileOnly: true,
  30. getCustomTransformers: () => ({
  31. before: [
  32. // vant 按需引入
  33. tsImportPluginFactory({
  34. libraryName: 'vant',
  35. libraryDirectory: 'es',
  36. style: true
  37. })
  38. ],
  39. compilerOptions: {
  40. module: 'es2015'
  41. }
  42. })
  43. })
  44. return options;
  45. })
  46. }
  47. })