Skip to content

Commit 1c74da5

Browse files
committed
Add SASS support
1 parent e4b1f94 commit 1c74da5

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ module.exports = {
188188
// "style" loader turns CSS into JS modules that inject <style> tags.
189189
// In production, we use a plugin to extract that CSS to a file, but
190190
// in development "style" loader enables hot editing of CSS.
191+
// SASS/SCSS supported.
191192
{
192193
test: /\.css$/,
193194
use: [
@@ -220,6 +221,44 @@ module.exports = {
220221
},
221222
],
222223
},
224+
{
225+
test: /\.scss$/,
226+
use: [
227+
require.resolve('style-loader'),
228+
{
229+
loader: require.resolve('css-loader'),
230+
options: {
231+
importLoaders: 1,
232+
},
233+
},
234+
{
235+
loader: require.resolve('postcss-loader'),
236+
options: {
237+
// Necessary for external CSS imports to work
238+
// https://github.com/facebookincubator/create-react-app/issues/2677
239+
ident: 'postcss',
240+
plugins: () => [
241+
require('postcss-flexbugs-fixes'),
242+
autoprefixer({
243+
browsers: [
244+
'>1%',
245+
'last 4 versions',
246+
'Firefox ESR',
247+
'not ie < 9', // React doesn't support IE8 anyway
248+
],
249+
flexbox: 'no-2009',
250+
}),
251+
],
252+
},
253+
},
254+
{
255+
loader: require.resolve('sass-loader'),
256+
options: {
257+
importLoaders: 1,
258+
},
259+
},
260+
],
261+
},
223262
// "file" loader makes sure those assets get served by WebpackDevServer.
224263
// When you `import` an asset, you get its (virtual) filename.
225264
// In production, they would get copied to the `build` folder.

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ module.exports = {
200200
// tags. If you use code splitting, however, any async bundles will still
201201
// use the "style" loader inside the async code so CSS from them won't be
202202
// in the main CSS file.
203+
// SASS/SCSS supported.
203204
{
204205
test: /\.css$/,
205206
loader: ExtractTextPlugin.extract(
@@ -247,6 +248,59 @@ module.exports = {
247248
),
248249
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
249250
},
251+
{
252+
test: /\.scss$/,
253+
loader: ExtractTextPlugin.extract(
254+
Object.assign(
255+
{
256+
fallback: {
257+
loader: require.resolve('style-loader'),
258+
options: {
259+
hmr: false,
260+
},
261+
},
262+
use: [
263+
{
264+
loader: require.resolve('css-loader'),
265+
options: {
266+
importLoaders: 1,
267+
minimize: true,
268+
sourceMap: shouldUseSourceMap,
269+
},
270+
},
271+
{
272+
loader: require.resolve('postcss-loader'),
273+
options: {
274+
// Necessary for external CSS imports to work
275+
// https://github.com/facebookincubator/create-react-app/issues/2677
276+
ident: 'postcss',
277+
plugins: () => [
278+
require('postcss-flexbugs-fixes'),
279+
autoprefixer({
280+
browsers: [
281+
'>1%',
282+
'last 4 versions',
283+
'Firefox ESR',
284+
'not ie < 9', // React doesn't support IE8 anyway
285+
],
286+
flexbox: 'no-2009',
287+
}),
288+
],
289+
},
290+
},
291+
{
292+
loader: require.resolve('sass-loader'),
293+
options: {
294+
importLoaders: 1,
295+
},
296+
},
297+
],
298+
},
299+
extractTextPluginOptions
300+
)
301+
),
302+
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
303+
},
250304
// "file" loader makes sure assets end up in the `build` folder.
251305
// When you `import` an asset, you get its filename.
252306
// This loader doesn't use a "test" so it will catch all modules

packages/react-scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
"postcss-loader": "2.0.8",
4242
"promise": "8.0.1",
4343
"raf": "3.4.0",
44-
"source-map-loader": "^0.2.1",
4544
"react-dev-utils": "^5.0.1",
4645
"resolve": "1.6.0",
46+
"sass-loader": "^7.0.3",
47+
"source-map-loader": "^0.2.1",
4748
"style-loader": "0.19.0",
4849
"sw-precache-webpack-plugin": "0.11.4",
4950
"ts-jest": "22.0.1",

0 commit comments

Comments
 (0)