Code Monkey home page Code Monkey logo

webpack-howto's Introduction

webpack-howto

Goal of this guide

This is a cookbook of how to get things done with webpack. This includes most things we use at Instagram and nothing we don't use.

My advice: start with this as your webpack docs, then look at the official docs for clarification.

Prerequisites

  • You know browserify, RequireJS or something similar
  • You see the value in:
    • Bundle splitting
    • Async loading
    • Packaging static assets like images and CSS

1. Why webpack?

  • It's like browserify but can split your app into multiple files. If you have multiple pages in a single-page app, the user only downloads code for just that page. If they go to another page, they don't redownload common code.

  • It often replaces grunt or gulp because it can build and bundle CSS, preprocessed CSS, compile-to-JS languages and images, among other things.

It supports AMD and CommonJS, among other module systems (Angular, ES6). If you don't know what to use, use CommonJS.

2. Webpack for Browserify people

These are equivalent:

browserify main.js > bundle.js
webpack main.js bundle.js

However, webpack is more powerful than Browserify, so you generally want to make a webpack.config.js to keep things organized:

// webpack.config.js
module.exports = {
  entry: './main.js',
  output: {
    filename: 'bundle.js'       
  }
};

This is just JS, so feel free to put Real Code in there.

3. How to invoke webpack

Switch to the directory containing webpack.config.js and run:

  • webpack for building once for development
  • webpack -p for building once for production (minification)
  • webpack --watch for continuous incremental build in development (fast!)
  • webpack -d to include source maps

4. Compile-to-JS languages

webpack's equivalent of browserify transforms and RequireJS plugins is a loader. Here's how you can teach webpack to load CoffeeScript and Facebook JSX+ES6 support (you must npm install babel-loader coffee-loader):

See also the babel-loader installation instructions for additional dependencies (tl;dr run npm install babel-core babel-preset-es2015 babel-preset-react).

// webpack.config.js
module.exports = {
  entry: './main.js',
  output: {
    filename: 'bundle.js'       
  },
  module: {
    loaders: [
      { test: /\.coffee$/, loader: 'coffee-loader' },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015', 'react']
        }
      }
    ]
  }
};

To enable requiring files without specifying the extension, you must add a resolve.extensions parameter specifying which files webpack searches for:

// webpack.config.js
module.exports = {
  entry: './main.js',
  output: {
    filename: 'bundle.js'       
  },
  module: {
    loaders: [
      { test: /\.coffee$/, loader: 'coffee-loader' },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015', 'react']
        }
      }
    ]
  },
  resolve: {
    // you can now require('file') instead of require('file.coffee')
    extensions: ['', '.js', '.json', '.coffee'] 
  }
};

5. Stylesheets and images

