I'm starting a React project with ES6 classes (and ESLint with airbnb config) and I need webpack to bundle them.
I started with the React tutorial and tried using const React = require('react');
and const $ = require('jquery');
, but I realized my bundle grew from 15 kb to 700 kb. I then decided to include jquery
, react
and react-dom
via <script/>
tags.
Hash: 082980fb232d17977e55
Version: webpack 1.13.0
Time: 869ms
Asset Size Chunks Chunk Names
bundle.js 13.3 kB 0 [emitted] app
+ 5 hidden modules
But when I remove the const React = require('react');
, I get errors in my code (e.g. : React must be in scope when using JSX - react/react-in-jsx-scope). I then read some docs about Webpack's externals
, and tried doing this :
module.exports = {
entry: {
app: './main.js',
},
output: {
filename: 'bundle.js',
},
externals: {
jquery: 'jQuery',
$: '$',
React: 'React',
ReactDOM: 'ReactDOM',
marked: 'marked',
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
},
],
},
};
But Webpack bundles them anyway, whereas I read here and here it shouldn't.
Hash: 6438094053346ce42228
Version: webpack 1.13.0
Time: 4975ms
Asset Size Chunks Chunk Names
bundle.js 709 kB 0 [emitted] app
+ 172 hidden modules
What am I missing?
Thanks in advance!