Created
December 24, 2015 16:21
-
-
Save aj0strow/78b1ef1e861384d89dab to your computer and use it in GitHub Desktop.
Webpack local styles example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:local(.green) { | |
height: 20px; | |
background: green; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const React = require("react") | |
const css = require("./component.scss") | |
const Component = React.createClass({ | |
render () { | |
return <div className={css.green}></div> | |
} | |
}) | |
module.exports = Component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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