我有 2 个旧 JS 文件,我不想更改。出于这个原因,我想使用exports-loader和imports-loader
文件 B-legacy 需要来自 File A-legacy的全局变量 GLOB
我的 webpack.config.js 结果
rules: [
{ test: /\.ts$/, use: 'ts-loader' }, // Typescript file loader;
{
test: path.resolve(__dirname, '../Scripts/legacy/A-legacy'),
use: 'exports-loader?GLOB'
},
{
test: path.resolve(__dirname, '../Scripts/legacy/B-legacy'),
use: 'imports-loader?GLOB'
}
],
据我了解,这应该有效。我正在导出 A-legacy 中的 GLOB var,并希望将其导入 B-legacy。
但是构建它会出现以下错误:
./Scripts/legacy/B-legacy.js 中的错误模块未找到:错误:无法解析“C:\anypath\Scripts\legacy”中的“GLOB”@ ./Scripts/legacy/A-legacy.js 2 :11-26
我已经尝试将 enforce: "pre" 添加到 exports-loader 规则。但这并没有改变任何东西