const path = require('path'); const File = require('../File'); const { Component } = require('./Component'); /** @typedef {import('../../types/extract').Extraction} Extraction */ /** @typedef {import('../../types/extract').ExtractConfig} ExtractConfig */ /** @typedef {import('../builder/Entry')} Entry */ module.exports = class Extract extends Component { /** @type {Entry|null} */ entry = null; /** @type {Extraction[]} */ extractions = []; /** * The name of the component. * * mix.extract() or mix.extractVendor() */ name() { return ['extract', 'extractVendors']; } /** * Register the component. * * @param {ExtractConfig} [config] * @param {string} [output] */ register(config = null, output = null) { this.context.chunks.runtime = true; this.extractions.push(this.normalizeExtraction(config, output)); } /** * Assets to append to the webpack entry. * * @param {Entry} entry */ webpackEntry(entry) { this.entry = entry; this.context.chunks.entry = entry; if (!this.context.bundlingJavaScript) { throw new Error('You must compile JS to extract vendor code'); } this.extractions.forEach(extraction => { const path = this.extractionPath(extraction.to); const isDefaultVendorChunk = extraction.to === null || extraction.to === undefined || extraction.test.source === '(? `${lib}[\\\\/]`).join('|'); } else if (libraries instanceof RegExp) { extra = libraries.source; } else { throw new Error( `Unexpected type [${typeof libraries}] passed to mix.extract({ libraries: … }). ` + `You may pass either an array of strings or a regular expression.` ); } return new RegExp(`${pattern}(${extra})`, 'i'); } };