首先下载ts-import-plugin
npm i -D ts-import-plugin
然后在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: true
})
]
}),
compilerOptions: {
module: "es2015"
}
});
return options;
});
}
};
在main.js中就可以直接使用了
import { Button } from 'vant';
Vue.use(Button);
网友评论