Skip to content
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
1 change: 1 addition & 0 deletions e2e/cases/css/inline-query-node-target/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Android >= 4.0
17 changes: 11 additions & 6 deletions e2e/cases/css/inline-query-node-target/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
output: {
target: 'node',
module: true,
overrideBrowserslist: ['Android >= 4.0'],
distPath: process.env.NODE_ENV === 'production' ? 'dist-build' : 'dist-dev',
},
dev: {
writeToDisk: true,
},
environments: {
web: {},
node: {
output: {
target: 'node',
module: true,
distPath:
process.env.NODE_ENV === 'production' ? 'dist-build' : 'dist-dev',
},
},
},
});
19 changes: 17 additions & 2 deletions packages/core/src/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ export const pluginCss = (): RsbuildPlugin => ({

api.modifyBundlerChain({
order: 'pre',
handler: async (chain, { target, isProd, CHAIN_ID, environment }) => {
handler: async (
chain,
{ target, isProd, CHAIN_ID, environment, environments },
) => {
const rule = chain.module.rule(CHAIN_ID.RULE.CSS);
const inlineRule = chain.module.rule(CHAIN_ID.RULE.CSS_INLINE);
const { config } = environment;
Expand Down Expand Up @@ -358,6 +361,18 @@ export const pluginCss = (): RsbuildPlugin => ({

const { minifyCss } = parseMinifyOptions(config);

// Use the same browserslist as web bundles to ensure consistent CSS output
// Prevent mismatched prefixes or features between SSR and client hydration
let { browserslist } = environment;
if (target === 'node') {
const webEnvironment = Object.values(environments).find(
(env) => env.config.output.target === 'web',
);
if (webEnvironment?.browserslist) {
browserslist = webEnvironment.browserslist;
}
}

updateRules(
(rule, type) => {
// Inline styles are not processed by Rspack's minimizers,
Expand All @@ -368,7 +383,7 @@ export const pluginCss = (): RsbuildPlugin => ({

const lightningcssOptions = getLightningCSSLoaderOptions(
config,
environment.browserslist,
browserslist,
minify,
);

Expand Down
5 changes: 4 additions & 1 deletion packages/core/tests/__snapshots__/environments.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,10 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e
"options": {
"errorRecovery": true,
"targets": [
"node >= 16",
"chrome >= 87",
"edge >= 88",
"firefox >= 78",
"safari >= 14",
],
},
},
Expand Down
Loading