oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.35k stars 2.78k forks source link

Bun.build & Bun.Transpiler CSSStyleSheet 样式表相关的问题 #15310

Open vamsaya opened 23 hours ago

vamsaya commented 23 hours ago

js now supports importing css modules, the type is CSSStyleSheet, refer to the documentation. https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/import

demo.js

import reset from './reset.css' with { type: 'css' };
document.adoptedStyleSheets = [reset];

Unfortunately, Bun.build doesn't support this, and my suggestion is like this:

Bun.build({
    loader: {
        ".css": "CSSStyleSheet",
    },
    naming: {
        CSSStyleSheet: "/css/[name].css",
    }
});

demo.js

import reset from '/css/reset.css' with { type: 'css' };
document.adoptedStyleSheets = [reset];

Bun.Transpiler with similar functionality to Bun.build removes with { type: 'css' };, please improve it, 3Q