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

docs: rename object to match official parameter name + simplify example #499

Merged
merged 2 commits into from
Jan 18, 2025
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
44 changes: 8 additions & 36 deletions docs/src/content/docs/v3/other/babel-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,6 @@ However, in some cases you might want to process files that miss such import:

If that's your case, you can configure the Babel plugin to process them.

```js title="babel.config.js"
/** @type {import('react-native-unistyles/plugin').UnistylesPluginOptions} */
const unistylesPluginConfig = {
autoProcessImports: ['@react-native-ui-kit', '@codemask/styles'],
}

module.exports = function (api) {
api.cache(true)

return {
plugins: [
['react-native-unistyles/plugin', unistylesPluginConfig]
]
}
}
```

#### `autoProcessPaths`

By default babel plugin will ignore `node_modules`.
Expand All @@ -233,31 +216,20 @@ Defaults to:
['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
```

```js title="babel.config.js"
/** @type {import('react-native-unistyles/plugin').UnistylesPluginOptions} */
const unistylesPluginConfig = {
autoProcessPaths: ['external-library/components'],
}

module.exports = function (api) {
api.cache(true)

return {
plugins: [
['react-native-unistyles/plugin', unistylesPluginConfig]
]
}
}
```

#### `debug`

In order to list detected dependencies by the Babel plugin you can enable the `debug` flag.
It will `console.log` name of the file and component with Unistyles dependencies.

#### Usage in `babel.config.js`

You can apply any of the options above as follows:

```js title="babel.config.js"
/** @type {import('react-native-unistyles/plugin').UnistylesPluginOptions} */
const unistylesPluginConfig = {
const unistylesPluginOptions = {
autoProcessImports: ['@react-native-ui-kit', '@codemask/styles'],
autoProcessPaths: ['external-library/components'],
debug: true,
}

Expand All @@ -266,7 +238,7 @@ module.exports = function (api) {

return {
plugins: [
['react-native-unistyles/plugin', unistylesPluginConfig]
['react-native-unistyles/plugin', unistylesPluginOptions]
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path')
const pak = require('../package.json')

/** @type {import('../plugin').UnistylesPluginOptions} */
const unistylesPluginConfig = {
const unistylesPluginOptions = {
debug: true,
isLocal: true,
autoProcessImports: ['@lib/theme', './st'],
Expand All @@ -16,7 +16,7 @@ module.exports = api => {
plugins: [
[
path.join(__dirname, '../plugin'),
unistylesPluginConfig
unistylesPluginOptions
],
[
'module-resolver',
Expand Down
35 changes: 24 additions & 11 deletions plugin/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
export interface UnistylesPluginOptions {
/**
* Logs found dependencies in every StyleSheet
* By default babel plugin will look for any `react-native-unistyles` import to start processing your file.
* However, in some cases you might want to process files that miss such import:
* - ui-kits that aggregates Unistyles components
* - monorepos that use Unistyles under absolute path like `@codemask/styles`
*
* If that's your case, you can configure the Babel plugin to process them.
*/
debug?: boolean;
autoProcessImports?: string[]

/**
* Only applicable for Unistyles monorepo for
* path resolution, don't use it!
* By default babel plugin will ignore `node_modules`.
* However similar to `autoProcessImports`, you can configure it to process extra paths.
*
* Under these paths we will replace `react-native` imports with `react-native-unistyles` factories that will borrow components refs [read more](https://www.unistyl.es/v3/other/babel-plugin#3-component-factory-borrowing-ref).
*
* Defaults to:
*
* ```ts
* ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
* ```
*/
isLocal?: boolean;
autoProcessPaths?: string[];

/**
* A list of imports that should trigger Unistyles
* babel plugin eg. `@codemask/ui`
* In order to list detected dependencies by the Babel plugin you can enable the `debug` flag.
* It will `console.log` name of the file and component with Unistyles dependencies.
*/
autoProcessImports?: string[]
debug?: boolean;

/**
* A list of paths that should trigger Unistyles babel
* plugin, check the default list defined in `REPLACE_WITH_UNISTYLES_PATHS`
* Only applicable for Unistyles monorepo for
* path resolution, don't use it!
*/
autoProcessPaths?: string[];
isLocal?: boolean;
}

export interface UnistylesPluginPass {
Expand Down