Я изучаю веб-пакет и пытаюсь уменьшить размер пакета приложения с 2,14 МБ до менее, используя Treeshaking с Babel 7.
Но это уменьшает размер до нескольких байтов.
Почемуэто происходит, даже если я выполнил все шаги в документах Webpack?Это приложение не настолько маленького размера в байтах.
ЗДЕСЬ МОИ КОНФИГУРАЦИИ
.babelrc
{
"presets": [["@babel/preset-env",{ "modules": false }], "@babel/preset-react"],
"plugins": ["react-html-attrs", "@babel/plugin-proposal-class-properties","react-hot-loader/babel"]
}
Package.json
{
"name": "ibism-frontend-2",
"version": "1.0.0",
"description": "",
"main": "./src/app.js",
"sideEffects": false,
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"webpack": "^4.16.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "^3.1.4",
"webpack-merge": "^4.1.2"
},
"dependencies": {
"axios": "^0.16.1",
"jwt-decode": "^2.2.0",
}
}
Webpack.config.js
let debug = process.env.NODE_ENV !== "production";
let webpack = require('webpack');
let path = require('path');
let define = new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
});
let ignore = new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
const HtmlWebPackPlugin = require("html-webpack-plugin");
module.exports = {
optimization:{
usedExports:true,
},
devServer:{
// inline: true,
contentBase: path.resolve(__dirname, "dist"),
historyApiFallback: true,
// hot:true
// port: 8081
},
watch: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000, //seems to stablise HMR file change detection
ignored: /node_modules/
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules/, // or u can also do this path.join(__dirname, 'src')
include: path.resolve(__dirname, "src"),
use:{
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: ['style-loader','css-loader']
},
]
},
plugins: [
ignore,
new HtmlWebPackPlugin({
template: "./src/index.ejs",
filename: "./index.html",
// hash:true
}),
],
};
РЕЗУЛЬТАТ:
Asset Size Chunks Chunk Names
main.js 951 bytes 0 [emitted] main
. / Index.html 2,05 КиБ [испущено]