next-yak
Version:
next-yak is a CSS-in-JS solution tailored for Next.js that seamlessly combines the expressive power of styled-components syntax with efficient build-time extraction of CSS using Next.js's built-in CSS configuration
52 lines (50 loc) • 1.33 kB
JavaScript
import { fileURLToPath } from "node:url";
import { buildYakPluginOptions, resolveYakContext } from "../withYak/index.js";
//#region rsbuild/index.ts
const rspackLoaderPath = fileURLToPath(new URL("../loaders/turbo-loader.cjs", import.meta.url));
function pluginYak(yakOptions = {}) {
return {
name: "next-yak",
setup(api) {
api.modifyRspackConfig((config) => {
const rootContext = api.context.rootPath;
const yakPluginOptions = {
...buildYakPluginOptions(yakOptions, rootContext),
importMode: {
value: "data:text/css;base64,",
transpilation: "Css",
encoding: "Base64"
}
};
config.module ??= {};
config.module.rules ??= [];
config.module.rules.push({
test: /\.(c|m)?[jt]sx?$/,
exclude: /[\\/]node_modules[\\/]/,
enforce: "pre",
use: [{
loader: rspackLoaderPath,
options: {
yakOptions,
yakPluginOptions
}
}]
}, {
mimetype: "text/css",
type: "css/auto"
});
const yakContext = resolveYakContext(yakOptions.contextPath, rootContext);
if (yakContext) {
config.resolve ??= {};
config.resolve.alias = {
...config.resolve.alias,
"next-yak/context/baseContext": yakContext
};
}
});
}
};
}
//#endregion
export { pluginYak };
//# sourceMappingURL=index.js.map