我有一个 TypeScript 项目,它使用节点包和 webpack 来编译和捆绑。
我的文件夹结构是;
Scripts
App
Various Modules
Utility
Various Utility components and helpers
Index.tsx
我的 webpack 配置看起来像;
const path = require('path');
const nodeExternals = require('webpack-node-externals');
function srcPath(subdir) {
return path.join(__dirname, 'Scripts', subdir);
}
config = {
mode: 'development',
entry: './Scripts/Index.tsx',
output: {
filename: 'scripts/js/bundle.js',
path: __dirname + '/wwwroot'
},
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
resolve: {
// resolve shortened import paths
alias: {
App: srcPath('App'),
Utility: srcPath('Utility')
},
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.json']
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
transpileOnly: true
}
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' }
]
},
optimization: {
minimize: false,
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial',
enforce: true
}
}
}
},
target: 'web'
};
module.exports = config;
然后生成 2 个文件;bundle.js
这是我所有的代码,vendor.bundle.js
也是编译和捆绑的所有 node_packages。
目前,这平均需要 9 秒才能完成。这是该项目处于非常早期阶段的情况。我担心的是,随着项目的发展,等待时间会增加。
有没有办法缓存它,vendor.bundle.js
所以每次运行时都不会编译和捆绑它webpack
?