
const merge = require('webpack-merge');
const tsImportPluginFactory = require('ts-import-plugin');

module.exports = {
  publicPath: './',
  css: {
    loaderOptions: {
      // 给 sass-loader 传递选项
      scss: {
        // @/ 是 src/ 的别名
        // 所以这里假设你有 `src/index.sass` 这个文件
        // 注意：在 sass-loader v7 中，这个选项名是 "data"
        prependData: `@import "~@/common/index.scss";`
      },
    },
  },
  devServer: {
    disableHostCheck: true,
    proxy: {
      '^/api': {
        target: `http://172.16.101.87:${process.env.VUE_APP_CATEGORY === 'cs' ? '46788' : '46789'}`,
        pathRewrite: {
          '^/api': '/api',
        }
      }
    },
  },
  chainWebpack: config => {
    config.module
      .rule('ts')
        .use('ts-loader')
          .tap(options => {
            options = merge(options, {
              transpileOnly: true,
              getCustomTransformers: () => ({
                before: [
                  tsImportPluginFactory({
                    libraryName: 'vant',
                    libraryDirectory: 'lib',
                    style: (path) => {
                      return `${path}/style`
                    },
                  })
                ]
              }),
              compilerOptions: {
                module: 'es2015'
              }
            });
            return options;
          });
    config.module
      .rule('vue')
        .use('vue-loader')
          .tap(options => {
            options = merge(options, {
              transformAssetUrls:{
                'van-image': ['src'],
                'van-empty': ['image']
              }
            });
            return options;
          })
    config
      .plugin('html')
      .tap(args => {
        args[0].title = '溯源存证'
        return args
      });
  }
};