Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sass loader #4195

Merged
merged 28 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4b40a7d
Installs and adds sass loader task in webpack for dev environment.
Fabianopb Mar 20, 2018
0670888
Uses Timer's branch of sass-loader without node-sass dependency.
Fabianopb Mar 20, 2018
fc1b9d4
Adds method for handling SASS modules.
Fabianopb Mar 21, 2018
ac4cf34
Fixes extension of excluded files when looking for scss modules.
Fabianopb Mar 21, 2018
61bd312
Adds support for both .scss and .sass extensions.
Fabianopb Mar 21, 2018
69ce2e6
Uses ExtractTextPlugin with sass-loader to bundle styles for the prod…
Fabianopb Mar 21, 2018
0a81f2a
Bundles SASS modules for the production build.
Fabianopb Mar 21, 2018
5a7f534
Uses the latest version of sass-loader.
Fabianopb Mar 21, 2018
b2573f5
Adds function to create different rules for style loaders in dev envi…
Fabianopb Mar 24, 2018
6e60b6e
Abstracts style loaders to a common function to avoid repetition.
Fabianopb Mar 24, 2018
c8052c5
Simplifies the common function that creates style loaders.
Fabianopb Mar 24, 2018
876c9b3
Creates assets for testing SASS/SCSS support.
Fabianopb Mar 26, 2018
9865439
Creates mock components and unit tests for SASS and SCSS with and wit…
Fabianopb Mar 26, 2018
1629d78
Creates integration tests for SASS/SCSS support.
Fabianopb Mar 26, 2018
479423a
Adds node-sass as a template dependency so sass-loader can be tested.
Fabianopb Mar 26, 2018
dc640e4
Includes sass tests when test component is mounted.
Fabianopb Mar 27, 2018
f44250e
Fixes asserted module name for sass and scss modules tests.
Fabianopb Mar 27, 2018
0f36d90
Removes tests against css imports in SCSS and SASS files.
Fabianopb Mar 27, 2018
c68d168
Merge branch 'next' of https://github.com/facebook/create-react-app i…
Fabianopb Apr 6, 2018
7ba882e
Updates sass-loader to v7.
Fabianopb Apr 13, 2018
2311570
Merge branch 'next' of https://github.com/facebook/create-react-app i…
Fabianopb Apr 13, 2018
3657b78
Uses getCSSModuleLocalIdent from react-dev-utils.
Fabianopb Apr 14, 2018
5a49244
Fixes tests to match the use of getCSSModuleLocalIdent.
Fabianopb Apr 14, 2018
9e67bde
Improves readability of getStyleLoader function.
Fabianopb Apr 14, 2018
4c14a2f
Uses postcss after sass.
Fabianopb Apr 15, 2018
3b8bbb8
Refactors dev config to simplify common function for style loaders.
Fabianopb Apr 15, 2018
d9621fb
Refactors prod config to simplify common function for style loaders.
Fabianopb Apr 15, 2018
22475dc
Use importLoaders config according to css-loader docs.
Fabianopb Apr 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,36 @@ module.exports = {
},
],
},
// Opt-in support for SASS (using .scss or .sass extensions).
// Chains the sass-loader with the css-loader and the style-loader
// to immediately apply all styles to the DOM.
// By default we support SASS Modules with the
// extensions .module.scss or .module.sass
{
test: /\.(scss|sass)$/,
exclude: /\.module\.(scss|sass)$/,
use: [
require.resolve('style-loader'),
require.resolve('css-loader'),
require.resolve('sass-loader'),
],
},
// Adds support for CSS Modules, but using SASS
// using the extension .module.scss or .module.sass
{
test: /\.module\.(scss|sass)$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
modules: true,
localIdentName: '[path]__[name]___[local]',
},
},
require.resolve('sass-loader'),
],
},
// The GraphQL loader preprocesses GraphQL queries in .graphql files.
{
test: /\.(graphql)$/,
Expand Down
76 changes: 75 additions & 1 deletion packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,80 @@ module.exports = {
),
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
},
// Opt-in support for SASS. The logic here is somewhat similar
// as in the CSS routine, except that "sass-loader" runs first
// to compile SASS files into CSS.
// By default we support SASS Modules with the
// extensions .module.scss or .module.sass
{
test: /\.(scss|sass)$/,
exclude: /\.module\.(scss|sass)$/,
loader: ExtractTextPlugin.extract(
Object.assign(
{
fallback: {
loader: require.resolve('style-loader'),
options: {
hmr: false,
},
},
use: [
{
loader: require.resolve('css-loader'),
options: {
minimize: true,
sourceMap: shouldUseSourceMap,
},
},
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: shouldUseSourceMap,
},
},
],
},
extractTextPluginOptions
)
),
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
},
// Adds support for CSS Modules, but using SASS
// using the extension .module.scss or .module.sass
{
test: /\.module\.(scss|sass)$/,
loader: ExtractTextPlugin.extract(
Object.assign(
{
fallback: {
loader: require.resolve('style-loader'),
options: {
hmr: false,
},
},
use: [
{
loader: require.resolve('css-loader'),
options: {
minimize: true,
sourceMap: shouldUseSourceMap,
modules: true,
localIdentName: '[path]__[name]___[local]',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use react-dev-utils/getCSSModuleLocalIdent when #4192 is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

},
},
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: shouldUseSourceMap,
},
},
],
},
extractTextPluginOptions
)
),
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
},
// The GraphQL loader preprocesses GraphQL queries in .graphql files.
{
test: /\.(graphql)$/,
Expand Down Expand Up @@ -413,7 +487,7 @@ module.exports = {
// having to parse `index.html`.
new ManifestPlugin({
fileName: 'asset-manifest.json',
publicPath: publicPath
publicPath: publicPath,
}),
// Generate a service worker script that will precache, and keep up to date,
// the HTML & assets that are part of the Webpack build.
Expand Down
1 change: 1 addition & 0 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"promise": "8.0.1",
"raf": "3.4.0",
"react-dev-utils": "^5.0.0",
"sass-loader": "^6.0.7",
"style-loader": "0.19.1",
"svgr": "1.8.1",
"sw-precache-webpack-plugin": "0.11.4",
Expand Down