11

I am new to webpack, I am facing few problems while trying to setup webpack.

I have the following directory structure:

  • Node Modules
  • Public (index.html, index.jsx)
  • Components
  • webpack.config.js

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']
    }
}

1 Answer 1

13

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.