当webpack(1.13.3)与webpack-split-by-path(0.0.10)一起使用时,即使我没有在任何地方使用uglify插件,webpack仍然可以解决所有问题。这是为什么?不使用split-by-path插件时,不使用uglify(如预期的那样)。
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")
);
答案 0 :(得分:1)
uglify是什么意思?你是说变量名被破坏了吗?或者仅仅是JavaScript正在重新格式化/缩小?
否则,当你使用-p(生产)标志运行webepack时,它会缩小你的文件。