Adding SCSS variables config to webpack prod config

This commit is contained in:
Adolfo Panizo 2018-03-05 11:02:45 +01:00
parent 90b1c4fe04
commit 7df9ec1bc8
12 changed files with 20 additions and 15 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
node_modules/ node_modules/
build/ build/
build_webpack/
build/contracts/ build/contracts/
truffle-config.js truffle-config.js

View File

@ -113,6 +113,7 @@ module.exports = {
/\.html$/, /\.html$/,
/\.(js|jsx)$/, /\.(js|jsx)$/,
/\.css$/, /\.css$/,
/\.scss$/,
/\.json$/, /\.json$/,
/\.woff$/, /\.woff$/,
/\.woff2$/, /\.woff2$/,
@ -138,8 +139,8 @@ module.exports = {
} }
}, },
{ {
test: /\.css$/, test: /\.(scss|css)$/,
loader: 'style!css?importLoaders=1&modules=true&minimize=true&localIdentName=[name]__[local]___[hash:base64:5]!postcss?sourceMap' loader: 'style!css?importLoaders=1&modules=true&minimize=false&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.

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 ExtractTextPlugin = require('extract-text-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin');
@ -8,7 +9,7 @@ var url = require('url');
var paths = require('./paths'); var paths = require('./paths');
var getClientEnvironment = require('./env'); var getClientEnvironment = require('./env');
var cssvariables = require(paths.appSrc + '/theme/variables');
function ensureSlash(path, needsSlash) { function ensureSlash(path, needsSlash) {
var hasSlash = path.endsWith('/'); var hasSlash = path.endsWith('/');
@ -116,6 +117,7 @@ module.exports = {
/\.html$/, /\.html$/,
/\.(js|jsx)$/, /\.(js|jsx)$/,
/\.css$/, /\.css$/,
/\.scss$/,
/\.json$/, /\.json$/,
/\.woff$/, /\.woff$/,
/\.woff2$/, /\.woff2$/,
@ -146,8 +148,8 @@ module.exports = {
// use the "style" loader inside the async code so CSS from them won't be // use the "style" loader inside the async code so CSS from them won't be
// in the main CSS file. // in the main CSS file.
{ {
test: /\.css$/, test: /\.(scss|css)$/,
loader: ExtractTextPlugin.extract('style', 'css?importLoaders=1!postcss') loader: ExtractTextPlugin.extract('style', 'css?importLoaders=1&modules=true&minimize=false!postcss?sourceMap')
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`. // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
}, },
// JSON is not enabled by default in Webpack but both Node and Browserify // JSON is not enabled by default in Webpack but both Node and Browserify
@ -200,6 +202,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: true
}),
]; ];
}, },
plugins: [ plugins: [

View File

@ -7,7 +7,7 @@ import contract from 'truffle-contract'
import TextField from './components/forms/TextField' import TextField from './components/forms/TextField'
import Page from './components/layout/Page' import Page from './components/layout/Page'
import PageFrame from './components/layout/PageFrame' import PageFrame from './components/layout/PageFrame'
import './App.css' import './App.scss'
class App extends Component { class App extends Component {
constructor(props) { constructor(props) {

View File

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

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import styles from './index.css'; import styles from './index.scss';
const Header = () => ( const Header = () => (
<header className={styles.header}> <header className={styles.header}>

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import Header from '../../Header' import Header from '../../Header'
import styles from './index.css'; import styles from './index.scss';
const Page = ({children}) => ( const Page = ({children}) => (
<div className={styles.page}> <div className={styles.page}>

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import styles from './index.css'; import styles from './index.scss';
const PageFrame = ({ children }) => ( const PageFrame = ({ children }) => (
<main className={styles.container}> <main className={styles.container}>

View File

@ -1,5 +0,0 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}