请输入代码
项目是react全站的单页应用,主要的库是antd+自己写的scss和一些表单,cookie等处理逻辑,.jsx大概有15个左右.用webpack构建的,在开发环境用的webpack-dev-server启动的,webpack.config.js如下图:'"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');
module.exports = {
devtool: 'cheap-eval-source-map',
devServer: {
hot: true,
inline: true,
contentBase: "./src",
proxy: {
'/sms-web/*': {
target: 'http://localhost:9099',
changeOrigin: true,
secure: false
}
}
},
// devtool: "source-map", //生成sourcemap,便于开发调试
entry: {
app: "./src/main.js", //
vendors: ['react', 'react-dom', 'moment', 'axios', 'recharts'] //第三方库
}, //入口文件
output: {
path: path.join(__dirname, "src"),
publicPath: "",
filename: "[name].bundle.js",
chunkFilename: "[id].[hash].bundle.js"
},
resolve: {
extensions: ["", ".js", ".jsx", ".tsx", ".ts"] //resolve.extensions 用于指明程序自动补全识别哪些后缀,
},
module: {
//各种加载器,即让各种文件格式可用require引用
loaders: [{
test: /\.js|jsx$/,
loader: ["babel"],
exclude: "/node_modules/",
query: {
presets: ['es2015', 'react']
}
}, {
test: /\.css$/,
exclude: "/node_modules/",
// loader: ExtractTextPlugin.extract("css-loader")
loader: "style-loader!css-loader"
}, {
test: /\.scss$/,
loader: "style!css!sass"
}, {
test: /\.(png|jpg|woff|woff2|eot|ttf|svg)/,
loader: 'url-loader?limit=40000'
}]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new WebpackBrowserPlugin(),
]
};'
构建出来的结果如下图:
app.bundle.js居然达到了16.3M.不过只是在开发环境下,没有压缩js文件,
在生产环境中build后,app.bundle.js只有1M多点了:
还有什么办法能在优化下吗?
有没有用
babel-plugin-import
把antd按需引入?https://segmentfault.com/q/10...