Skip to content

Commit 8ca98e3

Browse files
Michel HerszakMichel Herszak
authored andcommitted
Update extract-text-webpack-plugin to 2.1.0
1 parent f07c01c commit 8ca98e3

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
"eslint-plugin-import": "^2.2.0",
179179
"eslint-plugin-jsx-a11y": "^4.0.0",
180180
"eslint-plugin-react": "^6.10.0",
181-
"extract-text-webpack-plugin": "2.0.0-beta.5",
181+
"extract-text-webpack-plugin": "2.1.0",
182182
"file-loader": "^0.10.0",
183183
"font-awesome": "^4.7.0",
184184
"font-awesome-webpack": "^0.0.4",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @summary: The encoder function is capable to apply either incoming strings from webpack modules or objects.
3+
* @param loader
4+
* @returns {string}
5+
*/
6+
function encodeLoader(loader) {
7+
if (typeof loader === 'string') {
8+
return loader;
9+
}
10+
11+
if (typeof loader.options !== 'undefined') {
12+
const query = Object
13+
.keys(loader.options)
14+
.map((param) => `${encodeURIComponent(param)}=${encodeURIComponent(loader.options[param])}`)
15+
.join('&');
16+
return `${loader.loader}?${query}`;
17+
}
18+
return loader.loader;
19+
}
20+
21+
/**
22+
* buildExtractStylesLoader can also deal with options without any trouble as
23+
* it converts them to query parameters if needed.
24+
*/
25+
module.exports = function buildExtractStylesLoader(loaders) {
26+
const extractTextLoader = encodeLoader(loaders[0]);
27+
const fallbackLoader = encodeLoader(loaders[1]);
28+
29+
const restLoaders = loaders
30+
.slice(2)
31+
.map((loader) => {
32+
if (typeof loader === 'string') {
33+
return loader;
34+
}
35+
return encodeLoader(loader);
36+
});
37+
38+
return [
39+
extractTextLoader,
40+
fallbackLoader,
41+
...restLoaders,
42+
].join('!');
43+
};
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
const buildExtractStylesLoader = require('./buildExtractStylesLoader');
12
const fontAwesomeConfig = require('./font-awesome.config.js');
23
const ExtractTextPlugin = require('extract-text-webpack-plugin');
3-
fontAwesomeConfig.styleLoader = ExtractTextPlugin.extract({
4-
fallbackLoader: 'style-loader',
5-
loader: 'css-loader!less-loader'
6-
});
4+
5+
/**
6+
* buildExtractStylesLoader can also deal with options without any trouble as
7+
* it converts them to query parameters if needed.
8+
*/
9+
fontAwesomeConfig.styleLoader = buildExtractStylesLoader(ExtractTextPlugin.extract({
10+
fallback: 'style-loader',
11+
use: ['css-loader', 'less-loader'],
12+
}));
713
module.exports = fontAwesomeConfig;

0 commit comments

Comments
 (0)