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

Replace rollup-swc-preserve-directives with rollup-preserve-directives #60

Merged
merged 1 commit into from
Dec 1, 2023
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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

**New:** Building library for React Server Component support is added in `0.9.0`! `'use client'` and `'use server'` directives now are handled properly, without triggering rollup warnings. [Start using `'use client'` and `'use server'` in your library by adding two lines in your `rollup.config.js`](#react-server-component-directives-use-client-and-use-server)

> Since `0.9.1` the support for `'use client'` and `'use server'` has been separated into a standalone rollup plugin [`rollup-swc-preserve-directives`](https://github.com/huozhi/rollup-plugin-swc-preserve-directives), the previous `preserveUseDirective` named export is retained for the backward compatability.
> Since `0.9.1` the support for `'use client'` and `'use server'` has been separated into a standalone rollup plugin [`rollup-preserve-directives`](https://github.com/huozhi/rollup-preserve-directives), the previous `preserveUseDirective` named export is retained for the backward compatibility.

## Comparison

Expand Down Expand Up @@ -168,36 +168,36 @@ const swcMinifyConfig = {}

~~Since version `0.9.0`, the support for `'use client'` and `'use server'` has been added:~~

> The support for `'use client'` and `'use server'` has been separated into a standalone rollup plugin [`rollup-swc-preserve-directives`](https://github.com/huozhi/rollup-plugin-swc-preserve-directives), maintained by [@huozhi](https://github.com/huozhi) and me. The previous `preserveUseDirective` named export is retained for the backward compatibility.
> The support for `'use client'` and `'use server'` has been separated into a standalone rollup plugin [`rollup-preserve-directives`](https://github.com/huozhi/rollup-preserve-directives), maintained by [@huozhi](https://github.com/huozhi) and me. The previous `preserveUseDirective` named export is retained for the backward compatibility.

```bash
# npm
npm install -D rollup-swc-preserve-directives
npm install -D rollup-preserve-directives
# yarn
yarn add -D rollup-swc-preserve-directives
yarn add -D rollup-preserve-directives
# pnpm
pnpm add -D rollup-swc-preserve-directives
pnpm add -D rollup-preserve-directives
```

```js
// rollup.config.js
import { swc } from 'rollup-plugin-swc3';
import swcPreserveDirectives from 'rollup-swc-preserve-directives';
import preserveDirectives from 'rollup-preserve-directives';

export default {
input: 'xxxx',
output: {},
plugins: [
swc(),
// And add `swcPreserveDirectives` plugin after the `swc` plugin
swcPreserveDirectives()
// And add `preserveDirectives` plugin after the `swc` plugin
preserveDirectives()
];
}
```

And that is it!

`swcPreserveDirectives` supports:
`preserveDirectives` supports:

- Merging duplicated directives in the output bundles

Expand All @@ -220,7 +220,7 @@ And that is it!
export default {
input: 'src/index.js',
output: { file: 'dist/index.js' }
plugins: [swc(), swcPreserveDirectives()]
plugins: [swc(), preserveDirectives()]
}

// dist/index.js
Expand Down Expand Up @@ -255,7 +255,7 @@ And that is it!
},
// output both client bundle and server bundle in the "dist/" directory
output: { dir: 'dist/', entryFileName: '[name].js' }
plugins: [swc(), swcPreserveDirectives()]
plugins: [swc(), preserveDirectives()]
}

// dist/client.js
Expand Down
28 changes: 20 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@fastify/deepmerge": "^1.3.0",
"@rollup/pluginutils": "^5.0.5",
"get-tsconfig": "^4.7.2",
"rollup-swc-preserve-directives": "^0.6.0"
"rollup-preserve-directives": "^1.0.0"
},
"devDependencies": {
"@eslint-sukka/node": "^4.1.9",
Expand Down
2 changes: 1 addition & 1 deletion src/directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* preserveUseDirective is now a separate plugin, re-export to maintain the backward compatibility
*/
export { default as preserveUseDirective } from 'rollup-swc-preserve-directives';
export { default as preserveUseDirective } from 'rollup-preserve-directives';