Adding JS -> SCSS variables to webpack

This commit is contained in:
Adolfo Panizo 2018-03-05 09:45:42 +01:00
parent e8cd758ca9
commit 90b1c4fe04
4 changed files with 75 additions and 2 deletions

View File

@ -1,4 +1,5 @@
var autoprefixer = require('autoprefixer'); var autoprefixer = require('autoprefixer');
var cssvars = require('postcss-simple-vars');
var webpack = require('webpack'); var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin');
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
@ -19,6 +20,8 @@ var publicUrl = '';
// Get environment variables to inject into our app. // Get environment variables to inject into our app.
var env = getClientEnvironment(publicUrl); var env = getClientEnvironment(publicUrl);
var cssvariables = require(paths.appSrc + '/theme/variables');
// This is the development configuration. // This is the development configuration.
// It is focused on developer experience and fast rebuilds. // It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file. // The production configuration is different and lives in a separate file.
@ -136,7 +139,7 @@ module.exports = {
}, },
{ {
test: /\.css$/, test: /\.css$/,
loader: 'style!css?importLoaders=1&modules=true&localIdentName=[name]__[local]___[hash:base64:5]!postcss' loader: 'style!css?importLoaders=1&modules=true&minimize=true&localIdentName=[name]__[local]___[hash:base64:5]!postcss?sourceMap'
}, },
// "postcss" loader applies autoprefixer to our CSS. // "postcss" loader applies autoprefixer to our CSS.
// "css" loader resolves paths in CSS and adds assets as dependencies. // "css" loader resolves paths in CSS and adds assets as dependencies.
@ -207,6 +210,12 @@ module.exports = {
'not ie < 9', // React doesn't support IE8 anyway 'not ie < 9', // React doesn't support IE8 anyway
] ]
}), }),
cssvars({
variables: function () {
return Object.assign({}, cssvariables);
},
silent: false
}),
]; ];
}, },
plugins: [ plugins: [

63
package-lock.json generated
View File

@ -9453,6 +9453,69 @@
"uniq": "1.0.1" "uniq": "1.0.1"
} }
}, },
"postcss-simple-vars": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/postcss-simple-vars/-/postcss-simple-vars-4.1.0.tgz",
"integrity": "sha512-J/TRomA8EqXhS4VjQJsPCYTFIa9FYN/dkJK/8oZ0BYeVIPx91goqM8T+ljsP57+4bwSEywFOuB7EZ8n1gjjxZw==",
"dev": true,
"requires": {
"postcss": "6.0.19"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "1.9.1"
}
},
"chalk": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz",
"integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==",
"dev": true,
"requires": {
"ansi-styles": "3.2.1",
"escape-string-regexp": "1.0.5",
"supports-color": "5.3.0"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"postcss": {
"version": "6.0.19",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.19.tgz",
"integrity": "sha512-f13HRz0HtVwVaEuW6J6cOUCBLFtymhgyLPV7t4QEk2UD3twRI9IluDcQNdzQdBpiixkXj2OmzejhhTbSbDxNTg==",
"dev": true,
"requires": {
"chalk": "2.3.2",
"source-map": "0.6.1",
"supports-color": "5.3.0"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
},
"supports-color": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz",
"integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==",
"dev": true,
"requires": {
"has-flag": "3.0.0"
}
}
}
},
"postcss-svgo": { "postcss-svgo": {
"version": "2.1.6", "version": "2.1.6",
"resolved": "https://registry.npmjs.org/postcss-svgo/-/postcss-svgo-2.1.6.tgz", "resolved": "https://registry.npmjs.org/postcss-svgo/-/postcss-svgo-2.1.6.tgz",

View File

@ -35,6 +35,7 @@
"object-assign": "4.1.0", "object-assign": "4.1.0",
"path-exists": "2.1.0", "path-exists": "2.1.0",
"postcss-loader": "1.0.0", "postcss-loader": "1.0.0",
"postcss-simple-vars": "^4.0.0",
"promise": "7.1.1", "promise": "7.1.1",
"react-dev-utils": "^0.4.2", "react-dev-utils": "^0.4.2",
"recursive-readdir": "2.1.0", "recursive-readdir": "2.1.0",

View File

@ -1,6 +1,6 @@
body { body {
font-family: 'Montserrat', sans-serif; font-family: 'Montserrat', sans-serif;
color: #6b7c93; color: $(secondary);
background-color: #f0f1f3; background-color: #f0f1f3;
} }