forked from swc-project/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# plugins | ||
Plugins for swc, written in rust | ||
# Plugins | ||
|
||
Plugins for SWC, written in Rust | ||
|
||
#### Currently Available: | ||
|
||
- [`emotion`](packages/emotion) | ||
- [`jest`](packages/jest) | ||
- [`relay`](packages/relay) | ||
- [`styled-components`](packages/styled-components) | ||
- [`styled-jsx`](packages/styled-jsx) | ||
- [`transform-imports`](packages/transform-imports) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
### `@swc/plugin-relay` | ||
|
||
#### Setup | ||
|
||
```sh | ||
npm install --save-dev @swc/plugin-relay @swc/[email protected] | ||
``` | ||
|
||
> @swc/core@1.2.215 is required for now | ||
### Example | ||
|
||
The below shows how to configure `@swc/plugin-relay` and pass the options to Webpack: | ||
|
||
Create an `.swcrc.js` file like the below: | ||
|
||
```js | ||
// .swcrc.js | ||
|
||
module.exports = { | ||
jsc: { | ||
experimental: { | ||
plugins: [ | ||
[ | ||
"@swc/plugin-relay", | ||
{ | ||
language: "typescript", | ||
schema: "data/schema.graphql", | ||
rootDir: __dirname, | ||
src: "src", | ||
artifactDirectory: "src/__generated__", | ||
}, | ||
], | ||
], | ||
}, | ||
parser: { | ||
syntax: "typescript", | ||
tsx: true, | ||
}, | ||
transform: { | ||
react: { | ||
runtime: "automatic", | ||
}, | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
And then update your `swc-loader` Webpack config: | ||
|
||
```js | ||
const swcConfig = require("./.swcrc.js") | ||
|
||
// ... | ||
|
||
{ | ||
include: path.resolve("./src"), | ||
test: /\.ts$/, | ||
use: [ | ||
{ | ||
loader: "swc-loader", | ||
options: swcConfig, | ||
}, | ||
], | ||
} | ||
``` | ||
|
||
> Note: We're using a `.swcrc.js` file extension up above and importing the config directly because Relay needs access to `__dirname`, which can't be derived from the default JSON parsed from `.swcrc`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### `@swc/plugin-styled-components` | ||
|
||
#### Setup | ||
|
||
```sh | ||
npm install --save-dev @swc/plugin-styled-components @swc/[email protected] | ||
``` | ||
|
||
> @swc/core@1.2.215 is required for now | ||
Then update your `.swcrc` file like below: | ||
|
||
```json | ||
{ | ||
"jsc": { | ||
"experimental": { | ||
"plugins": [ | ||
[ | ||
"@swc/plugin-styled-components", | ||
{ | ||
"displayName": true, | ||
"ssr": true | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} | ||
``` |