Skip to content

Commit

Permalink
fix: ensure postcss-loader uses the built-in postcss (#3204)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Aug 14, 2024
1 parent 462ccdf commit f8fa16d
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/mini-css-extract-plugin/dist/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 0,
"modules": {
Expand Down Expand Up @@ -421,7 +421,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
"loader": "<ROOT>/node_modules/<PNPM_INNER>/mini-css-extract-plugin/dist/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 0,
"modules": {
Expand Down Expand Up @@ -784,7 +784,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
"loader": "<ROOT>/packages/core/dist/ignoreCssLoader.cjs",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 0,
"modules": {
Expand Down Expand Up @@ -1089,7 +1089,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
"loader": "<ROOT>/packages/core/dist/ignoreCssLoader.cjs",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 0,
"modules": {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/prebundle.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ export default {
);
},
},
{
name: 'postcss',
ignoreDts: true,
},
{
name: 'css-loader',
ignoreDts: true,
externals: {
semver: './semver',
postcss: '../postcss',
picocolors: '../picocolors',
},
afterBundle: writeEmptySemver,
Expand All @@ -172,6 +177,7 @@ export default {
externals: {
jiti: '../jiti',
semver: './semver',
postcss: '../postcss',
},
ignoreDts: true,
beforeBundle(task) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/helpers/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getCommonParentPath(paths: string[]): string {
}

export const getCompiledPath = (packageName: string): string =>
join(COMPILED_PATH, packageName);
join(COMPILED_PATH, packageName, 'index.js');

/**
* ensure absolute file path.
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const getPostcssLoaderOptions = async ({
userPostcssConfig.plugins ||= [];

const defaultPostcssConfig: PostCSSLoaderOptions = {
implementation: getCompiledPath('postcss'),
postcssOptions: userPostcssConfig,
sourceMap: config.output.sourceMap.css,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down
18 changes: 10 additions & 8 deletions packages/core/tests/__snapshots__/css.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`plugin-css > should use custom cssModules rule when using output.cssMod
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down Expand Up @@ -66,7 +66,7 @@ exports[`plugin-css injectStyles > should apply ignoreCssLoader when injectStyle
"loader": "<ROOT>/packages/core/src/ignoreCssLoader.cjs",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 0,
"modules": {
Expand Down Expand Up @@ -103,10 +103,10 @@ exports[`plugin-css injectStyles > should use css-loader + style-loader when inj
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/style-loader",
"loader": "<ROOT>/packages/core/compiled/style-loader/index.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down Expand Up @@ -154,7 +154,7 @@ exports[`should ensure isolation of PostCSS config objects between different bui
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand All @@ -179,8 +179,9 @@ exports[`should ensure isolation of PostCSS config objects between different bui
},
},
{
"loader": "<ROOT>/packages/core/compiled/postcss-loader",
"loader": "<ROOT>/packages/core/compiled/postcss-loader/index.js",
"options": {
"implementation": "<ROOT>/packages/core/compiled/postcss/index.js",
"postcssOptions": {
"config": false,
"plugins": [
Expand Down Expand Up @@ -211,7 +212,7 @@ exports[`should ensure isolation of PostCSS config objects between different bui
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand All @@ -236,8 +237,9 @@ exports[`should ensure isolation of PostCSS config objects between different bui
},
},
{
"loader": "<ROOT>/packages/core/compiled/postcss-loader",
"loader": "<ROOT>/packages/core/compiled/postcss-loader/index.js",
"options": {
"implementation": "<ROOT>/packages/core/compiled/postcss/index.js",
"postcssOptions": {
"config": false,
"plugins": [
Expand Down
8 changes: 4 additions & 4 deletions packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down Expand Up @@ -441,7 +441,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down Expand Up @@ -903,7 +903,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
"loader": "<ROOT>/packages/core/dist/ignoreCssLoader.cjs",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 0,
"modules": {
Expand Down Expand Up @@ -1237,7 +1237,7 @@ exports[`tools.rspack > should match snapshot 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/__snapshots__/environments.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ exports[`environment config > tools.rspack / bundlerChain can be used in environ
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down Expand Up @@ -1756,7 +1756,7 @@ exports[`environment config > tools.rspack / bundlerChain can be used in environ
"loader": "<ROOT>/packages/core/src/ignoreCssLoader.cjs",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 0,
"modules": {
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-less/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`plugin-less > should add less-loader 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand Down Expand Up @@ -65,10 +65,10 @@ exports[`plugin-less > should add less-loader and css-loader when injectStyles 1
"test": /\\\\\\.less\\$/,
"use": [
{
"loader": "<ROOT>/packages/core/compiled/style-loader",
"loader": "<ROOT>/packages/core/compiled/style-loader/index.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand Down Expand Up @@ -126,7 +126,7 @@ exports[`plugin-less > should add less-loader with excludes 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand Down Expand Up @@ -181,7 +181,7 @@ exports[`plugin-less > should add less-loader with tools.less 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports[`plugins/react > should work with swc-loader 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 1,
"modules": {
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-sass/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`plugin-sass > should add sass-loader 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 3,
"modules": {
Expand Down Expand Up @@ -67,10 +67,10 @@ exports[`plugin-sass > should add sass-loader and css-loader when injectStyles 1
"test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/,
"use": [
{
"loader": "<ROOT>/packages/core/compiled/style-loader",
"loader": "<ROOT>/packages/core/compiled/style-loader/index.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 3,
"modules": {
Expand Down Expand Up @@ -130,7 +130,7 @@ exports[`plugin-sass > should add sass-loader with excludes 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 3,
"modules": {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-stylus/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`plugin-stylus > should add stylus loader config correctly 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand Down Expand Up @@ -61,7 +61,7 @@ exports[`plugin-stylus > should allow to configure stylus options 1`] = `
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/builtin-plugin/css-extract/loader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader",
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
Expand Down

0 comments on commit f8fa16d

Please sign in to comment.