如何导入VueLoaderPlugin toTypeScript文件?

问题描述 投票:0回答:2

我使用TypeScript生成webpack配置。

根据vue-loader documentation,我安装了vue-loadervue-template-compiler

我确保vue-loader有类型定义文件:

enter image description here

但是,我的TypeScript项目没有看到plugin.js文件。

TS2307: Cannot find module 'vue-loader/lib/plugin'.

enter image description here

我试过"allowJs": true:没有效果。

另外,如果要通过@ts-ignore来抑制错误消息,我的应用程序将由webpack成功构建。所以问题有些遗漏了声明。哪个是?

我的tsconfig.json设置是:

{
  "compilerOptions": {

    "target": "es6",
    "strict": true,

    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,

    "lib": [
      "es2018"
    ],

    "baseUrl": "./",

    "noUnusedLocals": false,
    "noUnusedParameters": false
  }
}

更新:建议解决方案尝试

enter image description here

TS7016: Could not find a declaration file for module 'vue-loader/lib/plugin'

node_modules/vue-loader/lib/index.d.ts的内容是:

import { Plugin } from 'webpack'

declare namespace VueLoader {
  class VueLoaderPlugin extends Plugin {}
}

export = VueLoader
typescript vue.js webpack
2个回答
1
投票

你是这样尝试的:import { VueLoaderPlugin } from "vue-loader";

这对我有用。


0
投票

您可以将插件导入到typescript中,如下所示:

import * as VueLoaderPlugin from 'vue-loader/lib/plugin';

之后你应该得到一大堆与consolidate相关的错误,Consolidate - Webpack build fails #295是node.js的模板引擎整合库。

我尝试使用类似于qazxswpoi的方法修复这些错误,但无法获得有效的webpack配置。

© www.soinside.com 2019 - 2024. All rights reserved.