Search code examples
webpackuglifyjschunks

Why does webpack uglify all chunks even without the plugin?


When using webpack (1.13.3) with webpack-split-by-path (0.0.10), webpack is uglifying all chunks even though I'm not using the uglify plugin anywhere. Why is that? When not using the split-by-path plugin, uglify isn't used (as expected).

webpack.config.js:

const path = require('path');
const webpack = require('webpack');
const SplitByPathPlugin = require('webpack-split-by-path');

module.exports = {
    entry: "./src/index.tsx",
    output: {
        filename: "[name].js",
        chunkFilename: "[name].js",
        path: __dirname + "/dist"
    },
    devtool: "source-map",
    resolve: {
        extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },
    module: {
        loaders: [
            { test: /\.tsx?$/, loader: "ts-loader" }
        ],
        preLoaders: [
            { test: /\.js$/, loader: "source-map-loader" }
        ],
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': '"' + process.env.NODE_ENV + '"',
        }),
        new SplitByPathPlugin([
            { name: 'vendor', path: [path.join(__dirname, 'node_modules/')] },
        ]),
    ],
};

package.json:

{
    "name": "some-project",
    "version": "0.1.0",
    "description": "Some Project",
    "devDependencies": {
        "cross-env": "^3.1.3",
        "react": "^15.4.0",
        "react-dom": "^15.4.0",
        "source-map-loader": "^0.1.5",
        "ts-loader": "^1.2.2",
        "typescript": "^2.0.10",
        "typings": "^2.0.0",
        "webpack": "^1.13.3",
        "webpack-split-by-path": "^0.0.10"
    }
}

tsconfig.json:

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": false,
    "module": "commonjs",
    "target": "es5",
    "jsx": "react"
  },
  "include": [
    "./src/**/*",
    "./typings/index.d.ts"
  ],
  "exclude": [
    "./node_modules"
  ]
}

index.tsx:

import * as React from 'react';
import * as ReactDOM from 'react-dom';

ReactDOM.render(
    <div>Hello, world!</div>,
    document.getElementById("root")
);

Solution

  • What do you mean by uglify? You are saying variable names are being mangled? Or is it just that the JavaScript is being reformatted/minified?

    Otherwise, when you run webepack with the -p (production) flag it's going to minify your files.