MCPcopy Index your code
hub / github.com/andywer/webpack-blocks / extractText

Function extractText

packages/extract-text/index.js:15–53  ·  view source on GitHub ↗

* @param {string} outputFilePattern * @return {Function}

(outputFilePattern = 'css/[name].[contenthash:8].css')

Source from the content-addressed store, hash-verified

13 * @return {Function}
14 */
15function extractText(outputFilePattern = 'css/[name].[contenthash:8].css') {
16 const plugin = new ExtractTextPlugin(outputFilePattern)
17
18 const postHook = (context, util) => prevConfig => {
19 let nextConfig = prevConfig
20
21 // Only apply to loaders in the same `match()` group or css loaders if there is no `match()`
22 const ruleToMatch = context.match || { test: /\.css$/ }
23 const matchingLoaderRules = getMatchingLoaderRules(ruleToMatch, prevConfig)
24
25 if (matchingLoaderRules.length === 0) {
26 throw new Error(
27 `extractText(): No loaders found to extract contents from. Looking for loaders matching ${
28 ruleToMatch.test
29 }`
30 )
31 }
32
33 const [fallbackLoaders, nonFallbackLoaders] = splitFallbackRule(matchingLoaderRules)
34
35 const newLoaderDef = Object.assign({}, ruleToMatch, {
36 use: plugin.extract({
37 fallback: fallbackLoaders,
38 use: nonFallbackLoaders
39 })
40 })
41
42 for (const ruleToRemove of matchingLoaderRules) {
43 nextConfig = removeLoaderRule(ruleToRemove)(nextConfig)
44 }
45
46 nextConfig = util.addPlugin(plugin)(nextConfig)
47 nextConfig = util.addLoader(newLoaderDef)(nextConfig)
48
49 return nextConfig
50 }
51
52 return Object.assign(() => prevConfig => prevConfig, { post: postHook })
53}
54
55function getMatchingLoaderRules(ruleToMatch, webpackConfig) {
56 return webpackConfig.module.rules.filter(

Callers 5

productionConfigFunction · 0.85
webpack.config.jsFile · 0.85
webpack.config.jsFile · 0.85
webpack.config.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…