I am currently working on a project and I need to configure WebPack . In the project, we also use ReactJS and Semantic-UI . Here is webpack.config.js :
var path = require("path"); var webpack = require('webpack'); var BundleTracker = require('webpack-bundle-tracker'); var BundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; module.exports = { context: __dirname, entry: { react: ["react", "react-dom"], home: './assets/js/index.jsx', }, output: { path: path.resolve('./assets/bundles/'), filename: "[name].js", }, plugins: [ new BundleTracker({filename: './webpack-stats.json'}), new webpack.optimize.CommonsChunkPlugin({ names: ["react"], }), new webpack.optimize.CommonsChunkPlugin({ name: "home", chunks: ['home'], filename: "[name]-[hash].js", }), new BundleAnalyzer(), ], module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader', options: { presets: ["es2015", "react"] } }, ], }, resolve: { modules: ['node_modules', 'bower_components'], extensions: ['*', '.js', '.jsx'] }, };
In the assets / js / index.jsx file , we have only these import statements:
import React from "react"; import ReactDOM from 'react-dom'; import { Button } from 'semantic-ui-react';
Running the webpack command, it issues two files:
- react.js: 779KB
- home- [some_hash_number] .js: 1.5 MB
Using the webpack-bundle-analyzer plugin, we get the following:

As you see the red rectangle in the picture, all semantic-ui interaction components are inserted into the home.js file, although I just imported the Button component from the assets / js / index.js file and therefore the output file is getting too big.
Is it possible to simply link the necessary components?
UPDATE
Reading @Alexander Fedyashov's answer, I installed babel-plugin-lodash and updated webpack.config.js accordingly:
var path = require("path"); var webpack = require('webpack'); var BundleTracker = require('webpack-bundle-tracker'); var BundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; module.exports = { context: __dirname, entry: { react: ["react", "react-dom"], home: './assets/js/index.jsx', }, output: { path: path.resolve('./assets/bundles/'), filename: "[name].js", }, plugins: [ new BundleTracker({filename: './webpack-stats.json'}), new webpack.optimize.CommonsChunkPlugin({ name: "react", }), new webpack.optimize.CommonsChunkPlugin({ name: "home", chunks: ['home'], filename: "[name]-[hash].js", }), new BundleAnalyzer(), ], module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader', options: { plugins: ["lodash", { "id": ["lodash", "semantic-ui-react"] }], presets: ["es2015", "react"], } }, ], }, resolve: { modules: ['node_modules', 'bower_components'], extensions: ['*', '.js', '.jsx'] }, };
Now everything works and only the necessary components are loaded.