我正在嘗試將基於requireJS的應用程序遷移到webpack。webpack捆綁包大小vs requirejs捆綁包大小
這個應用程序沒有很多依賴 - 實際上它只需要一個承諾填充 - 我已經想出瞭如何使用縮小的webpack來製作webpack。
使用requireJS的包的大小爲43KB,使用webpack時爲121KB。
雖然121KB並不是真的很大,但它是一個顯着的尺寸增加。
從運行webpack --display-reasons --display-modules
我知道我的包中似乎有一些node_module依賴關係。比我預想的方式。
我看到的東西像buffer
,readable-stream
,stream-http
,stream-browserify
,core-util-is
,buffer-shims
...
是對的WebPack包裝代碼的這一預期/一部分?
有什麼我可以做,以排除這些依賴關係?
這是我webpack.config.js:
var webpack = require('webpack');
module.exports = {
entry: {
"mynexuz": "./js/mynexuz-api.js",
"kws": "./js/kws-api.js",
"main": "./js/main.js",
"quest": "./js/quest.js"
},
output: {
filename: "./dist/[name]-bundle.js",
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
}
})
],
node: {
//stream: false,
//process: false,
//global: false
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
modules: ['js', 'js/lib', 'node_modules'],
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
loaders: [
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
test: /\.js$/,
loader: "source-map-loader",
exclude: /node_modules/
},
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
loader: "awesome-typescript-loader",
exclude: /node_modules/
}
]
},
};
這很有趣;我想發佈你的Webpack配置和一些關於你的源代碼依賴的線索會有所幫助。 –
43KB是否包含RequireJS本身? –
這是沒有requireJS本身 –