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,OAAL,CAAa,QAAlB,EAA4B;AAC1B,wBAAM,KAAN,CAAY,MAAZ,CAAmB,MAAM,KAAN,CAAY,OAAZ,CAAoB,MAAM,IAA1B,CAAnB,EAAoD,CAApD;AACA,yBAAO,OAAO,MAAM,IAAb,CAAP;AACD;AACD,oBAAI,OAAJ,EAAa;AACX,yBAAO,OAAP,IAAkB,wBAAc,OAAd,CAAlB;AACA,wBAAM,KAAN,CAAY,IAAZ,CAAiB,OAAjB;AACD;AACF,eA1BD;AA2BA,qBAAO,QAAQ,OAAR,EAAP;AACD,aA7BM,CAAP;AA8BD,WAjCgB,CAAjB;AAkCA,kBAAQ,GAAR,CAAY,QAAZ,EAAsB,IAAtB,CAA2B,YAAM;AAC/B;AACD,WAFD,EAEG,IAFH;AAGD,SAtCD;AAuCD,OA1CD;AA2CD;;;;;;kBA5HkB,qB","file":"index.js","sourcesContent":["import postcss from 'postcss';\nimport chunk from './chunk';\nimport SourceMapSource from 'webpack/lib/SourceMapSource';\nimport RawSource from 'webpack/lib/RawSource';\nimport {interpolateName} from 'loader-utils';\n\n/**\n * Detect if a file should be considered for CSS splitting.\n * @param {String} name Name of the file.\n * @returns {Boolean} True if to consider the file, false otherwise.\n */\nconst isCSS = (name : string) : boolean => /\\.css$/.test(name);\n\n/**\n * Remove the trailing `/` from URLs.\n * @param {String} str The url to strip the trailing slash from.\n * @returns {String} The stripped url.\n */\nconst strip = (str : string) : string => str.replace(/\\/$/, '');\n\n/**\n * Create a function that generates names based on some input. This uses\n * webpack's name interpolator under the hood, but since webpack's argument\n * list is all funny this exists just to simplify things.\n * @param {String} input Name to be interpolated.\n * @returns {Function} Function to do the interpolating.\n */\nconst nameInterpolator = (input) => ({file, content, index}) => {\n const res = interpolateName({\n context: '/',\n resourcePath: `/${file}`,\n }, input, {\n content,\n }).replace(/\\[part\\]/g, index + 1);\n return res;\n};\n\n/**\n * Normalize the `imports` argument to a function.\n * @param {Boolean|String} input The name of the imports file, or a boolean\n * to use the default name.\n * @param {Boolean} preserve True if the default name should not clash.\n * @returns {Function} Name interpolator.\n */\nconst normalizeImports = (input, preserve) => {\n switch (typeof input) {\n case 'string':\n return nameInterpolator(input);\n case 'boolean':\n if (input) {\n if (preserve) {\n return nameInterpolator('[name]-split.[ext]');\n }\n return ({file}) => file;\n }\n return () => false;\n default:\n throw new TypeError();\n }\n};\n\n/**\n * Webpack plugin to split CSS assets into multiple files. This is primarily\n * used for dealing with IE <= 9 which cannot handle more than ~4000 rules\n * in a single stylesheet.\n */\nexport default class CSSSplitWebpackPlugin {\n /**\n * Create new instance of CSSSplitWebpackPlugin.\n * @param {Number} size Maximum number of rules for a single file.\n * @param {Boolean|String} imports Truish to generate an additional import\n * asset. When a boolean use the default name for the asset.\n * @param {String} filename Control the generated split file name.\n * @param {Boolean} preserve True to keep the original unsplit file.\n */\n constructor({\n size = 4000,\n imports = false,\n filename = '[name]-[part].[ext]',\n preserve,\n }) {\n this.options = {\n size,\n imports: normalizeImports(imports, preserve),\n filename: nameInterpolator(filename),\n preserve,\n };\n }\n\n /**\n * Generate the split chunks for a given CSS file.\n * @param {String} key Name of the file.\n * @param {Object} asset Valid webpack Source object.\n * @returns {Promise} Promise generating array of new files.\n */\n file(key : string, asset : Object) {\n // Use source-maps when possible.\n const input = asset.sourceAndMap ? asset.sourceAndMap() : {\n source: asset.source(),\n };\n const name = (i) => this.options.filename({\n ...asset,\n content: input.source,\n file: key,\n index: i,\n });\n return postcss([chunk({\n ...this.options,\n result: (i) => {\n return {\n to: name(i),\n from: key,\n map: {\n inline: false,\n prev: input.map,\n },\n };\n },\n })]).process(input.source, {\n from: key,\n }).then((result) => {\n return Promise.resolve({\n file: key,\n chunks: result.chunks.map(({css, map}, i) => {\n return new SourceMapSource(\n css,\n name(i),\n map.toString()\n );\n }),\n });\n });\n }\n\n /**\n * Run the plugin against a webpack compiler instance. Roughly it walks all\n * the chunks searching for CSS files and when it finds one that needs to be\n * split it does so and replaces the original file in the chunk with the split\n * ones. If the `imports` option is specified the original file is replaced\n * with an empty CSS file importing the split files, otherwise the original\n * file is removed entirely.\n * @param {Object} compiler Compiler instance\n * @returns {void}\n */\n apply(compiler : Object) {\n // Only run on `this-compilation` to avoid injecting the plugin into\n // sub-compilers as happens when using the `extract-text-webpack-plugin`.\n compiler.plugin('this-compilation', (compilation) => {\n const assets = compilation.assets;\n const publicPath = strip(compilation.options.output.publicPath || './');\n compilation.plugin('optimize-chunk-assets', (chunks, done) => {\n const promises = chunks.map((chunk) => {\n const input = chunk.files.filter(isCSS);\n const items = input.map((name) => this.file(name, assets[name]));\n return Promise.all(items).then((entries) => {\n entries.forEach((entry) => {\n // Skip the splitting operation for files that result in no\n // split occuring.\n if (entry.chunks.length === 1) {\n return;\n }\n // Inject the new files into the chunk.\n entry.chunks.forEach((file) => {\n assets[file._name] = file;\n chunk.files.push(file._name);\n });\n const content = entry.chunks.map((file) => {\n return `@import \"${publicPath}/${file._name}\";`;\n }).join('\\n');\n const imports = this.options.imports({\n ...entry,\n content,\n });\n if (!this.options.preserve) {\n chunk.files.splice(chunk.files.indexOf(entry.file), 1);\n delete assets[entry.file];\n }\n if (imports) {\n assets[imports] = new RawSource(content);\n chunk.files.push(imports);\n }\n });\n return Promise.resolve();\n });\n });\n Promise.all(promises).then(() => {\n done();\n }, done);\n });\n });\n }\n}\n"]}
\No newline at end of file