Skip to content

Commit

Permalink
feat(react): add support for css modules for SASS/SCSS files (nrwl#2719)
Browse files Browse the repository at this point in the history
Closes nrwl#2406
  • Loading branch information
jaysoo authored Mar 25, 2020
1 parent 975bd49 commit 7225d29
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
1 change: 0 additions & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ export function copyMissingPackages(): void {
'semver',

'css-loader',
'css-modules-typescript-loader',
'mime',
'less',
'send',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
"core-js": "^2.6.9",
"cosmiconfig": "^4.0.0",
"css-loader": "3.4.2",
"css-modules-typescript-loader": "4.0.0",
"cypress": "^4.1.0",
"cz-conventional-changelog": "^3.0.2",
"cz-customizable": "^6.2.0",
Expand Down
1 change: 0 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"copy-webpack-plugin": "5.1.1",
"core-js": "^3.2.1",
"css-loader": "3.4.2",
"css-modules-typescript-loader": "4.0.0",
"file-loader": "4.2.0",
"find-cache-dir": "3.0.0",
"fork-ts-checker-webpack-plugin": "^3.1.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/builders/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface WebBuildBuilderOptions extends BuildBuilderOptions {
baseHref: string;
deployUrl: string;

extractCss?: boolean;

polyfills?: string;
es2015Polyfills?: string;

Expand Down
33 changes: 29 additions & 4 deletions packages/web/src/utils/web.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { IndexHtmlWebpackPlugin } from './third-party/cli-files/plugins/index-ht
import { generateEntryPoints } from './third-party/cli-files/utilities/package-chunk-sort';
import { ScriptTarget } from 'typescript';

const MiniCssExtractPlugin = require('mini-css-extract-plugin');

export function getWebConfig(
root,
sourceRoot,
Expand Down Expand Up @@ -44,7 +46,7 @@ export function getWebConfig(
return mergeWebpack([
_getBaseWebpackPartial(options, esm, isScriptOptimizeOn),
getPolyfillsPartial(options, esm, isScriptOptimizeOn),
getStylesPartial(wco),
getStylesPartial(wco, options),
getCommonPartial(wco),
getBrowserPartial(wco, options, isScriptOptimizeOn)
]);
Expand Down Expand Up @@ -104,7 +106,10 @@ function getCommonPartial(wco: any): Configuration {
return commonConfig;
}

function getStylesPartial(wco: any): Configuration {
function getStylesPartial(
wco: any,
options: WebBuildBuilderOptions
): Configuration {
const partial = getStylesConfig(wco);
const rules = partial.module.rules.map(rule => {
if (!Array.isArray(rule.use)) {
Expand All @@ -130,8 +135,28 @@ function getStylesPartial(wco: any): Configuration {
{
test: /\.module\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-modules-typescript-loader' },
{
loader: options.extractCss
? MiniCssExtractPlugin.loader
: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1
}
}
]
},
{
test: /\.module\.(scss|sass)$/,
use: [
{
loader: options.extractCss
? MiniCssExtractPlugin.loader
: 'style-loader'
},
{
loader: 'css-loader',
options: {
Expand Down

0 comments on commit 7225d29

Please sign in to comment.