Skip to content

Commit 6eb0622

Browse files
committed
feature: added css/sass modules into react-scripts
1 parent 28aefe0 commit 6eb0622

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,95 @@ module.exports = {
387387
),
388388
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
389389
},
390+
{
391+
test: /\.module\.css$/,
392+
loader: ExtractTextPlugin.extract(
393+
Object.assign(
394+
{
395+
fallback: require.resolve('style-loader'),
396+
use: [
397+
{
398+
loader: require.resolve('css-loader'),
399+
options: {
400+
modules: true,
401+
importLoaders: 1,
402+
minimize: true,
403+
sourceMap: shouldUseSourceMap,
404+
localIdentName: '[name]__[local]__[hash:base64:5]'
405+
},
406+
},
407+
{
408+
loader: require.resolve('postcss-loader'),
409+
options: {
410+
// Necessary for external CSS imports to work
411+
// https://github.com/facebookincubator/create-react-app/issues/2677
412+
ident: 'postcss',
413+
plugins: () => [
414+
require('postcss-flexbugs-fixes'),
415+
autoprefixer({
416+
browsers: [
417+
'>1%',
418+
'last 4 versions',
419+
'Firefox ESR',
420+
'not ie < 9', // React doesn't support IE8 anyway
421+
],
422+
flexbox: 'no-2009',
423+
}),
424+
],
425+
},
426+
},
427+
],
428+
},
429+
extractTextPluginOptions
430+
)
431+
),
432+
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
433+
},
434+
{
435+
test: /\.module\.s[ca]ss$/,
436+
loader: ExtractTextPlugin.extract(
437+
Object.assign(
438+
{
439+
fallback: require.resolve('style-loader'),
440+
use: [
441+
{
442+
loader: require.resolve('css-loader'),
443+
options: {
444+
modules: true,
445+
importLoaders: 1,
446+
minimize: true,
447+
sourceMap: shouldUseSourceMap,
448+
localIdentName: '[name]__[local]__[hash:base64:5]'
449+
},
450+
},
451+
{
452+
loader: require.resolve('postcss-loader'),
453+
options: {
454+
// Necessary for external CSS imports to work
455+
// https://github.com/facebookincubator/create-react-app/issues/2677
456+
ident: 'postcss',
457+
plugins: () => [
458+
require('postcss-flexbugs-fixes'),
459+
autoprefixer({
460+
browsers: [
461+
'>1%',
462+
'last 4 versions',
463+
'Firefox ESR',
464+
'not ie < 9', // React doesn't support IE8 anyway
465+
],
466+
flexbox: 'no-2009',
467+
}),
468+
],
469+
},
470+
},
471+
{ loader: 'sass-loader', options: { sourceMap: shouldUseSourceMap } }
472+
],
473+
},
474+
extractTextPluginOptions
475+
)
476+
),
477+
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
478+
},
390479
// "file" loader makes sure assets end up in the `build` folder.
391480
// When you `import` an asset, you get its filename.
392481
// This loader doesn't use a "test" so it will catch all modules

packages/react-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"babel-jest": "20.0.3",
2828
"babel-loader": "7.1.2",
2929
"babel-preset-react-app": "^3.1.0",
30+
"babel-preset-stage-0": "^6.24.1",
3031
"babel-runtime": "6.26.0",
3132
"case-sensitive-paths-webpack-plugin": "2.1.1",
3233
"chalk": "1.1.3",

0 commit comments

Comments
 (0)