2016-11-20 51 views
0

當使用webpack(1.13.3)和webpack-split-by-path(0.0.10)時,即使我沒有在任何地方使用uglify插件,webpack仍會忽略所有塊。這是爲什麼?不使用分路徑插件時,不使用uglify(如預期的那樣)。即使沒有插件,webpack爲什麼會醜化所有的塊?

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") 
); 

回答

1

uglify是什麼意思?你說變量名正在被破壞?或者只是JavaScript正在被重新格式化/縮小?

否則,當您使用-p(生產)標誌運行webepack時,它將會縮小文件。

+0

doh ...剛剛意識到我在package.json腳本中加了'-p'。我在最後一個小時一直在努力,可能更多! – astro101

+0

很高興幫助。謝謝你的觀點。 –

相關問題