Skip to content

Commit

Permalink
feat: use postcss plugin to transform unocss (#6790)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia authored Feb 18, 2024
1 parent 3ce4cb8 commit e0b2eae
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 900 deletions.
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

0 comments on commit e0b2eae

Please sign in to comment.