私はドキュメントを何度も読んだことがありますが、webpackの設定でrecordsPath
エントリを使用したい(またはしたくない)のはいつも混乱しています。誰かがもっと素人で説明できますか?ウェブパック設定の "recordsPath"の目的は何ですか?
また、上記のwebpack 1.xと2.xの違いは何ですか?ドキュメントから
私はドキュメントを何度も読んだことがありますが、webpackの設定でrecordsPath
エントリを使用したい(またはしたくない)のはいつも混乱しています。誰かがもっと素人で説明できますか?ウェブパック設定の "recordsPath"の目的は何ですか?
また、上記のwebpack 1.xと2.xの違いは何ですか?ドキュメントから
:JSONファイルへ/から
ストア/ロードコンパイラ状態。これにより、モジュールとチャンクの永続IDは になります。
絶対パスが必要です。 recordsPathはrecordsInputPath に使用され、recordsOutputPathは未定義のままの場合は使用されます。
これは、複数の のコンパイラ呼び出し間でホットコード置換を使用する場合に必要です。
https://webpack.github.io/docs/configuration.html#recordspath-recordsinputpath-recordsoutputpath
次のような構造を持つシンプルなアプリとし、一例を挙げれば:
require('./test.js');
と./src/test.js
ちょうど空のファイルです:./src/index.js
がある
./src
├── index.js
└── test.js
を。
node.js APIを使用してファイルをコンパイルします。
const webpack = require('webpack');
const webpackConfig = {
entry: {
'app': [
path.resolve(__dirname, './src')
]
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js'
},
recordsPath: path.resolve(__dirname, './recordsPath.json')
};
const compiler = webpack(webpackConfig,() => {});
それは./recordsPath.json
を生成します。
{
"modules": {
"byIdentifier": {
"src/index.js": 0,
"src/test.js": 1
},
"usedIds": {
"0": 0,
"1": 1
}
},
"chunks": {
"byName": {
"app": 0
},
"byBlocks": {},
"usedIds": {
"0": 0
}
}
}
は、モジュールIDのユースケースを理解するには、どのようにwebpackバンドルスクリプトを理解する必要があります。上記のアプリケーションの場合、出力は次のようになります。
(function(modules) {
// Module resolution logic.
// Excluded for brevity.
})
([
function(module, exports, __webpack_require__) {
// ./index.js
__webpack_require__(1);
},
function(module, exports) {
// ./test.js
}
]);
ご覧のとおり、内部ではwebpackはIDを使用してモジュールを参照しています。 recordsPath
はこれらのIDを公開します。
これは、CommonChunksPluginで使用するときにLTキャッシングに必要であることも発見しました。 – wlingke
これは私のローカルマシンのプロジェクトの中にファイルを作成し、それを.gitignoreなどに追加します。 –
@RafaelEyngは、チェックインするのがおすすめです - https://webpack.js.org/configuration/other-options/#recordspath – olore