[英]Uncaught ReferenceError: require is not defined react + webpack
I have been working on a project for about 2 months and used webpack-dev-middleware . 我已经在一个项目上工作了大约2个月,并使用了webpack-dev-middleware 。
According to the WDM documentation, its just a wrapper for webpack and run the project in the memory to enable hot reloading. 根据WDM文档,它只是webpack的包装器,并在内存中运行项目以启用热重新加载。
But now when im trying to build and deploy with webpack and same webpack.config.js i get Uncaught ReferenceError: require is not defined
error. 但是现在当我尝试使用webpack和webpack.config.js构建和部署时,我得到Uncaught ReferenceError: require is not defined
错误。
I have searched alot and couldn't find a right answer for my case. 我搜索了很多,找不到我的案子的正确答案。
I'd really appreciate any help :). 我真的很感激任何帮助:)。
my webpack.config.js 我的webpack.config.js
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');
var autoprefixer = require('autoprefixer');
const webpack = require('webpack');
var fs = require('fs')
module.exports = {
entry: './src/client.js',
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js'
},
target: 'web',
// keep node_module paths out of the bundle
externals: fs.readdirSync(path.resolve(__dirname, 'node_modules')).concat([
'react-dom/server', 'react/addons',
]).reduce(function (ext, mod) {
ext[mod] = 'commonjs ' + mod
return ext
}, {}),
node: {
__filename: true,
__dirname: true
},
plugins: [
new ExtractTextPlugin('styles.css'),
],
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
}, {
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
loader: 'url-loader?limit=100000&name=/[hash].[ext]',
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader']),
},
{ test: /\.json$/, loader: "json-loader"}
],
},
devtool: 'cheap-module-source-map'
}
I'm using webpack version : 1.13.3 as local. 我正在使用webpack版本:1.13.3作为本地版本。
在我的情况下,原因是: ... module: { noParse: /\\.min\\.js$/, ...
我已经评论出来了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.