これは私のwebpack.dev.config.js私はこのように、webpack-dev-server
と開発にそれを実行するためにnpm start
を使用 WebPACKのパッケージサイズを小さくする方法
"use strict";
let webpack = require('webpack');
let path = require('path');
// let HtmlWebpackPlugin = require('html-webpack-plugin');
// let ExtractTextPlugin = require("extract-text-webpack-plugin");
const WebpackBrowserPlugin = require('webpack-browser-plugin');
const vendors = ['react', 'react-dom', 'react-router'];
module.exports = {
devtool: 'cheap-eval-source-map',
devServer: {
port: 3001,
hot: true,
hotOnly: true,
inline: true,
watchContentBase: true,
watchOptions: {
poll: true
},
contentBase: "./src",
compress: true,
historyApiFallback: true,
clientLogLevel: "none",
proxy: {
'/sms-web/*': {
target: 'http://localhost:9099',
changeOrigin: true,
secure: false
}
}
},
entry: {
app: "./src/main.js", //
vendors: vendors //第三方库
}, //入口文件
output: {
path: path.join(__dirname, "src"),
publicPath: "",
filename: "[name].bundle.js"
},
resolve: {
extensions: [".js", ".jsx", ".tsx", ".ts"] //resolve.extensions 用于指明程序自动补全识别哪些后缀,
},
module: {
//各种加载器,即让各种文件格式可用require引用
rules: [{
test: /\.js|jsx$/,
loader: "babel-loader",
exclude: "/node_modules/",
options: {
presets: ['es2015', 'react']
}
}, {
test: /\.css$/,
exclude: "/node_modules/",
// loader: ExtractTextPlugin.extract("css-loader")
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}, {
test: /\.less$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{ loader: "less-loader" },
]
}, {
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: "url-loader",
query: {
limit: 10000
}
}]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new WebpackBrowserPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
},
mangle: {
screw_ie8: true
},
output: {
comments: false,
screw_ie8: true
},
except: ['$super', '$', 'exports', 'require'] //排除关键字
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['vendors'],
filename: "vendors.bundle.js",
minChunks: Infinity
}),
]
};
"start": "webpack-dev-server --config webpack.config.dev.js"
しかし、同梱の場合
Version: webpack 2.3.3
Time: 17035ms
Asset Size Chunks Chunk Names
app.bundle.js 90 kB 0 [emitted] app
vendors.bundle.js 3.33 MB 1 [emitted] [big] vendors
chunk {0} app.bundle.js (app) 33.5 kB {1} [initial] [rendered]
ベンダーは3.33Mですので、reactでreact-dom.react-routerを使用してくださいまたは、それが正常であることを知りたい、または減らすべきことをしたいのですか?
あなたの設定はあまり役に立ちません.Webpackの統計情報を共有してください。 'webpack --profile --json> stats.json'を実行し、stats.jsonをアップロードします。 https://github.com/th0r/webpack-bundle-analyzerツールを使用してバンドルのサイズマップのスクリーンショットを撮って、ここで共有することもできます。 – hazardous
私はこの方法を試して、それは251個のモジュールを持っています。なぜそれほど大きいですか? –
示されている通りにstats.jsonを利用可能にしてください。 – hazardous