2016-08-12 19 views

回答

2

從文檔:從/到一個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只是一個空文件。

使用 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的使用情況下,你需要如何束腳本熟悉。在上述應用程序的情況下,輸出將等同於:

(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。

+1

我還發現在使用CommonChunksPlugin時,這對於LT緩存是必需的。 – wlingke

+0

因此,這將在我的本地計算機中創建一個文件,然後將其添加到.gitignore之類的文件中? –

+0

@RafaelEyng看起來像推薦檢查它 - https://webpack.js.org/configuration/other-options/#recordspath – olore