Skip to content

SASS compatibility implemented in react-scripts #1509

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ module.exports = {
/\.(js|jsx)$/,
/\.css$/,
/\.json$/,
/\.svg$/
/\.svg$/,
/(\.scss|\.sass)$/
],
loader: 'url',
query: {
Expand Down Expand Up @@ -159,6 +160,17 @@ module.exports = {
test: /\.css$/,
loader: 'style!css?importLoaders=1!postcss'
},
// "sass" loader transpiling SASS to CSS.
// "postcss" loader applies autoprefixer to our CSS.
// "css" loader resolves paths in CSS and adds assets as dependencies.
// "style" loader turns CSS into JS modules that inject <style> tags.
// In production, we use a plugin to extract that CSS to a file, but
// in development "style" loader enables hot editing of CSS.
{
test: /(\.scss|\.sass)$/,
include: paths.appSrc,
loader: "style!css!postcss!sass?sourceMap"
}
// JSON is not enabled by default in Webpack but both Node and Browserify
// allow it implicitly so we also enable it.
{
Expand Down
19 changes: 19 additions & 0 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ module.exports = {
loader: ExtractTextPlugin.extract('style', 'css?importLoaders=1!postcss')
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
},
// The notation here is somewhat confusing.
// "sass" loader transpiling SASS to CSS.
// "postcss" loader applies autoprefixer to our CSS.
// "css" loader resolves paths in CSS and adds assets as dependencies.
// "style" loader normally turns CSS into JS modules injecting <style>,
// but unlike in development configuration, we do something different.
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
// (second argument), then grabs the result CSS and puts it into a
// separate file in our build process. This way we actually ship
// a single CSS file in production instead of JS code injecting <style>
// tags. If you use code splitting, however, any async bundles will still
// use the "style" loader inside the async code so CSS from them won't be
// in the main CSS file.
{
test: /(\.scss|\.sass)$/,
include: paths.appSrc,
loader: ExtractTextPlugin.extract('style', 'css!postcss!sass?sourceMap')
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
},
// JSON is not enabled by default in Webpack but both Node and Browserify
// allow it implicitly so we also enable it.
{
Expand Down
24 changes: 0 additions & 24 deletions packages/react-scripts/template/src/App.css

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react-scripts/template/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import './App.scss';

class App extends Component {
render() {
Expand Down
24 changes: 24 additions & 0 deletions packages/react-scripts/template/src/App.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.App {
text-align: center;

&-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

&-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}

&-intro {
font-size: large;
}
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
2 changes: 1 addition & 1 deletion packages/react-scripts/template/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import './index.scss';

ReactDOM.render(
<App />,
Expand Down