我有一个简单的Typescript项目,其中包含以下代码:
import {
parseComponent,
compile as compileTemplate,
ASTElement,
} from "vue-template-compiler";
...
我使用
tsc
与:
"target": "es2020",
"module": "commonjs",
它给出了这样的代码:
const vue_template_compiler_1 = require("vue-template-compiler");
在我的
package.json
我有这个:
"dependencies": {
"vue-template-compiler": "^2.6.12"
但我
不要
有
"vue"
,因为我不需要所有的Vue——只需要模板编译器。
这一切都很好,但我试图使用Webpack将每个人捆绑到一个文件中。然而,当我运行webpack时,我收到了以下错误:
ERROR in ./node_modules/vue-template-compiler/index.js 2:19-41
Module not found: Error: Can't resolve 'vue' in '/path/to/myproject/node_modules/vue-template-compiler'
@ ./build/analysis.js 8:32-64
@ ./build/index.js 8:19-40
这对应于
require("vue-template-checker")
线。为什么我会得到这个错误?
这是我的
webpack.config.js
:
const path = require("path");
const webpack = require("webpack");
module.exports = {
target: "node",
entry: "./build/index.js",
mode: "production",
output: {
filename: "index.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
new webpack.BannerPlugin({ banner: "#!/usr/bin/env node", raw: true }),
],
};