Skip to content

Commit

Permalink
feat(webpack): provide preseted webpack plugin entry, close #1056
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 4, 2022
1 parent 1ea7dd7 commit 0803628
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/unocss/build.config.ts
Expand Up @@ -4,6 +4,7 @@ export default defineBuildConfig({
entries: [
'src/index',
'src/vite',
'src/webpack',
'src/preset-uno',
'src/preset-icons',
'src/preset-attributify',
Expand Down
13 changes: 13 additions & 0 deletions packages/unocss/package.json
Expand Up @@ -72,6 +72,11 @@
"types": "./dist/vite.d.ts",
"require": "./dist/vite.cjs",
"import": "./dist/vite.mjs"
},
"./webpack": {
"types": "./dist/webpack.d.ts",
"require": "./dist/webpack.cjs",
"import": "./dist/webpack.mjs"
}
},
"main": "dist/index.cjs",
Expand All @@ -88,6 +93,14 @@
"build": "unbuild",
"stub": "unbuild --stub"
},
"peerDependencies": {
"@unocss/webpack": "workspace:*"
},
"peerDependenciesMeta": {
"@unocss/webpack": {
"optional": true
}
},
"dependencies": {
"@unocss/cli": "workspace:*",
"@unocss/core": "workspace:*",
Expand Down
18 changes: 18 additions & 0 deletions packages/unocss/src/webpack.ts
@@ -0,0 +1,18 @@
import type { WebpackPluginOptions } from '@unocss/webpack'
import WebpackPlugin from '@unocss/webpack'
import presetUno from '@unocss/preset-uno'

export * from '@unocss/webpack'

export default function UnocssWebpackPlugin<Theme extends {}>(
configOrPath?: WebpackPluginOptions<Theme> | string,
) {
return WebpackPlugin<Theme>(
configOrPath,
{
presets: [
presetUno(),
],
},
)
}
4 changes: 2 additions & 2 deletions packages/webpack/README.md
Expand Up @@ -9,12 +9,12 @@ Currently, this plugin only supports [the `global` mode](https://github.com/unoc
## Installation

```bash
npm i -D @unocss/webpack
npm i -D unocss @unocss/webpack
```

```ts
// webpack.config.js
const UnoCSS = require('@unocss/webpack').default
const UnoCSS = require('unocss/webpack').default

module.exports = {
plugins: [
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack/src/index.ts
Expand Up @@ -23,8 +23,8 @@ export function defineConfig<Theme extends {}>(config: WebpackPluginOptions<Them
return config
}

export default function WebpackPlugin(
configOrPath?: WebpackPluginOptions | string,
export default function WebpackPlugin<Theme extends {}>(
configOrPath?: WebpackPluginOptions<Theme> | string,
defaults?: UserConfigDefaults,
) {
return createUnplugin(() => {
Expand Down

0 comments on commit 0803628

Please sign in to comment.