Conversation
✅ Deploy Preview for unocss ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
commit: |
packages/webpack/src/index.ts
Outdated
| return unplugin(configOrPath, defaults).webpack() | ||
| } | ||
|
|
||
| export function UnoCSSRspackPlugin<Theme extends object>( |
There was a problem hiding this comment.
Named export will make the CJS interop hard - Maybe we should expose a new sub module with default export instead.
There was a problem hiding this comment.
We already have a named export defineConfig in this file. What we should do with it?
There was a problem hiding this comment.
Entry module "src/index.ts" is using named and default exports together. Consumers of your bundle will have to use
chunk.defaultto access the default export, which may not be what you want. Useoutput.exports: "named"to disable this warning.
I removed defineConfig. We already export WebpackPluginOptions interface, it seemed unnecessary to me. After removing it the warning above disappeared. I guess this makes it a breaking change?
There was a problem hiding this comment.
It can be a minor breaking change, I can bump a new minor version to be safe.
|
@sibbng Hello, how to use it? Use it like in webpack: Add import { createApp } from 'vue'
import App from './App.vue''
import 'uno.css'
import './index.css'
createApp(App).mount('#root')But I encountered a problem: The unocss I wrote in /* src/style.css */
.body {
--uno: m-0;
@apply: bg-red;
}The generated result is: .body {
--uno: m-0;
}But should be: .body {
margin: 0;
--un-bg-opacity: 1;
background-color: rgb(248 113 113 / var(--un-bg-opacity));
}I have added the css file in the filesystem and configured the transformerDirectives plugin. import { defineConfig, presetUno, transformerDirectives, transformerVariantGroup } from 'unocss'
export default defineConfig<Theme>({
content: {
filesystem: ['src/**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,css}'],
},
presets: [
presetUno(),
],
transformers: [transformerVariantGroup(), transformerDirectives()],
})There is the same issue in the postcss plugin. But this works fine in Vite. |
|
I create a example project: https://codesandbox.io/p/github/rspack-contrib/rsbuild-codesandbox-example/csb-89wjsv/draft/clever-roman // uno.config.mjs
import { defineConfig, presetUno } from 'unocss';
export default defineConfig({
content: {
filesystem: ['./src/**/*.{html,js,ts,jsx,tsx,css}'],
},
presets: [presetUno()],
preflights: [
{
getCSS: ({ theme }) => `
body {
color: blue;
--uno: bg-red;
}
`
}
]
});/* src/index.css */
@unocss preflights;
@unocss default;
@unocss;
body {
--uno: font-italic;
color: green;
}The results are:
|
|
I found a new issue, <span className="hover:(c-red text-16) hover-font-bold hover:bg-pink">default style</span>
|
Yes.
Yeah, It seems that a problem in our Webpack plugin. For some reasons CSS files are excluded. You can fix that like that: import { defineConfig, presetUno, transformerDirectives, transformerVariantGroup } from 'unocss'
import { Theme } from 'unocss/preset-mini'
export default defineConfig<Theme>({
content: {
pipeline: {
exclude: [],
}
},
presets: [
presetUno(),
],
transformers: [transformerVariantGroup(), transformerDirectives({ enforce: "pre" })],
})
Also you need to set
I cannot fork Codesandbox project. I tried locally on my project It works for me. Maybe you should update rsbuild to latest. Your template using beta version. |
|
Thank you for your reply. I will start trying right away. The issue with However, the /* src/index.css */
:root {
@apply c-grey-700 bg-primary-50;
}No output was generated. I tried using I am migrating my project from I will create a GitHub example repository later to replicate this issue. @sibbng Hello, Sorry to trouble you, I have created a repository for reproduction, could you take a look? https://github.com/wtto00/rsbuild-unocss-apply-issue The This issue is not necessary for the migration work. I replaced the |
|
My bad, also need to include CSS in include section: content: {
pipeline: {
include: [/\.(css|vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/],
exclude: [],
}
}, |
|
Perfact, it works! Thanks a lot. By the way, hope to add the usage and precautions to the document. |
|
|
|
|
rsbuild.config.ts import {defineConfig} from '@rsbuild/core';
import {pluginVue} from '@rsbuild/plugin-vue';
import {UnoCSSRspackPlugin} from "@unocss/webpack/rspack";
import {presetAttributify, presetUno, transformerDirectives, transformerVariantGroup} from "unocss";
export default defineConfig({
plugins: [pluginVue()],
tools: {
rspack(config, ctx) {
ctx.prependPlugins(UnoCSSRspackPlugin({
content: {
pipeline: {
include: [/\.(css|vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/],
exclude: [],
}
},
presets: [presetUno(), presetAttributify()],
transformers: [
transformerVariantGroup(),
transformerDirectives({enforce: "pre"}),
]
})
);
config.optimization ??= {};
config.optimization.realContentHash = true;
}
}
});index.ts import { createApp } from 'vue';
import App from './App.vue';
import "uno.css"
import './index.css';
createApp(App).mount('#root');App.vue <template>
<div class="content text-green-500">
Rsbuild with Vue3
</div>
</template>
<style scoped>
.content {
border:1px solid gray; /* worked */
@apply text-red-400; /* doesnt worked */
--at-apply: text-yellow-400; /* doesnt worked */
}
</style>
|



Fixes #4142
Usage: