javascript – react-dom吹出webpack捆绑大小MASSIVELY
作者:互联网
这一直是我遇到的webpack最奇怪的问题之一……
react-dom 533.24KB – 认真的WTF
我认为它可能是我的依赖项中的损坏,但nuking node_modules并重新安装没有任何影响.我想这与webpack捆绑它的方式有关,但是我迷失了想法.我正在处理.js进口的方式是相当的股票标准.
// webpack.config.js
const path = require('path');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const Dashboard = require('webpack-dashboard');
const DashboardPlugin = require('webpack-dashboard/plugin');
const dashboard = new Dashboard();
module.exports = {
context: path.join(__dirname, 'src'),
entry: {
bundle: './index.js',
},
output: {
filename: 'bundle.js',
path: path.join(__dirname, 'build'),
},
module: {
rules: [
{
test: /\.html$/,
use: 'file-loader?name=[name].[ext]',
},
{
test: /.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
'postcss-loader',
],
}),
},
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
],
},
plugins: [
// new BundleAnalyzerPlugin(),
new ExtractTextPlugin('styles.css'),
new DashboardPlugin(dashboard.setData),
],
devServer: {
quiet: true,
},
};
// .babelrc
{
"presets": [
"react",
"es2015"
],
"plugins": ["transform-object-rest-spread"]
}
解决方法:
http://elijahmanor.com/react-file-size/
在v15.4.0中,react-dom的文件大小从1.17kB增加到619.05kB.这意味着我的webpack设置没有做任何错误的捆绑文件.这个模块变得如此庞大的原因是因为代码是从react模块传输的.
标签:javascript,reactjs,webpack-2,react-dom,babel-loader 来源: https://codeday.me/bug/20190611/1217865.html