Skip to content

Commit c3fa6ff

Browse files
committed
Use the postcss-webpack-loader
Use postcss-webpack-loader instead of webpack-cli to process the scss. Doing so mostly means that we avoid the problem that webpack-dev-server fails to start if we haven't already built the CSS. (It also simplifies package.json somewhat, which is no bad thing)
1 parent c5032ba commit c3fa6ff

4 files changed

Lines changed: 40 additions & 28 deletions

File tree

‎package.json‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,19 @@
2929
"reskindex": "reskindex -h src/header",
3030
"build:res": "node scripts/copy-res.js",
3131
"build:modernizr": "modernizr -c .modernizr.json -d src/vector/modernizr.js",
32-
"build:css": "mkdirp build && postcss -c postcss.config.json",
3332
"build:compile": "babel --source-maps -d lib src",
3433
"build:bundle": "NODE_ENV=production webpack -p --progress",
3534
"build:bundle:dev": "webpack --optimize-occurence-order --progress",
3635
"build:electron": "npm run clean && npm run build && build -wml --ia32 --x64",
37-
"build": "node scripts/babelcheck.js && npm run build:res && npm run build:css && npm run build:bundle",
38-
"build:dev": "node scripts/babelcheck.js && npm run build:res && npm run build:css && npm run build:bundle:dev",
36+
"build": "node scripts/babelcheck.js && npm run build:res && npm run build:bundle",
37+
"build:dev": "node scripts/babelcheck.js && npm run build:res && npm run build:bundle:dev",
3938
"dist": "scripts/package.sh",
4039
"start:res": "node scripts/copy-res.js -w",
4140
"start:js": "webpack-dev-server -w --progress",
4241
"start:js:prod": "NODE_ENV=production webpack-dev-server -w --progress",
43-
"start:css": "mkdirp build && postcss -c postcss.config.json -w",
44-
"start": "node scripts/babelcheck.js && parallelshell \"npm run start:res\" \"npm run start:js\" \"npm run start:css\"",
45-
"start:prod": "parallelshell \"npm run start:res\" \"npm run start:js:prod\" \"npm run start:css\"",
46-
"clean": "rimraf build lib webapp electron/dist",
42+
"start": "node scripts/babelcheck.js && parallelshell \"npm run start:res\" \"npm run start:js\"",
43+
"start:prod": "parallelshell \"npm run start:res\" \"npm run start:js:prod\"",
44+
"clean": "rimraf lib webapp electron/dist",
4745
"prepublish": "npm run build:compile",
4846
"test": "karma start --single-run=true --autoWatch=false --browsers PhantomJS --colors=false",
4947
"test:multi": "karma start"
@@ -114,9 +112,9 @@
114112
"mocha": "^2.4.5",
115113
"parallelshell": "^1.2.0",
116114
"phantomjs-prebuilt": "^2.1.7",
117-
"postcss-cli": "^2.6.0",
118115
"postcss-extend": "^1.0.5",
119116
"postcss-import": "^9.0.0",
117+
"postcss-loader": "^1.2.2",
120118
"postcss-mixins": "^5.4.1",
121119
"postcss-nested": "^1.0.0",
122120
"postcss-scss": "^0.4.0",

‎postcss.config.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
plugins: [
3+
require("postcss-import")(),
4+
require("autoprefixer")(),
5+
require("postcss-simple-vars")(),
6+
require("postcss-extend")(),
7+
require("postcss-nested")(),
8+
require("postcss-mixins")(),
9+
require("postcss-strip-inline-comments")(),
10+
],
11+
"parser": "postcss-scss",
12+
"local-plugins": true,
13+
};

‎postcss.config.json‎

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

‎webpack.config.js‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ module.exports = {
1717
"olm": "./src/vector/olm-loader.js",
1818

1919
// CSS themes
20-
"theme-light": "./build/light.scss",
21-
"theme-dark": "./build/dark.scss",
20+
"theme-light": "./src/skins/vector/css/themes/light.scss",
21+
"theme-dark": "./src/skins/vector/css/themes/dark.scss"
2222
},
2323
module: {
2424
preLoaders: [
@@ -27,9 +27,25 @@ module.exports = {
2727
loaders: [
2828
{ test: /\.json$/, loader: "json" },
2929
{ test: /\.js$/, loader: "babel", include: path.resolve('./src') },
30-
// css-raw-loader loads CSS but doesn't try to treat url()s as require()s
31-
// we're assuming that postcss has already preprocessed SCSS by this point
32-
{ test: /\.s?css$/, loader: ExtractTextPlugin.extract("css-raw-loader") },
30+
{
31+
test: /\.scss$/,
32+
33+
// 1. postcss-loader turns the SCSS into normal CSS.
34+
// 2. css-raw-loader turns the CSS into a javascript module
35+
// whose default export is a string containing the CSS.
36+
// (css-raw-loader is similar to css-loader, but the latter
37+
// would also drag in the imgs and fonts that our CSS refers to
38+
// as webpack inputs.)
39+
// 3. ExtractTextPlugin turns that string into a separate asset.
40+
loader: ExtractTextPlugin.extract(
41+
"css-raw-loader!postcss-loader?config=postcss.config.js"
42+
),
43+
},
44+
{
45+
// this works similarly to the scss case, without postcss.
46+
test: /\.css$/,
47+
loader: ExtractTextPlugin.extract("css-raw-loader"),
48+
},
3349
],
3450
noParse: [
3551
// don't parse the languages within highlight.js. They cause stack

0 commit comments

Comments
 (0)