UNPKG

2.01 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _constructorIndexInArray = require('./constructorIndexInArray');
8
9var _constructorIndexInArray2 = _interopRequireDefault(_constructorIndexInArray);
10
11function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13/**
14 * Get the common chunk filename from the CommonsChunkPlugin options
15 *
16 * @param {Object} commonsChunkOptions
17 *
18 * @return {String} The common chunk filename
19 */
20var getCommonsChunkFilename = function getCommonsChunkFilename(pluginOptions) {
21 // Detect CommonsChunkPlugin usage
22 var commonsChunkPluginIndex = (0, _constructorIndexInArray2.default)(pluginOptions, 'CommonsChunkPlugin');
23
24 // Get the filename of the common chunk
25 var commonsChunkFilename = void 0;
26 if (commonsChunkPluginIndex !== false) {
27 var commonsChunkOptions = pluginOptions[commonsChunkPluginIndex];
28 // Called like "new CommonsChunkPlugin('somename')"
29 if (commonsChunkOptions.filenameTemplate === commonsChunkOptions.chunkNames) {
30 commonsChunkFilename = commonsChunkOptions.chunkNames + '.js';
31 // Called like "new CommonsChunkPlugin({ filename: 'somefilename.js' })"
32 } else if (commonsChunkOptions.filenameTemplate) {
33 commonsChunkFilename = commonsChunkOptions.filenameTemplate;
34 // Called like "new CommonsChunkPlugin({ name: 'somename' })"
35 } else if (commonsChunkOptions.chunkNames) {
36 commonsChunkFilename = commonsChunkOptions.chunkNames + '.js';
37 // Don't know if this can actually happen, better to have it there just in case
38 } else {
39 // eslint-disable-next-line no-console
40 console.log('[CarteBlanche] We detected you use the CommonsChunkPlugin, ' + 'but we could not detect the filename of the common chunk. Please use the ' + '"filename" option of the CommonsChunkPlugin.');
41 }
42 }
43 return commonsChunkFilename;
44};
45
46exports.default = getCommonsChunkFilename;
\No newline at end of file