1、下载ts-import-plugin
npm i -D ts-import-pulgin
2、在src同级新建vue.config.js文件
const { merge } = require("webpack-merge");
const tsImportPluginFactory = require("ts-import-plugin");
module.exports = {
lintOnSave: true,
chainWebpack: (config) => {
config.module
.rule("ts")
.use("ts-loader")
.tap((options) => {
options = merge(options, {
transpileOnly: true,
getCustomTransformers: () => ({
before: [
tsImportPluginFactory({
libraryName: "vant",
libraryDirectory: "es",
style: false,
}),
],
}),
compilerOptions: {
module: "es2015",
},
});
return options;
});
},
};
3、文件有如下报错,在.eslintrc.js文件添加'@typescript-eslint/no-var-requires': 0