Skip to content

Instantly share code, notes, and snippets.

@aj0strow
Created December 24, 2015 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aj0strow/78b1ef1e861384d89dab to your computer and use it in GitHub Desktop.
Save aj0strow/78b1ef1e861384d89dab to your computer and use it in GitHub Desktop.
Webpack local styles example
:local(.green) {
height: 20px;
background: green;
}
const React = require("react")
const css = require("./component.scss")
const Component = React.createClass({
render () {
return <div className={css.green}></div>
}
})
module.exports = Component
// npm install --save-dev sass-loader css-loader style-loader null-loader
module.exports = function (options) {
var config = {}
var loaders = []
if (options.includeCss) {
var includePaths = [
root('src/mixins')
]
var includeParams = includePaths.map(function (path) {
return 'includePaths[]=' + encodeURIComponent(path)
}).join('&')
loaders.push({
test: /\.scss$/,
loader: 'style!css!sass?' + includeParams,
})
loaders.push({
test: /\.css$/,
loader: 'style!css',
})
} else {
loaders.push({
test: /\.s?css$/,
loader: 'null',
})
}
config.module = { loaders: loaders }
return config
}
// For develoment, for test pass false to null-loader it.
module.exports = require("./create-webpack-config")({
includeCss: true,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment