Skip to content

Commit

Permalink
Added flexibility to customise loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowrav Shekar authored and Gowrav Shekar committed Oct 2, 2015
1 parent 2f74ae8 commit 31b3f2f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,33 @@ Example:

### extract-text-webpack-plugin

Configure post style loaders in `bootstrap.config.js`.
Configure style loader in `bootstrap.config.js`.

Example:

``` javascript
module.exports = {
postStyleLoaders: [
require.resolve('extract-text-webpack-plugin/loader.js') + '?{"omit":1,"extract":true,"remove":true}'
],
styleLoader: require('extract-text-webpack-plugin').extract('style-loader', 'css-loader!less-loader'),
scripts: {
...
},
styles: {
...
}
};
```

Install `extract-text-webpack-plugin` before using this configuration.

### extract-text-webpack-plugin and postcss-loader

Configure style loader in `bootstrap.config.js`.

Example:

``` javascript
module.exports = {
styleLoader: require('extract-text-webpack-plugin').extract('style-loader', 'css-loader!postcss-loader!less-loader'),
scripts: {
...
},
Expand Down
4 changes: 4 additions & 0 deletions bootstrap.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {

// Default for the style loading
styleLoader: 'style-loader!css-loader!less-loader',

scripts: {
'transition': true,
'alert': true,
Expand Down
35 changes: 25 additions & 10 deletions index.loader.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
module.exports = function () {};
module.exports = function() {
};

module.exports.pitch = function (remainingRequest) {

// Webpack 1.7.3 uses this.resourcePath. Leaving in remaining request for possibly older versions
// of Webpack
var configFilePath = this.resourcePath || remainingRequest;
this.cacheable(true);
var config = require(this.resourcePath);
var postStyleLoaders = '';
if((typeof config.postStyleLoaders !== 'undefined') && (config.postStyleLoaders.length > 0)){
postStyleLoaders = config.postStyleLoaders.join('!') + '!';

if (!configFilePath || configFilePath.trim() === '') {
var msg = 'You specified the bootstrap-webpack with no configuration file. Please specify' +
' the configuration file, like: \'bootstrap-webpack!./bootstrap.config.js\' or use' +
' require(\'bootstrap-webpack\').';
console.error('ERROR: ' + msg);
throw new Error(msg);
}
return [
'require(' + JSON.stringify("-!" + postStyleLoaders + require.resolve("style-loader") + '!' + require.resolve("css-loader") +
'!' + require.resolve("less-loader") + '!' + require.resolve("./bootstrap-styles.loader.js") + '!' + remainingRequest) + ');',
'require(' + JSON.stringify("-!" + require.resolve("./bootstrap-scripts.loader.js") + "!" + remainingRequest) + ');'
].join("\n");

var config = require(configFilePath);
var styleLoader = config.styleLoader || 'style-loader!css-loader!less-loader';

var styleLoaderCommand = 'require(' + JSON.stringify('-!' + styleLoader + '!' +
require.resolve('./bootstrap-styles.loader.js') + '!' + configFilePath) + ');';
var jsLoaderCommand = 'require(' + JSON.stringify('-!' +
require.resolve('./bootstrap-scripts.loader.js') + '!' + configFilePath) + ');';
var result = [styleLoaderCommand, jsLoaderCommand].join('\n');
return result;

};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bootstrap-webpack",
"description": "bootstrap3 package for webpack",
"main": "index.js",
"version": "0.0.4",
"version": "0.0.5",
"loader": "index.loader.js",
"keywords": [
"bootstrap",
Expand Down

0 comments on commit 31b3f2f

Please sign in to comment.