Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: use postcss plugin to transform unocss #6790

Merged
merged 1 commit into from
Feb 18, 2024
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
5 changes: 5 additions & 0 deletions .changeset/yellow-donkeys-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/plugin-unocss': minor
---

fix: use postcss plugin to transform unocss
14 changes: 6 additions & 8 deletions packages/plugin-unocss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@
"files": [
"esm",
"!esm/**/*.map",
"*.d.ts"
"*.d.ts",
"uno.css"
],
"dependencies": {
"@unocss/config": "^0.57.6",
"@unocss/core": "^0.57.6",
"@unocss/reset": "^0.57.6",
"@unocss/webpack": "^0.57.6",
"unocss": "^0.57.6"
"@unocss/preset-uno": "^0.58.5",
"@unocss/postcss": "^0.58.5"
},
"devDependencies": {
"@ice/app": "workspace:^",
"@nuxt/schema": "^3.8.1"
"@unocss/core": "^0.58.5",
"@ice/app": "workspace:^"
},
"repository": {
"type": "http",
Expand Down
24 changes: 14 additions & 10 deletions packages/plugin-unocss/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as path from 'path';
import { fileURLToPath } from 'url';
import type { Plugin } from '@ice/app/types';
import UnocssWebpackPlugin from '@unocss/webpack';
import type { UserConfig } from '@unocss/core';
import { presetUno } from 'unocss';
import presetUno from '@unocss/preset-uno';

const PLUGIN_NAME = '@ice/plugin-unocss';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const plugin: Plugin<UserConfig> = (options) => ({
name: PLUGIN_NAME,
setup: ({ generator, onGetConfig }) => {
Expand Down Expand Up @@ -35,14 +38,15 @@ const plugin: Plugin<UserConfig> = (options) => ({
],
};
onGetConfig((config) => {
// Unocss is conflict with webpack 5 persistent caching.
config.enableCache = false;
config.configureWebpack ??= [];
config.configureWebpack.push((webpackConfig) => {
// @ts-expect-error
webpackConfig.plugins.push(UnocssWebpackPlugin({}, unoConfig));
return webpackConfig;
});
config.alias = {
...config.alias,
'uno.css': path.join(__dirname, '../uno.css'),
};
config.postcss = {
plugins: [['@unocss/postcss', {
configOrPath: unoConfig,
}]],
};
});
},
});
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-unocss/uno.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@unocss all;
Loading
Loading