安装
npm install typescript ts-loader --save-dev
vue.config.js
configureWebpack: { resolve: {extensions: [".ts", ".tsx", ".js", ".json"]}, module: { rules: [ { test: /\.ts$/, loader: "ts-loader" }, ] } }
tsconfig.json
{ "compilerOptions": { "target": "es5", "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, "sourceMap": false }, "include": ["src/**/*"], "exclude": ["node_modules","**/*.spec.ts"] }
报错
Syntax Error: TypeError: loaderContext.getOptions is not a function
原因:
ts-loader 9 不支持 webpack 4
换一个版本
npm install ts-loader@8.2.0
参考: