Skip to content

Commit 528bfc0

Browse files
committed
Using sass with node.
1 parent d3f67ad commit 528bfc0

File tree

9 files changed

+74
-26
lines changed

9 files changed

+74
-26
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Learning Fullstack JavaScript Development: MongoDB, Node.js, React.js",
55
"main": "index.js",
66
"scripts": {
7+
"build:dev": "webpack",
78
"start": "nodemon --exec babel-node server.js --ignore public/",
89
"dev": "webpack -wd"
910
},
@@ -25,13 +26,15 @@
2526
"express": "^4.15.3",
2627
"json-loader": "^0.5.4",
2728
"mongodb": "^2.2.28",
29+
"node-sass-middleware": "0.9.8",
2830
"react": "^15.6.0",
2931
"react-dom": "^15.6.0"
3032
},
3133
"devDependencies": {
3234
"babel-cli": "^6.24.1",
3335
"babel-eslint": "^7.2.3",
34-
"babel-loader": "^7.0.0",
36+
"babel-loader": "^6.2.5",
37+
"babel-preset-env": "^1.5.2",
3538
"babel-preset-es2015": "^6.24.1",
3639
"babel-preset-react": "^6.24.1",
3740
"babel-preset-stage-2": "^6.24.1",

public/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.ContestPreview{margin:1em;border:1px solid green}.ContestPreview .category-name{border-bottom:1px solid #ccc;padding:0.25em 0.5em;font-weight:bold;background-color:#eee}.ContestPreview .contest-name{padding:0.5em}

sass/style.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.ContestPreview {
2+
margin: 1em;
3+
border: 1px solid green;
4+
5+
.category-name {
6+
border-bottom: 1px solid #ccc;
7+
padding: 0.25em 0.5em;
8+
font-weight: bold;
9+
background-color: #eee;
10+
}
11+
12+
.contest-name {
13+
padding: 0.5em;
14+
}
15+
}

server.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import config from './config';
2-
import express from 'express';
32
import apiRouter from './api';
3+
import express from 'express';
4+
import sassMiddleware from 'node-sass-middleware';
5+
import path from 'path';
46

57
const server = express();
68

9+
server.use(sassMiddleware({
10+
/* Options */
11+
src: path.join(__dirname, 'sass'),
12+
dest: path.join(__dirname, 'public'),
13+
debug: 'true',
14+
outputStyle: 'compressed',
15+
prefix: '/static/'
16+
}));
17+
718
server.set('view engine', 'ejs');
819

920
server.get('/', (req, res) => {
@@ -16,5 +27,5 @@ server.use('/api', apiRouter);
1627
server.use(express.static('public'));
1728

1829
server.listen(config.port, () => {
19-
console.info('Express listening on port: ' + config.port)
20-
});
30+
console.info('Express listening on port', config.port);
31+
});

src/components/ContestPreview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import React from 'react';
33
const ContestPreview = (contest) => {
44
return (
55
<div className="ContestPreview">
6-
<div>
6+
<div className="category-name">
77
{contest.categoryName}
88
</div>
9-
<div>
9+
<div className="contest-name">
1010
{contest.contestName}
1111
</div>
1212
</div>

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33

4-
import App from './components/App';
54
import data from './testData';
5+
import App from './components/App';
66

77
ReactDOM.render(
88
<App contests={data.contests} />,

views/header.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<title>Naming Contests</title>
88
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
9+
<link rel="stylesheet" href="/style.css" media="screen">
910
</head>
1011
<body class="container">

webpack.config.babel.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const {resolve} = require('path');
2+
3+
module.exports = () => {
4+
return {
5+
context: resolve('src'),
6+
entry: './index.js',
7+
output: {
8+
path: resolve('public'),
9+
filename: 'bundle.js'
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.js$/,
15+
exclude: /(node_modules|bower_components)/,
16+
use: {
17+
loader: 'babel-loader',
18+
options: {
19+
presets: ['es2015', 'react', 'stage-2']
20+
}
21+
}
22+
},
23+
{
24+
test: /\.json$/,
25+
exclude: /(node_modules|bower_components)/,
26+
use: {
27+
loader: 'json-loader',
28+
options: {
29+
presets: ['env']
30+
}
31+
}
32+
}
33+
]
34+
}
35+
};
36+
};

webpack.config.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)