Skip to content

Commit 233fd47

Browse files
author
Neal Granger
committed
Initial commit.
0 parents  commit 233fd47

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

.editorconfig

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# EditorConfig: http://EditorConfig.org
3+
#
4+
# This files specifies some basic editor conventions for the files in this
5+
# project. Many editors support this standard, you simply need to find a plugin
6+
# for your favorite!
7+
#
8+
# For a full list of possible values consult the reference.
9+
# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties
10+
#
11+
12+
# Stop searching for other .editorconfig files above this folder.
13+
root = true
14+
15+
# Pick some sane defaults for all files.
16+
[*]
17+
18+
# UNIX line-endings are preferred.
19+
# http://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line/
20+
end_of_line = lf
21+
22+
# No reason in these modern times to use anything other than UTF-8.
23+
charset = utf-8
24+
25+
# Ensure that there's no bogus whitespace in the file.
26+
trim_trailing_whitespace = true
27+
28+
# A little esoteric, but it's kind of a standard now.
29+
# http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline
30+
insert_final_newline = true
31+
32+
# Pragmatism today.
33+
# http://programmers.stackexchange.com/questions/57
34+
indent_style = 2
35+
36+
# Personal preference here. Smaller indent size means you can fit more on a line
37+
# which can be nice when there are lines with several indentations.
38+
indent_size = 2
39+
40+
# Prefer a more conservative default line length – this allows editors with
41+
# sidebars, minimaps, etc. to show at least two documents side-by-side.
42+
# Hard wrapping by default for code is useful since many editors don't support
43+
# an elegant soft wrap; however, soft wrap is fine for things where text just
44+
# flows normally, like Markdown documents or git commit messages. Hard wrap
45+
# is also easier for line-based diffing tools to consume.
46+
# See: http://tex.stackexchange.com/questions/54140
47+
max_line_length = 80
48+
49+
# Markdown uses trailing spaces to create line breaks.
50+
[*.md]
51+
trim_trailing_whitespace = false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
*.log

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# css-js-loader

index.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var defaults = require('lodash/defaults');
2+
var loaderUtils = require('loader-utils');
3+
var dangerousStyleValue = require('react/lib/dangerousStyleValue');
4+
var hyphenateStyleName = require('fbjs/lib/hyphenateStyleName');
5+
6+
function indent(pretty, depth) {
7+
return pretty ? Array(depth).join(' ') : '';
8+
};
9+
10+
function space(pretty) {
11+
return pretty ? ' ' : '';
12+
};
13+
14+
function line(pretty) {
15+
return pretty ? '\n' : '';
16+
}
17+
18+
function parse(config, styles, level) {
19+
level = level === undefined ? 0 : level;
20+
21+
var pretty = config.pretty;
22+
var css = '';
23+
24+
for (var styleName in styles) {
25+
if (!styles.hasOwnProperty(styleName)) {
26+
continue;
27+
}
28+
29+
// Extract the style definition or nested block.
30+
var styleValue = styles[styleName];
31+
32+
if (styleValue === null) {
33+
continue;
34+
}
35+
36+
// Remove whitespace from selector/block.
37+
styleName = styleName.trim();
38+
39+
var block = Object.prototype.toString.call(styleValue) === '[object Object]';
40+
41+
if (block) {
42+
css += indent(pretty, level) + styleName + space(pretty) + '{' + line(pretty);
43+
css += parse(config, styleValue, level + 1);
44+
css += indent(pretty, level) + '}' + line(pretty) + line(pretty);
45+
continue;
46+
}
47+
48+
css += indent(pretty, level + 1) + hyphenateStyleName(styleName) + ':' + space(pretty);
49+
css += dangerousStyleValue(styleName, styleValue) + ';' + line(pretty);
50+
}
51+
52+
return css;
53+
}
54+
55+
module.exports = function(content) {
56+
this.cacheable();
57+
58+
config = defaults(loaderUtils.getLoaderConfig(this, 'jsCssLoader'), {pretty: process.env.NODE_ENV !== 'production'});
59+
60+
var styles = this.exec(content, this.resourcePath);
61+
62+
return parse(config, styles.__esModule ? styles.default : styles);
63+
};

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "css-js-loader",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Neal Granger <neal@metalab.co>",
10+
"license": "CC0-1.0",
11+
"dependencies": {
12+
"fbjs": "^0.8.4",
13+
"loader-utils": "^0.2.15",
14+
"lodash": "^4.15.0",
15+
"react": "^15.3.1"
16+
}
17+
}

0 commit comments

Comments
 (0)