First update your code to require() your static assets (named as they would with node's require()):

require('./bootstrap.css');
require('./myapp.less');

var img = document.createElement('img');
img.src = require('./glyph.png');

When you require CSS (or less, etc), webpack inlines the CSS as a string inside the JS bundle and require() will insert a <style> tag into the page. When you require images, webpack inlines a URL to the image into the bundle and returns it from require().

But you need to teach webpack to do this (again, with loaders):

// webpack.config.js
module.exports = {
  entry: './main.js',
  output: {
    path: './build', // This is where images AND js will go
    publicPath: 'http://mycdn.com/', // This is used to generate URLs to e.g. images
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders
      { test: /\.css$/, loader: 'style-loader!css-loader' },
      { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest
    ]
  }
};

6. Feature flags

We have code we want to gate only to our dev environments (like logging) and our internal dogfooding servers (like unreleased features we're testing with employees). In your code, refer to magic globals:

if (__DEV__) {
  console.warn('Extra logging');
}
// ...
if (__PRERELEASE__) {
  showSecretFeature();
}

Then teach webpack those magic globals:

// webpack.config.js

// definePlugin takes raw strings and inserts them, so you can put strings of JS if you want.
var definePlugin = new webpack.DefinePlugin({
  __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
  __PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
});

module.exports = {
  entry: './main.js',
  output: {
    filename: 'bundle.js'       
  },
  plugins: [definePlugin]
};

Then you can build with BUILD_DEV=1 BUILD_PRERELEASE=1 webpack from the console. Note that since webpack -p runs uglify dead-code elimination, anything wrapped in one of these blocks will be stripped out, so you won't leak secret features or strings.

7. Multiple entrypoints

Let's say you have a profile page and a feed page. You don't want to make the user download the code for the feed if they just want the profile. So make multiple bundles: create one "main module" (called an entrypoint) per page:

// webpack.config.js
module.exports = {
  entry: {
    Profile: './profile.js',
    Feed: './feed.js'
  },
  output: {
    path: 'build',
    filename: '[name].js' // Template based on keys in entry above
  }
};

For profile, insert <script src="build/Profile.js"></script> into your page. Do a similar thing for feed.

8. Optimizing common code

Feed and Profile share a lot in common (like React and the common stylesheets and components). webpack can figure out what they have in common and make a shared bundle that can be cached between pages:

// webpack.config.js

var webpack = require('webpack');

var commonsPlugin =
  new webpack.optimize.CommonsChunkPlugin('common.js');

module.exports = {
  entry: {
    Profile: './profile.js',
    Feed: './feed.js'
  },
  output: {
    path: 'build',
    filename: '[name].js' // Template based on keys in entry above
  },
  plugins: [commonsPlugin]
};

Add <script src="build/common.js"></script> before the script tag you added in the previous step and enjoy the free caching.

9. Async loading

CommonJS is synchronous but webpack provides a way to asynchronously specify dependencies. This is useful for client-side routers, where you want the router on every page, but you don't want to have to download features until you actually need them.

Specify the split point where you want to load asynchronously. For example:

if (window.location.pathname === '/feed') {
  showLoadingState();
  require.ensure([], function() { // this syntax is weird but it works
    hideLoadingState();
    require('./feed').show(); // when this function is called, the module is guaranteed to be synchronously available.
  });
} else if (window.location.pathname === '/profile') {
  showLoadingState();
  require.ensure([], function() {
    hideLoadingState();
    require('./profile').show();
  });
}

webpack will do the rest and generate extra chunk files and load them for you.

webpack will assume that those files are in your root directory when you load then into a html script tag for example. You can use output.publicPath to configure that.

// webpack.config.js
output: {
    path: "/home/proj/public/assets", //path to where webpack will build your stuff
    publicPath: "/assets/" //path that will be considered when requiring your files
}

Additional resources

Take a look at a real world example on how a successful team is leveraging webpack: http://youtu.be/VkTCL6Nqm6Y This is Pete Hunt at OSCon talking about webpack at Instagram.com

FAQ

webpack doesn't seem modular

webpack is extremely modular. What makes webpack great is that it lets plugins inject themselves into more places in the build process when compared to alternatives like browserify and requirejs. Many things that may seem built into the core are just plugins that are loaded by default and can be overridden (i.e. the CommonJS require() parser).

webpack-howto's People

Contributors

amleth avatar anxsec avatar bguiz avatar colinrymer avatar danillocorvalan avatar enaqx avatar everdimension avatar fvgs avatar jdaudier avatar leopic avatar lozy219 avatar mlusetti avatar petehunt avatar qiuyuntao avatar sboselli avatar sophiebits avatar tgriesser avatar ufukomer avatar yuanzhaohao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-howto's Issues

How to use cors with webpack?

i have recently started with the webpack, now i am stuck with cors bascially there are few request i am doing through a different server, can anyone point me how to fix cors in webpack.

Examples

How do you feel about a folder where people can submit fully working examples for different things, like working with 3rd party libraries, fonts, etc?

Would be kind of messy to manage maybe :)

webpack command fails with below error.

Steps performed.

  1. Downloaded the ZIP from git and unzipped it.
  2. npm install
  3. webpack

Hash: 396f0bfb9d565b6f60f0
Version: webpack 1.13.3
Time: 703ms
+ 1 hidden modules

ERROR in ./modules/main.js
Module build failed: ReferenceError: [BABEL] D:\temporary\Working\webpack-howto-master\example\modules\main.js: Unknown option: direct.presets
at Logger.error (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-core\lib\transformation\file\logger.js:58:11)
at OptionManager.mergeOptions (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-core\lib\transformation\file\options\option-manager.js:126:29)
at OptionManager.init (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-core\lib\transformation\file\options\option-manager.js:216:10)
at File.initOptions (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-core\lib\transformation\file\index.js:147:75)
at new File (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-core\lib\transformation\file\index.js:137:22)
at Pipeline.transform (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-core\lib\transformation\pipeline.js:164:16)
at transpile (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-loader\index.js:12:22)
at Object.module.exports (D:\temporary\Working\webpack-howto-master\example\node_modules\babel-loader\index.js:71:12)

Error in main.js when running: Module build failed: ReferenceError: [BABEL]

When I pull the latest code from the repo, install webpack globally, and run the example code, I get the following error message:

$ webpack

Hash: 396f0bfb9d565b6f60f0
Version: webpack 1.12.14
Time: 1401ms
    + 1 hidden modules

ERROR in ./modules/main.js
Module build failed: ReferenceError: [BABEL] /code/webpack-howto/example/modules/main.js: Unknown option: direct.presets
    at Logger.error (/code/webpack-howto/example/node_modules/babel-core/lib/transformation/file/logger.js:58:11)
    at OptionManager.mergeOptions (/code/webpack-howto/example/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29)
    at OptionManager.init (/code/webpack-howto/example/node_modules/babel-core/lib/transformation/file/options/option-manager.js:216:10)
    at File.initOptions (/code/webpack-howto/example/node_modules/babel-core/lib/transformation/file/index.js:147:75)
    at new File (/code/webpack-howto/example/node_modules/babel-core/lib/transformation/file/index.js:137:22)
    at Pipeline.transform (/code/webpack-howto/example/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at transpile (/code/webpack-howto/example/node_modules/babel-loader/index.js:12:22)
    at Object.module.exports (/code/webpack-howto/example/node_modules/babel-loader/index.js:69:12)

Steps I took:

$ npm install -g webpack
$ cd example
$ npm install
$ webpack

Versions of node, npm and webpack installed:

$ node -v
v5.3.0
$ npm -v
3.3.12
$ webpack -v
Hash: 396f0bfb9d565b6f60f0
Version: webpack 1.12.14
Time: 22ms
# then same error message as above

Require('file.css') messing with Jest tests

Hey guys!

Firstly i'd like to say that webpack really impressed me, what a cool project! And thanks for this howto, very helpful ๐Ÿ‘

I followed some webpack examples (and what is presented in this how-to) and then set up a little project following the structure of petehunt/react-touch. When i started adding some tests i came up with problems with some of the files that contained require('./MyComponent.css') - in a MyComponent.jsx, for example.

When removing that .css dependency i was able to proceed with the test (running them with Jest).

Am i doing something wrong (testing a component that required a .css - should i modularize more?) or there is a pattern/plugin for dealing with this? Maybe some help on this would be great for others that encounter the same issue :neckbeard:

Thanks!

i thought this was the best place to ask as i think those who are comming to webpack - like me - might search a question like that here. Please tell me if this was not the right place!

Require a image in CSS

I can require a image in JS easily like:

var img = document.createElement('img');
img.src = require('./glyph.png');

How can I require a image in CSS? I need something like:

.H1:before {
  content: url({require('./glyph.png)});
}

Module build failed: ReferenceError: [BABEL] webpack-howto/example/modules/main.js: Unknown option: direct.presets

I was hoping this howto would help an absolute beginner, but it seems to be dead-on-arrival. Any ideas?

ERROR in ./modules/main.js
Module build failed: ReferenceError: [BABEL] /Users/wolfch/src/webpack-howto/example/modules/main.js: Unknown option: direct.presets
    at Logger.error (/Users/wolfch/src/webpack-howto/example/node_modules/babel-core/lib/transformation/file/logger.js:58:11)
    at OptionManager.mergeOptions (/Users/wolfch/src/webpack-howto/example/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29)
    at OptionManager.init (/Users/wolfch/src/webpack-howto/example/node_modules/babel-core/lib/transformation/file/options/option-manager.js:216:10)
    at File.initOptions (/Users/wolfch/src/webpack-howto/example/node_modules/babel-core/lib/transformation/file/index.js:147:75)
    at new File (/Users/wolfch/src/webpack-howto/example/node_modules/babel-core/lib/transformation/file/index.js:137:22)
    at Pipeline.transform (/Users/wolfch/src/webpack-howto/example/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at transpile (/Users/wolfch/src/webpack-howto/example/node_modules/babel-loader/index.js:12:22)
    at Object.module.exports (/Users/wolfch/src/webpack-howto/example/node_modules/babel-loader/index.js:71:12)

include css and js files into HTML

i have code like this

<html>
      <head>
         <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
         <link href="path_to_css/some_css.css" rel="stylesheet" type="text/css">
      </head>
      <body>
       ...
      <script src="bootstrap/js/bootstrap.min.js"></script>
      <script src="jquery/jquery.min.js"></script>
   </body>
</html>

and i need plugin/loader or other way to get my html file with replaced link and script tags to content of this files, is there any way to do it ?

Further explanation of the webpack optimizer

It would be great to go into some more detail on how the webpack.optimize actually works.

Another things I'm pretty concerned about is code re-use on the server-side.

Webpack is often touted as a better alternative to browserify. But browserify has the unique strength of seamlessly working within node.js. Considering that the benefits of webpack come with async loading and 'require.ensure', and requiring static files, is there a way to make these lines work in node.js as well?
They mostly just need to be ignored.

webpack.optimize.CommonsChunkPlugin optimizes common stylesheets to an unexpected file name

when i use both "extract-text-webpack-plugin" and "webpack.optimize.CommonsChunkPlugin"

var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
 plugins: [
    new ExtractTextPlugin("css/[name].css"),
    new webpack.optimize.CommonsChunkPlugin('js/common.js')
  ]
}

i have multiple entrypoints and require the same style file,and after packaging,there is a common style file named common.js.css

how i can control the common style file's name or avoid optimizing style files to a common file ?

How to compile to memory

I'm trying to make a plugin for Socketstream to compile JS files to memory, but somehow I get an error regardless of my attempted variations.

webpack issue with /Users/Shared/Projects/Websites/fluentapi/client/code/discuss/controllers.js [Error: Invalid path '']

Is there anything in this code that is missing?

            var basePath = config.basePath || process.cwd(), //TODO project dir
                relPath = pathlib.relative(basePath, path).replace('.js','').replace('.es6','');

            var compiler = webpack({
                //config
                context: basePath,
                entry: './' + relPath,
                ouput: {
                    path: '/',
                    filename: 'temp.js'
                }
            });

            console.log('packing',basePath, relPath);

            //var stream = new Stream.Readable();
            var fsOut = compiler.outputFileSystem = new MemoryFileSystem();
            compiler.plugin("after-emit", function(compilation, callback) {
                console.log('after packing',basePath, relPath);
                compilation.assets.forEach(function(asset) {
                    var path = fsOut.join(compiler.outputPath, asset.name);
                    console.log(asset.name, path);
                    var contents = fsOut.readFileSync(path);

                    //TODO what about multiple resulting files
                    cb(contents);
                    //stream.push(new File({
                    //    base: compiler.outputPath,
                    //    path: path,
                    //    contents: contents
                    //});
                });
                //callback();
            });

            compiler.run(function(err, stats) {
                if(err)
                    return handleFatalError(err);
                var jsonStats = stats.toJson();
                if(jsonStats.errors.length > 0)
                    return handleSoftErrors(jsonStats.errors);
                if(jsonStats.warnings.length > 0)
                    handleWarnings(jsonStats.warnings);
                //successfullyCompiled(stats);
            });

A line of Chinese translation is incorrect

English: 'inline base64 URLs for <=8k images, direct URLs for the rest'

Chinese: "ๅ†…่”็š„base64็š„ๅ›พ็‰‡ๅœฐๅ€๏ผŒๅ›พ็‰‡่ฆๅฐไบŽ8k๏ผŒ็›ดๆŽฅ็š„url็š„ๅœฐๅ€ๅˆ™ไธ่งฃๆž"

I think the Chinese translation is incorrect. It should be:

"ๅ›พ็‰‡ๅฐไบŽ8kๆ—ถ๏ผŒ้‡‡็”จๅ†…่”็š„base64็š„ๅ›พ็‰‡ๅœฐๅ€๏ผ›ๅ…ถไฝ™็š„้‡‡็”จ็›ดๆŽฅ็š„URL"

Best practices for depenendencies vs devDependencies

Since webpack produces an artifact that bundles all dependencies, none of the dependencies need to be available in the node environment at runtime (because there is no node environment in prod unless we are using node to serve the prod assets), so shouldn't we all be using devDependencies for everything? Is there any reason that we are not doing this or is it just a misleading convention?

React server-side rendering

Please add a section describing the server-side rendering best practice. I find this part super confusing (e.g. require('style.css') won't work with node).

How to create split points with common chunks

There is an example of multiple entry points sharing chunks, but is it possible to create split points that have chunks in common? I've extended @codeboyim's sample app discussed in issue #8, here is my version.

The main changes:

  1. Created new lib.js file required by both modules:

    // feed.js (the same in profile.js)
    var lib = require('./lib');
  2. Added third parameter to require.ensure() invocation to be able to reference these modules in webpack.config.js file:

    require.ensure([], function () {
        require('./feed').show();
    }, 'feed');
    //...
    require.ensure([], function () {
        require('./profile').show();
    }, 'profile');
  3. Configured CommonsChunkPlugin:

    plugins: [
        new webpack.optimize.CommonsChunkPlugin('commons.js', ['feed', 'profile'])
    ]

Here is the full diff.

However both main.js and common.js generated files contain the module system and chunks loading logic, so the app doesn't work.

Link to talk?

It might be beneficial for the readme to link to your OSCON talk, which does a great job of explaining the motivations behind using webpack in more detail.

Just an idea. I've been using browserify for over a year now, and you've converted me.

npm start introduce error

Module build failed: ReferenceError: [BABEL] E:\git\webpack-howto\example\modules\main.js: Unknown option: direct.presets
at Logger.error (E:\git\webpack-howto\example\node_modules\babel-core\lib\transformation\file\logger.js:58:11)

Seem that global installed babel-cli6 is conflict with this repo, but there is no way to install cli5, do you know to resolve this? Thanks.

Loaders: worth discussing "-loader" suffix?

I'm new to Webpack and have found this howto an invaluable resource. I have a problem (that might end up just being a question) about the module.loaders section of our webpack.config.js though:

module: {
  loaders: [
    { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders
    { test: /\.css$/, loader: 'style-loader!css-loader' },
    { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest
  ]
}

I'm not sure whether this is specific to the loaders used here, but in Webpack's documentation I'm seeing the -loader omitted - so we could instead use this:

module: {
  loaders: [
    { test: /\.less$/, loader: 'style!css!less' }, // use ! to chain loaders
    { test: /\.css$/, loader: 'style!css' },
    { test: /\.(png|jpg)$/, loader: 'url?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest
  ]
}

Is there any difference? Would it be worth adding a note mentioning that they're optional?

What is the architecture needed to achieve steps 8โ€”Optimizing common code.

It does not seem like a bundle can be loaded lazily or otherwise (So I am not sure how you would load Profile/Feed).

How does one achieve loading multiple entry points over some router?

// webpack.config.js

var webpack = require('webpack');

var commonsPlugin =
  new webpack.optimize.CommonsChunkPlugin('common.js');

module.exports = {
  entry: {
    Profile: './profile.js', // go to profile pageโ€”load Profile
    Feed: './feed.js' // go to feed pageโ€”load Feed
  },
  output: {
    path: 'build',
    filename: '[name].js' // Template based on keys in entry above
  },
  plugins: [commonsPlugin]
};

Feature flags always returns TRUE

In example:

var definePlugin = new webpack.DefinePlugin({
  __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
  __PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
});

__DEV__ always be true even i BUILD_DEV is undefined.

JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')) => 'true'

maybe we should update this example to make __DEV__ return true only when BUILD_DEV exist.

for example:

JSON.stringify(typeof(process.env.BUILD_DEV) !== undefined)

how do we load json

While the howto suggests we can load in json quite easily, telling webpack to resolve .json doesn't actually work at all. It just throws up file errors when you try it. If this repo is still being maintained, can it be update with how to load in data from .json resource?

Update to webpack 2

webpack 2 is released for a time. Is there any plan for updating this guide to webpack 2?

"Module not found: Error: Cannot resolve module" for react-router and react

Hi,

Hopefully this is not a total noob question, but;

When I run 'webpack' I keep getting a "Module not found: Error: Cannot resolve module" for 'react-router' and 'react'.

Just for clarity I'm running 'npm install' in the example directory and then running 'webpack' in the same directory.

Would appreciate it if someone could help me out :)

Thanks in advance,
Jean

Add description and link

It might be helpful to add a description and homepage link to the repo (currently "No description or website provided.").

Maybe: "A how-to guide for webpack. https://webpack.github.io/"

(This isn't part of the repo, so I can't fork and PR. It's the 'Edit' option under the Code tab.)

How to inject scripts to index html file in production?

I have a index html file and i need to inject in production ENV additional scripts. with gulp i can do this with plugin like gulp inject, How can i do this with webpack?

For example:

<script src="script.js"></script>
// I want this script only in the production index html file
<script src="script2.js"></script>

Feature flags for different entry points

Is there a way to set a feature flag with the current entry point name so we could reuse components but at the same time change them slightly (deeply nested imports for example). Something like:

module.exports = {
  entry: {
    main: './src/main.js',
    admin: './src/admin.js'
  },
  output: {
    filename: "[name].bundle.js"       
  },
};

var definePlugin = new webpack.DefinePlugin({
  __APP_MODE__: "[name]"
});

In order to do something like:

import Menu from './components/menu'

/components/menu.js

if (__APP_MODE__) {
  module.exports = require('./admin/menu');
} else {
  module.exports = require('./main/menu');
}

How are images referenced from jsx?

Webpack automatically detects url("img/smile.png") statements in css files, so no need to put require there. But I am wondering, how nicely reference images inside jsx, when I am using react.

its certainly possible like this:

var smileURL = require('img/smile.png');
return <div><img src={smileURL}</div>

but it would be very nice if its possible to reference it directly in src tag:

return <div><img src="img/smile.png"</div>

So just wondering whats your take on this. Thank you!

How to inject bundled script to existing html?

I have referred html-webpack-plugin to inject the bundled files.

But, I want to inject the bundled files to existing html file. How can I do that? I didn't find any such an option.

My actual expectation is like,
I have asp.net mvc _layout.cshtml.
I want to inject the output of bundled js and css files to _layout.cshtml.

Running webpack --watch on old React project gives me the following error

What can I do to prevent this error from occurring? I haven't looked at the project in a couple of months and any information pertaining to the issue would be phenomenal. It looks like its having issues with an npm package but I would in no way understand why.

ERROR in ./frontend/nimbusplaylist.jsx
Module not found: Error: Cannot resolve module 'react-modal' in /Users/chrisvh/Documents/Capstone/frontend
 @ ./frontend/nimbusplaylist.jsx 3:12-34

ERROR in ./frontend/components/NewPlaylistModal.jsx
Module not found: Error: Cannot resolve module 'react-modal' in /Users/chrisvh/Documents/Capstone/frontend/components
 @ ./frontend/components/NewPlaylistModal.jsx 3:12-34

ERROR in ./frontend/components/PlaylistModal.jsx
Module not found: Error: Cannot resolve module 'react-modal' in /Users/chrisvh/Documents/Capstone/frontend/components
 @ ./frontend/components/PlaylistModal.jsx 5:12-34

ERROR in ./frontend/components/Like.jsx
Module not found: Error: Cannot resolve module 'react-modal' in /Users/chrisvh/Documents/Capstone/frontend/components
 @ ./frontend/components/Like.jsx 5:12-34

ERROR in ./~/react/lib/ReactDOM.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactLegacyElement in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOM.js 17:25-56

ERROR in ./~/react/lib/ReactDOM.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./mapObject in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOM.js 19:16-38

ERROR in ./~/react/lib/React.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactLegacyElement in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/React.js 27:25-56

ERROR in ./~/react/lib/React.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactContext in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/React.js 19:19-44

ERROR in ./~/react/lib/React.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactTextComponent in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/React.js 33:25-56

ERROR in ./~/react/lib/React.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/React.js 136:29-62

ERROR in ./~/react/lib/ReactElement.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactContext in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactElement.js 14:19-44

ERROR in ./~/react/lib/ReactElement.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactElement.js 17:14-34

ERROR in ./~/react/lib/ReactElementValidator.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactElementValidator.js 26:14-34

ERROR in ./~/react/lib/ReactElementValidator.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./monitorCodeUse in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactElementValidator.js 25:21-48

ERROR in ./~/react/lib/DOMPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/DOMPropertyOperations.js 19:14-34

ERROR in ./~/react/lib/ReactChildren.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactChildren.js 17:14-34

ERROR in ./~/react/lib/ReactDOMComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./monitorCodeUse in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMComponent.js 30:21-48

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactContext in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 15:19-44

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactLegacyElement in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 21:25-56

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./monitorCodeUse in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 34:21-48

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./mapObject in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 35:16-38

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 37:14-34

ERROR in ./~/react/lib/ReactDefaultInjection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultInjection.js 20:27-60

ERROR in ./~/react/lib/ReactMount.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactLegacyElement in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactMount.js 18:25-56

ERROR in ./~/react/lib/ReactMount.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactMount.js 28:14-34

ERROR in ./~/react/lib/deprecated.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/deprecated.js 13:14-34

ERROR in ./~/react/lib/DOMPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./escapeTextForBrowser in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/DOMPropertyOperations.js 17:27-60

ERROR in ./~/react/lib/ReactDOMComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./escapeTextForBrowser in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMComponent.js 26:27-60

ERROR in ./~/react/lib/DOMPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./memoizeStringOnly in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/DOMPropertyOperations.js 18:24-54

ERROR in ./~/react/lib/EventPluginUtils.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/EventPluginUtils.js 16:16-38

ERROR in ./~/react/lib/ReactDOMComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMComponent.js 27:16-38

ERROR in ./~/react/lib/ReactComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactComponent.js 19:16-38

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 31:16-38

ERROR in ./~/react/lib/ReactInstanceHandles.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactInstanceHandles.js 17:16-38

ERROR in ./~/react/lib/ReactMount.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactMount.js 26:16-38

ERROR in ./~/react/lib/ReactServerRendering.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactServerRendering.js 21:16-38

ERROR in ./~/react/lib/onlyChild.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/onlyChild.js 15:16-38

ERROR in ./~/react/lib/ReactDOMComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMComponent.js 29:12-30

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 33:12-30

ERROR in ./~/react/lib/ReactComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyMirror in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactComponent.js 20:16-38

ERROR in ./~/react/lib/ReactCompositeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyMirror in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactCompositeComponent.js 32:16-38

ERROR in ./~/react/lib/ReactDefaultInjection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./CompositionEventPlugin in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultInjection.js 17:29-64

ERROR in ./~/react/lib/ReactDefaultInjection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./MobileSafariClickEventPlugin in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultInjection.js 22:35-76

ERROR in ./~/react/lib/ReactDefaultInjection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactDOMForm in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultInjection.js 29:19-44

ERROR in ./~/react/lib/ReactDefaultInjection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactDOMImg in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultInjection.js 30:18-42

ERROR in ./~/react/lib/ReactDefaultInjection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./createFullPageComponent in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultInjection.js 44:30-66

ERROR in ./~/react/lib/ReactMount.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./containsNode in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactMount.js 22:19-44

ERROR in ./~/react/lib/ReactMount.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./getReactRootElementInContainer in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactMount.js 24:37-80

ERROR in ./~/react/lib/ReactPropTypes.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./emptyFunction in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactPropTypes.js 18:20-46

ERROR in ./~/react/lib/ReactPropTypeLocations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyMirror in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactPropTypeLocations.js 14:16-38

ERROR in ./~/react/lib/DOMProperty.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/DOMProperty.js 17:16-38

ERROR in ./~/react/lib/PooledClass.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/PooledClass.js 14:16-38

ERROR in ./~/react/lib/CSSPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/CSSPropertyOperations.js 16:27-60

ERROR in ./~/react/lib/CSSPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./memoizeStringOnly in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/CSSPropertyOperations.js 21:24-54

ERROR in ./~/react/lib/CSSPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/CSSPropertyOperations.js 22:14-34

ERROR in ./~/react/lib/EventConstants.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyMirror in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/EventConstants.js 14:16-38

ERROR in ./~/react/lib/ReactBrowserComponentMixin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactBrowserComponentMixin.js 17:16-38

ERROR in ./~/react/lib/traverseAllChildren.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/traverseAllChildren.js 17:16-38

ERROR in ./~/react/lib/ReactOwner.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactOwner.js 15:16-38

ERROR in ./~/react/lib/isEventSupported.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/isEventSupported.js 14:27-60

ERROR in ./~/react/lib/ReactUpdates.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactUpdates.js 21:16-38

ERROR in ./~/react/lib/ReactUpdates.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactUpdates.js 22:14-34

ERROR in ./~/react/lib/ReactEmptyComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactEmptyComponent.js 16:16-38

ERROR in ./~/react/lib/ReactPropTransferer.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./emptyFunction in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactPropTransferer.js 15:20-46

ERROR in ./~/react/lib/ReactPropTransferer.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactPropTransferer.js 16:16-38

ERROR in ./~/react/lib/ReactPropTransferer.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactPropTransferer.js 18:14-34

ERROR in ./~/react/lib/instantiateReactComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/instantiateReactComponent.js 15:14-34

ERROR in ./~/react/lib/instantiateReactComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactLegacyElement in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/instantiateReactComponent.js 18:25-56

ERROR in ./~/react/lib/BeforeInputEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/BeforeInputEventPlugin.js 17:27-60

ERROR in ./~/react/lib/BeforeInputEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/BeforeInputEventPlugin.js 20:12-30

ERROR in ./~/react/lib/ChangeEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ChangeEventPlugin.js 17:27-60

ERROR in ./~/react/lib/ChangeEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ChangeEventPlugin.js 23:12-30

ERROR in ./~/react/lib/HTMLDOMPropertyConfig.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/HTMLDOMPropertyConfig.js 17:27-60

ERROR in ./~/react/lib/EnterLeaveEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/EnterLeaveEventPlugin.js 20:12-30

ERROR in ./~/react/lib/DefaultEventPluginOrder.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/DefaultEventPluginOrder.js 14:13-31

ERROR in ./~/react/lib/ReactComponentBrowserEnvironment.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./getReactRootElementInContainer in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactComponentBrowserEnvironment.js 22:37-80

ERROR in ./~/react/lib/ReactComponentBrowserEnvironment.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactComponentBrowserEnvironment.js 23:16-38

ERROR in ./~/react/lib/ReactDOMInput.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMInput.js 25:16-38

ERROR in ./~/react/lib/ReactDefaultBatchingStrategy.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./emptyFunction in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultBatchingStrategy.js 18:20-46

ERROR in ./~/react/lib/ReactDOMButton.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyMirror in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMButton.js 20:16-38

ERROR in ./~/react/lib/ReactEventListener.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactEventListener.js 16:27-60

ERROR in ./~/react/lib/ReactDOMTextarea.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMTextarea.js 24:16-38

ERROR in ./~/react/lib/ReactDOMTextarea.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMTextarea.js 26:14-34

ERROR in ./~/react/lib/ReactDOMOption.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMOption.js 19:14-34

ERROR in ./~/react/lib/SelectEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/SelectEventPlugin.js 21:12-30

ERROR in ./~/react/lib/SimpleEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/SimpleEventPlugin.js 29:16-38

ERROR in ./~/react/lib/SimpleEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyOf in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/SimpleEventPlugin.js 30:12-30

ERROR in ./~/react/lib/SimpleEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/SimpleEventPlugin.js 31:14-34

ERROR in ./~/react/lib/ReactMultiChildUpdateTypes.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./keyMirror in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactMultiChildUpdateTypes.js 14:16-38

ERROR in ./~/react/lib/flattenChildren.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactTextComponent in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/flattenChildren.js 14:25-56

ERROR in ./~/react/lib/flattenChildren.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./warning in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/flattenChildren.js 17:14-34

ERROR in ./~/react/lib/ReactServerRenderingTransaction.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./emptyFunction in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactServerRenderingTransaction.js 21:20-46

ERROR in ./~/react/lib/CSSPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./camelizeStyleName in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/CSSPropertyOperations.js 18:24-54

ERROR in ./~/react/lib/CSSPropertyOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./hyphenateStyleName in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/CSSPropertyOperations.js 20:25-56

ERROR in ./~/react/lib/ReactOwner.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./emptyObject in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactOwner.js 14:18-42

ERROR in ./~/react/lib/ReactPropTransferer.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./joinClasses in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactPropTransferer.js 17:18-42

ERROR in ./~/react/lib/ReactDOMInput.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./AutoFocusMixin in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMInput.js 14:21-48

ERROR in ./~/react/lib/ReactDOMButton.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./AutoFocusMixin in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMButton.js 14:21-48

ERROR in ./~/react/lib/ReactDOMSelect.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./AutoFocusMixin in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMSelect.js 14:21-48

ERROR in ./~/react/lib/ReactDOMTextarea.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./AutoFocusMixin in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMTextarea.js 14:21-48

ERROR in ./~/react/lib/ReactEventListener.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./EventListener in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactEventListener.js 15:20-46

ERROR in ./~/react/lib/ReactEventListener.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./getUnboundedScrollPosition in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactEventListener.js 24:33-72

ERROR in ./~/react/lib/SelectEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./getActiveElement in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/SelectEventPlugin.js 19:23-52

ERROR in ./~/react/lib/SelectEventPlugin.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./shallowEqual in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/SelectEventPlugin.js 22:19-44

ERROR in ./~/react/lib/ReactDefaultPerf.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./performanceNow in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDefaultPerf.js 20:21-48

ERROR in ./~/react/lib/ReactServerRenderingTransaction.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactPutListenerQueue in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactServerRenderingTransaction.js 17:28-62

ERROR in ./~/react/lib/EventPluginHub.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/EventPluginHub.js 19:16-38

ERROR in ./~/react/lib/EventPluginRegistry.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/EventPluginRegistry.js 15:16-38

ERROR in ./~/react/lib/CallbackQueue.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/CallbackQueue.js 17:16-38

ERROR in ./~/react/lib/ViewportMetrics.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./getUnboundedScrollPosition in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ViewportMetrics.js 14:33-72

ERROR in ./~/react/lib/Transaction.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/Transaction.js 14:16-38

ERROR in ./~/react/lib/ReactNativeComponent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactNativeComponent.js 15:16-38

ERROR in ./~/react/lib/SyntheticEvent.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./emptyFunction in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/SyntheticEvent.js 18:20-46

ERROR in ./~/react/lib/ReactDOMIDOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMIDOperations.js 23:16-38

ERROR in ./~/react/lib/ReactReconcileTransaction.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactPutListenerQueue in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactReconcileTransaction.js 19:28-62

ERROR in ./~/react/lib/LinkedValueUtils.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/LinkedValueUtils.js 17:16-38

ERROR in ./~/react/lib/setInnerHTML.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/setInnerHTML.js 14:27-60

ERROR in ./~/react/lib/ReactInputSelection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./containsNode in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactInputSelection.js 16:19-44

ERROR in ./~/react/lib/ReactInputSelection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./getActiveElement in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactInputSelection.js 18:23-52

ERROR in ./~/react/lib/ReactInputSelection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./focusNode in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactInputSelection.js 17:16-38

ERROR in ./~/react/lib/accumulateInto.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/accumulateInto.js 14:16-38

ERROR in ./~/react/lib/DOMChildrenOperations.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/DOMChildrenOperations.js 19:16-38

ERROR in ./~/react/lib/ReactDOMSelection.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/ReactDOMSelection.js 14:27-60

ERROR in ./~/react/lib/getTextContentAccessor.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/getTextContentAccessor.js 14:27-60

ERROR in ./~/react/lib/Danger.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ExecutionEnvironment in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/Danger.js 17:27-60

ERROR in ./~/react/lib/Danger.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./emptyFunction in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/Danger.js 20:20-46

ERROR in ./~/react/lib/Danger.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./invariant in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/Danger.js 22:16-38

ERROR in ./~/react/lib/Danger.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./createNodesFromMarkup in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/Danger.js 19:28-62

ERROR in ./~/react/lib/Danger.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./getMarkupWrap in /Users/chrisvh/Documents/Capstone/node_modules/react/lib
 @ ./~/react/lib/Danger.js 21:20-46

Multiple entrypoints: what about components?

The example makes sense for "pages", but what about components? Are pages just inferring a set of related components? Do you still need/should you have an entrypoint for each component in a system?

Multiple entry-points with React Router

@petehunt thank you for this explanatory repo! It has helped a lot! One question though related to React router, how do you split entry points based upon routes? I want hitting a particular router to load another set of code.

For example, to lazy load code inside the About.js module, would you just wrap it in a require.ensure statement? Or is there something more magical with react-router and webpack? @rpflorence

Worth adding requirement of having webpack installed?

It's only a small point, but I wonder if it's worth updating the README to indicate that in order to get the example running, you need to have webpack installed?

And in order for the commands in the How to invoke webpack section of the README to work unchanged, webpack needs to be installed globally.

Happy to update & submit PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.