我已经安装了proxyquire,我的ajax.test.tsx文件包含以下代码,只有两行
import * as proxyquire from 'proxyquire';
proxyquire.noCallThru();
我的网页包代码如下
module.exports = {
entry: {
"book.service": './src/book.service.ts',
"ajax.test": './src/ajax.test.tsx'
},
output: {
filename: "[name].js",
path: __dirname + "/dist"
},
devtool: "source-map",
watch: true,
resolve: {
extensions: [".tsx", ".tsx", ".js", ".json", ".ts", '.d.ts']
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
externals: {
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': 'window'
}
};
我已经安装了proxyquire&@types/proxyquire。当我运行webpack命令时,它会抛出以下错误
WARNING in ./~/proxyquire/lib/proxyquire.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./~/proxyquire/index.js 3:17-44
@ ./src/ajax.test.tsx
ERROR in ./~/proxyquire/lib/proxyquire.js
Module not found: Error: Can't resolve 'module' in '***\node_modules\pr
oxyquire\lib'
最佳答案
Proxyquire与网页包不兼容-https://github.com/thlorenz/proxyquire/issues/62
问题
proxyquire使用web包不支持的require.extensions。
选择
inject loader
babel-plugin-rewire