Skip to content

Commit a4bbe9f

Browse files
committed
Initial commit
0 parents  commit a4bbe9f

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# React Toolbox Loader
2+
3+
A webpack loader to add custom theming variables to your React Toolbox Components build process. You can install it as an npm package:
4+
5+
```
6+
npm install --save-dev toolbox-loader
7+
```
8+
9+
## The configuration file
10+
11+
You just need to create a config file holding the variables you want to modify for your build and tell webpack to include it in the building process. For example you can create a little `theme.scss` file in your project context folder:
12+
13+
```scss
14+
$color-primary: $palette-indigo-500 !default;
15+
$color-primary-dark: $palette-indigo-700 !default;
16+
$color-accent: $palette-pink-a200 !default;
17+
$color-accent-dark: $palette-pink-700 !default;
18+
$color-primary-contrast: $color-dark-contrast !default;
19+
$color-accent-contrast: $color-dark-contrast !default;
20+
```
21+
22+
## Add the file to your css loader
23+
24+
In your webpack configuration you can add an option to webpack specifying the name of the configuration file. By default it's `theme.scss` so if you call it that way you just need to add the loader:
25+
26+
```javascript
27+
module: {
28+
loaders: [{
29+
test: /(\.scss|\.css)$/,
30+
loader: ExtractTextPlugin.extract('style', 'css!sass!toolbox')
31+
}]
32+
},
33+
toolboxTheme: 'theme.scss',
34+
....
35+
```
36+
37+
With this configuration your SASS files will be loaded with the context provided by your configuration file.

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var THEMED = '@import "~react-toolbox/_colors"; \n $theme-building: true;';
2+
var DEFAULT_NAME = 'theme.scss';
3+
var path = require('path');
4+
var fs = require('fs');
5+
6+
module.exports = function (source) {
7+
if (this.cacheable) this.cacheable();
8+
var callback = this.async();
9+
var themeName = this.options.toolboxTheme || DEFAULT_NAME;
10+
var themePath = path.resolve(themeName);
11+
12+
this.addDependency(themePath);
13+
14+
fs.readFile(themePath, "utf-8", function(err, theme) {
15+
if(err) return callback(err);
16+
callback(null, THEMED + '\n' + theme + '\n' + source);
17+
});
18+
};

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "toolbox-loader",
3+
"version": "0.0.1",
4+
"description": "A loader used to add SASS themes for React Toolbox",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Javi Velasco <javier.velasco86@gmail.com> (http://javivelasco.com/)",
10+
"license": "ISC"
11+
}

0 commit comments

Comments
 (0)