Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack): add back deprecated Stylus support until v18 #19810

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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