diff --git a/README.md b/README.md index 952012f78ad..0fa595c433f 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,12 @@ If something doesn’t work, please [file an issue](https://github.com/ctco-dev/ * [TSLint Config Airbnb](https://github.com/progre/tslint-config-airbnb) - a tslint config for [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) * [12 Factor Application Configuration](https://12factor.net/config) approach to profile application in runtime. [Details](https://github.com/ctco-dev/create-react-app/blob/master/packages/react-scripts/template/README.md#12-factor-app-config) * :whale: [Docker](https://www.docker.com/) support (plus 12 Factor configuration in runtime, see above) +* [CSS Modules](https://github.com/css-modules/css-modules) - optional +* [typings-for-css-modules-loader](https://github.com/Jimdo/typings-for-css-modules-loader) - lightweight `css-loader` replacement to enable type generation for css module files +* [Browserslist](https://github.com/browserslist/browserslist) +* [SASS/SCSS](https://sass-lang.com/) - optional +* Source maps for CSS enabled in dev mode +* [Classnames](https://github.com/JedWatson/classnames) - for conditionally joining classNames together ## Quick Overview diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 53369e98388..2187753b5a2 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -33,6 +33,60 @@ const publicUrl = ''; // Get environment variables to inject into our app. const env = getClientEnvironment(publicUrl); +// style files regexes +const cssRegex = /\.css$/; +const cssModuleRegex = /\.module\.css$/; +const sassRegex = /\.(scss|sass)$/; +const sassModuleRegex = /\.module\.(scss|sass)$/; +const localIdentName = '[name]__[local]___[hash:base64:8]'; + +// common function to get style loaders +const getStyleLoaders = (cssOptions, preProcessor, preProcessorOptions) => { + const loaders = [ + { + loader: require.resolve('style-loader'), + options: { sourceMap: true }, + }, + // this one is used instead of css-loader to allow css modules inside typescript + { + loader: require.resolve('typings-for-css-modules-loader'), + options: Object.assign({}, + { + sourceMap: true, + silent: true, // typings-for-css-modules-loader option + namedExport: true, // typings-for-css-modules-loader option + camelCase: true, // typings-for-css-modules-loader option + }, + cssOptions) + }, + { + // Options for PostCSS as we reference these options twice + // Adds vendor prefixing based on your specified browser support in + // package.json + loader: require.resolve('postcss-loader'), + options: { + // Necessary for external CSS imports to work + // https://github.com/facebook/create-react-app/issues/2677 + ident: 'postcss', + plugins: () => [ + require('postcss-flexbugs-fixes'), + autoprefixer({ + flexbox: 'no-2009', + }), + ], + sourceMap: true, + }, + }, + ]; + if (preProcessor) { + loaders.push({ + loader: require.resolve(preProcessor), + options: Object.assign({}, { sourceMap: true }, preProcessorOptions), + }); + } + return loaders; +}; + // This is the development configuration. // It is focused on developer experience and fast rebuilds. // The production configuration is different and lives in a separate file. @@ -210,37 +264,33 @@ module.exports = { // "style" loader turns CSS into JS modules that inject