您当前的位置: 首页 > 

彭世瑜

暂无认证

  • 0浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

vue: 使用ts-loader引入ts文件

彭世瑜 发布时间:2021-05-11 14:16:26 ,浏览量:0

安装

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

参考: https://github.com/TypeStrong/ts-loader/issues/595

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0892s