Skip to content

Commit 0cfc702

Browse files
Gowrav ShekarGowrav Shekar
authored andcommitted
Added flexibility to customise loaders
1 parent dbc79bf commit 0cfc702

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,13 @@ Example:
9292

9393
### extract-text-webpack-plugin
9494

95-
Configure post style loaders in `font-awesome.config.js`.
95+
Configure style loader in `font-awesome.config.js`.
9696

9797
Example:
9898

9999
``` javascript
100100
module.exports = {
101-
postStyleLoaders: [
102-
require.resolve('extract-text-webpack-plugin/loader.js') + '?{"omit":1,"extract":true,"remove":true}'
103-
],
101+
styleLoader: require('extract-text-webpack-plugin').extract('style-loader', 'css-loader!less-loader'),
104102
styles: {
105103
...
106104
}

font-awesome.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
2+
// Default for the style loading
3+
styleLoader: 'style-loader!css-loader!less-loader',
4+
25
styles: {
36
'mixins': true,
47
'bordered-pulled': true,

index.loader.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
module.exports = function() {
22
};
3-
module.exports.pitch = function(remainingRequest) {
4-
this.cacheable(true);
5-
var config = require(this.resourcePath);
6-
var postStyleLoaders = '';
7-
if((typeof config.postStyleLoaders !== 'undefined') && (config.postStyleLoaders.length > 0)){
8-
postStyleLoaders = config.postStyleLoaders.join('!') + '!';
9-
}
10-
return [
11-
'require(' + JSON.stringify("-!" + postStyleLoaders + require.resolve("style-loader") + '!' + require.resolve("css-loader") +
12-
'!' + require.resolve("less-loader") + '!' + require.resolve("./font-awesome-styles.loader.js") + '!' + remainingRequest) + ');'
13-
].join("\n");
14-
};
3+
4+
module.exports.pitch = function (remainingRequest) {
5+
6+
// Webpack 1.7.3 uses this.resourcePath. Leaving in remaining request for possibly older versions
7+
// of Webpack
8+
var configFilePath = this.resourcePath || remainingRequest;
9+
this.cacheable(true);
10+
11+
if (!configFilePath || configFilePath.trim() === '') {
12+
var msg = 'You specified the font-awesome-webpack with no configuration file. Please specify' +
13+
' the configuration file, like: \'font-awesome-webpack!./font-awesome.config.js\' or use' +
14+
' require(\'font-awesome-webpack\').';
15+
console.error('ERROR: ' + msg);
16+
throw new Error(msg);
17+
}
18+
19+
var config = require(configFilePath);
20+
var styleLoader = config.styleLoader || 'style-loader!css-loader!less-loader';
21+
22+
var styleLoaderCommand = 'require(' + JSON.stringify('-!' + styleLoader + '!' +
23+
require.resolve('./font-awesome-styles.loader.js') + '!' + configFilePath) + ');';
24+
return styleLoaderCommand;
25+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "font-awesome-webpack",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "font-awesome package for webpack",
55
"main": "index.js",
66
"loader": "index.loader.js",

0 commit comments

Comments
 (0)