Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var webpack = require("webpack");
- var CleanPlugin = require("clean-webpack-plugin");
- var ExtractTextPlugin = require("extract-text-webpack-plugin");
- var production = process.env.NODE_ENV === "production";
- var plugins = [
- new ExtractTextPlugin("bundle.css"),
- new webpack.optimize.CommonsChunkPlugin({
- name: "main",
- children: true,
- minChunks: 2
- })
- ];
- if(production)
- {
- plugins = plugins.concat([
- // Cleanup the builds/ folder before
- // compiling our final assets
- new CleanPlugin('builds'),
- // This plugin looks for similar chunks and files
- // and merges them for better caching by the user
- new webpack.optimize.DedupePlugin(),
- // This plugins optimizes chunks and modules by
- // how much they are used in your app
- new webpack.optimize.OccurenceOrderPlugin(),
- // This plugin prevents Webpack from creating chunks
- // that would be too small to be worth loading separately
- new webpack.optimize.MinChunkSizePlugin({
- minChunkSize: 51200, // ~50kb
- }),
- // This plugin minifies all the Javascript code of the final bundle
- new webpack.optimize.UglifyJsPlugin({
- mangle: true,
- compress: {
- warnings: false, // Suppress uglification warnings
- },
- }),
- // This plugins defines various variables that we can set to false
- // in production to avoid code related to them from being compiled
- // in our final bundle
- new webpack.DefinePlugin({
- __SERVER__: !production,
- __DEVELOPMENT__: !production,
- __DEVTOOLS__: !production,
- 'process.env': {
- BABEL_ENV: JSON.stringify(process.env.NODE_ENV),
- },
- }),
- ]);
- }
- module.exports = {
- entry: "./src",
- output: {
- path: "builds",
- filename: production ? "[name]-[hash].js" : "bundle.js",
- chunkFilename: "[name]-[chunkhash].js",
- publicPath: "builds/"
- },
- debug: !production,
- devtool: production ? false : "eval",
- devServer: {
- hot: true
- },
- module: {
- loaders: [
- {
- test: /\.js$/,
- exclude: /(node_modules)/,
- loader: "babel-loader",
- query: {
- presets: ["es2015", "react"],
- plugins: ["transform-class-properties"]
- }
- },
- {
- test: /\.scss/,
- loader: ExtractTextPlugin.extract("style", "css!sass")
- },
- {
- test: /\.html/,
- loader: "html"
- },
- {
- test: /\.(png|gif|jpe?g|svg)$/i,
- loader: "url",
- query: {
- limit: 10000,
- }
- }
- ]
- },
- plugins: plugins
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement