const merge = require("webpack-merge");
const tsImportPluginFactory = require("ts-import-plugin");
const version = new Date().getTime() // 全局版本号
module.exports = {
  publicPath: process.env.VUE_APP_publicPath,
  configureWebpack: {
    devtool: process.env.devtool,
    output: {
      filename: `static/js/[name].[hash:8].js`,
      chunkFilename: `static/js/[name].[hash:8].js`
    }
  },
  css: {
    extract: {
      filename: `static/css/[name].[hash:8].css`,
      chunkFilename: `static/css/[name].[hash:8].css`
    }
  },
  chainWebpack: config => {
    config.resolve.alias.set("@assets", "@/assets");

    config.module
      .rule("ts")
      .use("ts-loader")
      .tap(options => {
        options = merge(options, {
          transpileOnly: true,
          getCustomTransformers: () => ({
            before: [
              tsImportPluginFactory({
                libraryName: "vant",
                libraryDirectory: "es",
                style: true
              })
            ]
          })
        });
        return options;
      });
    config.plugin('html').tap(args => {
      args[0].meta = [
        { 'http-equiv': 'Cache-Control', content: 'no-cache, no-store, must-revalidate' },
        { 'http-equiv': 'Pragma', content: 'no-cache' },
        { 'http-equiv': 'Expires', content: '0' }
      ];
      args.forEach(arg => {
        arg.version = version
      })
      return args
    })
  },
  devServer: {
    // port: 8080,
    disableHostCheck: true, //放过域名检查
    open: true,
    proxy: {
      '/aidesign': {
        target: 'https://aidesigntest.nipponpaint.com.cn',//测试
        // target:'http://w4f596bf.natappfree.cc',
        changeOrigin: true,
        secure: true
      },
      [process.env.VUE_APP_AIDESIGN_API]: {
        target: process.env.VUE_APP_AIDESIGN,
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          ["^" + process.env.VUE_APP_AIDESIGN_API]: ""
        }
      },
    }
  }
};
