Skip to content

Commit

Permalink
fix(webpack): add back deprecated Stylus support until v18 (nrwl#19810)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored Oct 23, 2023
1 parent 228636c commit 742b9a1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"sass-loader": "^12.2.0",
"source-map-loader": "^3.0.0",
"style-loader": "^3.3.0",
"stylus": "^0.59.0",
"stylus-loader": "^7.1.0",
"terser-webpack-plugin": "^5.3.3",
"ts-loader": "^9.3.1",
"tsconfig-paths-webpack-plugin": "4.0.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/webpack/src/utils/webpack/deprecated-stylus-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { logger } from '@nx/devkit';
// @ts-ignore
import * as stylusLoader from 'stylus-loader';
// TOOD(v18): Remove this file and stylus support.
export default function (source: string): string {
logger.warn(
`Stylus is support is deprecated and will be removed in Nx 18. We recommend that you migrate to Sass by renaming \`.styl\` files to \`.scss\` and ensuring that the content is valid Sass.`
);
return stylusLoader.call(this, source);
}
51 changes: 49 additions & 2 deletions packages/webpack/src/utils/with-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function withWeb(pluginOptions: WithWebOptions = {}): NxWebpackPlugin {
if (stylesOptimization) {
minimizer.push(
new CssMinimizerPlugin({
test: /\.(?:css|scss|sass|less)$/,
test: /\.(?:css|scss|sass|less|styl)$/,
})
);
}
Expand Down Expand Up @@ -199,6 +199,21 @@ export function withWeb(pluginOptions: WithWebOptions = {}): NxWebpackPlugin {
},
],
},
{
test: /\.module\.styl$/,
exclude: globalStylePaths,
use: [
...getCommonLoadersForCssModules(mergedOptions, includePaths),
{
loader: join(__dirname, 'webpack/deprecated-stylus-loader.js'),
options: {
stylusOptions: {
include: includePaths,
},
},
},
],
},
];

const globalCssRules: RuleSetRule[] = [
Expand Down Expand Up @@ -244,6 +259,22 @@ export function withWeb(pluginOptions: WithWebOptions = {}): NxWebpackPlugin {
},
],
},
{
test: /\.styl$/,
exclude: globalStylePaths,
use: [
...getCommonLoadersForGlobalCss(mergedOptions, includePaths),
{
loader: join(__dirname, 'webpack/deprecated-stylus-loader.js'),
options: {
sourceMap: !!mergedOptions.sourceMap,
stylusOptions: {
include: includePaths,
},
},
},
],
},
];

const globalStyleRules: RuleSetRule[] = [
Expand Down Expand Up @@ -289,11 +320,27 @@ export function withWeb(pluginOptions: WithWebOptions = {}): NxWebpackPlugin {
},
],
},
{
test: /\.styl$/,
include: globalStylePaths,
use: [
...getCommonLoadersForGlobalStyle(mergedOptions, includePaths),
{
loader: require.resolve('stylus-loader'),
options: {
sourceMap: !!mergedOptions.sourceMap,
stylusOptions: {
include: includePaths,
},
},
},
],
},
];

const rules: RuleSetRule[] = [
{
test: /\.css$|\.scss$|\.sass$|\.less$/,
test: /\.css$|\.scss$|\.sass$|\.less$|\.styl$/,
oneOf: [...cssModuleRules, ...globalCssRules, ...globalStyleRules],
},
];
Expand Down

0 comments on commit 742b9a1

Please sign in to comment.