私はCommonsChunkPluginを設定するためのいくつかのガイドラインに従ってきましたが、動作していないようです。私はここでも他の記事を検索して読んだことがありますが運がありません。Webpack&TypeScript CommonsChunkPluginが動作しない
私は3つのファイル(TypeScript)を持ち、同じライブラリ(fancybox、moment、pikaday)のうちのいくつかをインポートしています。彼らは、ESモジュールの構文を使用してインポートされています:
import * as fancybox from 'fancybox';
import * as moment from 'moment';
import * as pikaday from 'pikaday';
マイtsconfig.json
出力ES6の構文とモジュールに設定されています:
{
"compileOnSave": true,
"compilerOptions": {
"target": "es6",
"module": "es6",
"noEmitOnError": true,
"moduleResolution": "node",
"sourceMap": true,
"diagnostics": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"traceResolution": false
},
"exclude": [
"node_modules",
"venue-finder"
]
}
マイwebpack.config.js
:
const webpack = require('webpack');
const path = require('path');
const WebpackNotifierPlugin = require('webpack-notifier');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = [{
bail: true,
entry: {
global: path.resolve(__dirname, 'js/responsive/global.ts'),
todo: path.resolve(__dirname, 'js/todo/todo.ts'),
budget: path.resolve(__dirname, 'Planner/javascript/Budget/BudgetPlannerUI.ts'),
promotions: path.resolve(__dirname, 'js/promotions-management.ts'),
planner: path.resolve(__dirname, 'Planner/javascript/MyPlanner.ts')
},
output: {
path: path.resolve(__dirname, 'dist/js'),
filename: '[name].js'
},
module: {
rules: [{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
'presets': [
['env', {
'modules': false
}]
]
}
},
{
loader: 'ts-loader'
}
]
}]
},
plugins: [
new WebpackNotifierPlugin({ alwaysNotify: true }),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
filename: 'commons-bundle.js',
minchunks: 2
}),
new BundleAnalyzerPlugin()
],
resolve: {
extensions: ['.js', '.ts', '.tsx']
},
devtool: 'none'
}];
を私の知る限り見ることができるように2回以上使用されているチャンク(3つあります)を見つけて、commons-bundle.js
に移動する必要がありますが、を実行するとと出力ファイルを見ると、pikaday、moment、fancyboxはすべて移動するのではなく、各ファイルに含まれていることが分かります。commons-bundle.js
助けてくれれば幸いです。
、おかげで多くのことを。 – descendent
ありがとう、これは私を助けた。ただし、node_moduleにない共通モジュールは移動しません。上の関数を少し変更すると、両方の場合がサポートされます: 'return(module.context && module.context.indexOf(" node_modules ")!== -1)|| count> = 2; ' – Paul