0
我在反應項目中工作。當我使用「exclude:/ node_modules」時,我的項目並未排除node_modules。所以我讀了一些解決的問題,並將下面的代碼添加到我的webpack.config.js中。在瀏覽器控制檯中使用「externals」排除node_modules錯誤
var nodeExternals = require('webpack-node-externals');
...
module.exports = {
...
target: 'node', // in order to ignore built-in modules like path, fs, etc.
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
...
};
我webpack.config.js則看起來像這樣
var path = require('path');
var webpack = require('webpack');
var nodeExternals = require('webpack-node-externals');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./dev/js/index.js'
],
target: 'node', // in order to ignore built-in modules like path, fs, etc.
externals: [nodeExternals()], // in order to ignore all modules in node_modules
module: {
loaders: [
{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/
},
{
test: /\.scss/,
loader: 'style-loader!css-loader!sass-loader'
}
]
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
};
當我運行我的應用程序,我在控制檯收到此錯誤
我怎樣才能解決這個問題錯誤?
所以我應該刪除它 – ApurvG
是的,你不應該需要這個模塊的瀏覽器包。 –
但是爲什麼瀏覽器控制檯熱載入程序會說更新了576個模塊,每當我對組件進行更改時。爲什麼每次更新很多模塊?這意味着節點模塊每次都會更新。我應該怎麼做? – ApurvG