I am new to webpack, I am facing few problems while trying to setup webpack.
I have the following directory structure:
In index.html I have tried to include
<script src="../node_modules/react/dist/react-with-addons.js"></script>
and when I am trying to run webpack dev server console is showing me
http://localhost:8080/node_modules/react/dist/react-with-addons.js not found
The following is my webpack.config.js file:
module.exports = {
//This is the entry point for the webpack
entry: {
app: ['./public/index.jsx']
},
output: {
// This is the name of the bundle which is created when webpack runs
path: './public',
filename: 'bundle.js'
},
module: {
loaders: [
{
//tell webpack to use jsx-loader for all *.jsx files
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony'
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
}
}
I know this is quite an old question, but I struggled with this today.
A solution I'm using is passing an array to the contentBase
with node_modules
.
devServer: {
contentBase: [
path.resolve(__dirname, "public"),
path.resolve(__dirname, "node_modules")
],
publicPath: "/"
}
Then in your html:
<script src="./react/dist/react.js"></script>
This way you don't need to include React in your bundle and it can be cached by the browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With