【发布时间】:2020-05-13 13:25:40
【问题描述】:
我正在使用 webpack ...我想在我的 webpack.config.js 文件中使用 3rd 方库(knockoutjs 库),库保存在我的本地目录中
我尝试过使用
const ojL10n = require("D:/SVN/trunk/core/channel/framework/tmp/ojL10n.js")
但我收到错误...定义未在 D:/SVN/trunk/core/channel/framework/tmp/ojL10n.js 中定义
这是我的配置文件
"use strict";
require("amd-loader");
const webpack = require("webpack"),
path = require("path");
ojL10n = require("./tmp/ojL10n.js"), //library stored in local
text = require("./tmp/text.js"), //library stored in local
webpackConfigurationObject = {
entry: "./entryModule.js",
target: "node",
mode: "development",
node: {
__dirname: false
},
resolve: {
alias: {
text : text,
ojL10n : ojL10n
},
extensions: [".ts",".js", ".json"]
},
output: {
path: path.join(__dirname, "dest"),
filename: "combinedFile.js",
library: "combinedFile",
libraryTarget: "commonjs2"
},
module: {
rules: [{
test: /\.ts$/,
include: /src/,
exclude: /(node_modules)|(dist)/,
use: {
loader: "babel-loader"
},
parser: { amd: false }
}]
},
externals: {
jquery: {
commonjs2 : "jQuery"
},
knockout: {
commonjs2 : "knockout"
}
}
};
const compiler = webpack(webpackConfigurationObject),
compiler.run(complete);
【问题讨论】:
-
你能发布你的 webpack.config.js 吗?您是否尝试将 output.libraryTarget 设置为“umd”?
-
你也可以尝试添加:
{ test: /ojL10n/, loader: 'imports-loader?define=>false' },作为规则加载器 -
@RazRonen 感谢您的回复...我已在问题中添加了我的配置文件代码
标签: webpack knockout.js