Skip to content

Commit c2313c9

Browse files
committed
Port css-modulesify example
1 parent 5062dc2 commit c2313c9

File tree

8 files changed

+86
-3
lines changed

8 files changed

+86
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
dist

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# CSS Modules Browserify Demo
22

3-
Coming soon.
3+
A working demo of **CSS Modules**, using [css-modulesify](https://github.com/css-modules/css-modulesify).
4+
5+
## Run the example
6+
7+
```bash
8+
$ npm install
9+
$ npm start & open http://localhost:8080
10+
```
411

512
## License
613

package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
"description": "A working demo of CSS Modules using browserify",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"clean": "rm -rf dist && mkdir dist",
9+
"browserify": "browserify -t css-modulesify -o dist/index.js src/index.js",
10+
"copy": "cp src/index.html dist/index.html",
11+
"build": "npm run clean && npm run copy && npm run browserify",
12+
"start": "npm run build && http-server dist",
13+
"publish": "npm run build && gh-pages -d dist -m \"Updates --skip-ci\""
814
},
915
"repository": {
1016
"type": "git",
@@ -15,5 +21,13 @@
1521
"bugs": {
1622
"url": "https://github.com/css-modules/browserify-demo/issues"
1723
},
18-
"homepage": "https://github.com/css-modules/browserify-demo"
24+
"homepage": "https://github.com/css-modules/browserify-demo",
25+
"devDependencies": {
26+
"browserify": "^10.2.3",
27+
"css-modulesify": "^0.1.2",
28+
"gh-pages": "^0.3.0",
29+
"http-server": "^0.8.0",
30+
"hyperscript": "^1.4.6",
31+
"insert-css": "^0.2.0"
32+
}
1933
}

src/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>CSS Modules Browserify Demo</title>
5+
</head>
6+
<body>
7+
<h1>CSS Modules Browserify Demo</h1>
8+
<p>This demo is powered by <a href="https://github.com/css-modules/css-modulesify">css-modulesify</a>.</p>
9+
<div id="content"></div>
10+
<script src="index.js"></script>
11+
</body>
12+
</html>

src/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var box1 = require('./style/box1.css');
2+
var box2 = require('./style/box2.css');
3+
4+
var h = require('hyperscript');
5+
6+
// dynamically add the css to the browser (this could be done at build-time instead)
7+
var insertCss = require('insert-css');
8+
insertCss(box1);
9+
insertCss(box2);
10+
11+
// create the markup and apply locally-scoped css classnames
12+
var content = h('div', [
13+
h('p', 'This is a demonstration of using generic classnames in css files like `.box` and `.text`, without any danger of name collisions between components'),
14+
15+
h('div', { className: box1.box }, [
16+
h('p', { className: box1.text }, 'Box 1')
17+
]),
18+
19+
h('div', { className: box2.box }, [
20+
h('p', { className: box2.text }, 'Box 2')
21+
])
22+
]);
23+
24+
document.getElementById('content').appendChild(content);

src/style/borders.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.dottyBorder {
2+
border: 1px dotted #000;
3+
}

src/style/box1.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.box {
2+
extends: dottyBorder from "./borders.css";
3+
padding: 10px;
4+
}
5+
6+
.text {
7+
font-style: italic;
8+
}

src/style/box2.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.box {
2+
padding: 10px;
3+
background: #555;
4+
transition: all 1s;
5+
}
6+
7+
.box:hover {
8+
background: #933;
9+
}
10+
11+
.text {
12+
color: #fff;
13+
font-weight: bold;
14+
}

0 commit comments

Comments
 (0)