我已經閱讀過很多次的文檔,但是我仍然對我希望(或不想)在webpack配置中使用recordsPath
條目感到困惑。有人能以更通俗的語言解釋嗎?webpack配置中「recordsPath」的用途是什麼?
上述不同的webpack 1.x與2.x的答案也是?
我已經閱讀過很多次的文檔,但是我仍然對我希望(或不想)在webpack配置中使用recordsPath
條目感到困惑。有人能以更通俗的語言解釋嗎?webpack配置中「recordsPath」的用途是什麼?
上述不同的webpack 1.x與2.x的答案也是?
從文檔:從/到一個JSON文件
存儲/加載編譯狀態。這將導致 模塊和塊的持久性標識符。
預期絕對路徑。 recordsPath用於recordsInputPath 和recordsOutputPath(如果它們未定義)。
當在編譯器的多個調用 之間使用熱代碼替換時,這是必需的。
https://webpack.github.io/docs/configuration.html#recordspath-recordsinputpath-recordsoutputpath
舉個例子,假設一個簡單的應用程序結構如下:
./src
├── index.js
└── test.js
其中./src/index.js
是:
require('./test.js');
和./src/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