Skip to content

[Feature]: a css option so stylesheet imports resolve without a preprocessor plugin #1696

Description

@fi3ework

What problem does this feature solve?

A test file that imports a component also pulls in that component's stylesheet, because components declare it as a bare side-effect import (import './styles.less'). The test never reads a computed style — it asserts on the class names the component produces — but Rspack still has to resolve that import at build time, so the run fails before a single test executes.

Minimal reproduction on Rstest 0.11.6 (four files, node environment, no plugins):

// package.json
{ "private": true, "type": "module" }
// + @rstest/core@0.11.6
// rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  testEnvironment: 'node',
  include: ['test/**/*.test.ts'],
});
// src/styles.less
@primary: #1677ff;

.button {
  color: @primary;
}
// src/button.ts
import './styles.less';

export function buttonClassName(): string {
  return 'button';
}
// test/button.test.ts
import { expect, test } from '@rstest/core';
import { buttonClassName } from '../src/button';

test('asserts on a class name, never reads a style', () => {
  expect(buttonClassName()).toBe('button');
});

npx rstest:

× Module parse failed:
╰─▶   × JavaScript parse error: Expression expected
       ╭─[1:0]
     1 │ @primary: #1677ff;
       · ─
     2 │
     3 │ .button {
       ╰────

help:
      You may need an appropriate loader to handle this file type.

Varying only the extension and the plugin list, on the same 0.11.6:

import plugins result
./styles.css none passes
./styles.less none Module parse failed
./styles.less @rsbuild/plugin-less passes

Plain CSS is already inert without any configuration. A preprocessor stylesheet is not: the only way to get the import to resolve is to install the matching plugin and its compiler (@rsbuild/plugin-less brings in less@4.8.1). That adds a Less/Sass toolchain to a test setup solely so a file nobody reads can be parsed, and it means the run compiles stylesheets whose output is discarded.

The error is also hard to place from the message alone — it points at line 1 of a stylesheet and reports a JavaScript parse error, so it reads like a broken source file rather than a missing capability.

Vitest covers this case with test.css, which defaults to processing nothing and replaces the module with an empty string. Under that default neither .css nor .less requires any preprocessor to be installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions