Skip to content

Files

Latest commit

584f4d7 · May 6, 2025

History

History

relay

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Mar 7, 2025
Oct 29, 2024
May 6, 2025
May 6, 2025
May 6, 2025
Aug 18, 2024
May 6, 2025
Jun 29, 2024
May 6, 2025
Mar 27, 2023

@swc/plugin-relay

Setup

npm install --save-dev @swc/plugin-relay @swc/core

Example

The below shows how to configure @swc/plugin-relay and pass the options to Webpack:

Create an .swcrc.js file like the below:

// .swcrc.js

module.exports = {
  jsc: {
    experimental: {
      plugins: [
        [
          "@swc/plugin-relay",
          {
            rootDir: __dirname,
            artifactDirectory: "src/__generated__",
            language: "typescript",
            eagerEsModules: true,
          },
        ],
        // Or if you want to use multiple projects
        [
          "@swc/plugin-relay",
          {
            projects: [
              {
                rootDir: path.resolve(__dirname, '../project1'),
              },
              {
                rootDir: path.resolve(__dirname, '../project2'),
              }
            ],
            language: "typescript",
            eagerEsModules: true,
          },
        ],
      ],
    },
    parser: {
      syntax: "typescript",
      tsx: true,
    },
    transform: {
      react: {
        runtime: "automatic",
      },
    },
  },
};

And then update your swc-loader Webpack config:

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.

Output import paths

By default, @swc/plugin-relay will transpile import paths based on the language option. You can use outputFileExtension to change the file extension of the generated import paths.

plugins: [
    [
        "@swc/plugin-relay",
        {
            rootDir: __dirname,
            artifactDirectory: "src/__generated__",
            language: "typescript",
            eagerEsModules: true,
            outputFileExtension: "js",
        },
    ],
],

In this example typescript graphql files will output transpiled import path of javascript ending with .js.

@swc/plugin-relay

7.0.4

Patch Changes

  • 5ddbaeb: Update swc_core to v23

7.0.3

Patch Changes

  • d51d525: Update swc_core to v22.0.0

7.0.2

Patch Changes

  • cb94b92: Update swc_core to v21.0.1

7.0.1

Patch Changes

  • 31e3254: build: Update swc_core to v19.0.0

7.0.0

Major Changes

  • f0fee1d: Update swc_core to v15.0.1

6.3.2

Patch Changes

  • 04465bc: Update swc_core to v14.0.0, really

6.3.1

Patch Changes

  • ce8d317: Update swc_core to v14.0.0

6.3.0

Minor Changes

  • bfa0a51: Update swc_core to v13

6.2.0

Minor Changes

  • b8c4e6c: Update swc_core to v12

6.1.0

Minor Changes

  • 4c8b0e2: Update swc_core

6.0.4

Patch Changes

  • e8973e8: Update swc_core to v10.2.3

6.0.3

Patch Changes

  • f436a09: Update swc_core to v10.

6.0.2

Patch Changes

  • f155bce: Update swc_core to v9

6.0.1

Patch Changes

  • c9e75ce: Bump crate versions

6.0.0

Major Changes

  • 4574a70: Update swc_core to v8.0.1

5.0.3

Patch Changes

  • f3cea5f: Bump versions

5.0.2

Patch Changes

  • a73664c: Update swc_core to v6.0.2

5.0.1

Patch Changes

  • 4ff3b22: Move formatjs plugin to official plugin repository

5.0.0

Major Changes

  • 4ad7f56: Update swc_core to v5

4.0.0

Major Changes

  • ba13397: Update swc_core to v4

3.0.4

Patch Changes

  • 0508b6d: Update swc_core to v3

3.0.3

Patch Changes

  • cd5ad2a: Update swc_core to 1.0

3.0.2

Patch Changes

  • 20162c8: Update swc_core to v0.106.0

3.0.1

Patch Changes

  • 04548e2: Update swc_core to 0.103.x

3.0.0

Major Changes

  • f8e5fd0: Update swc_core to 0.102.x

2.0.15

Patch Changes

  • 7d17e25: Update swc_core to v0.101.x

2.0.14

Patch Changes

  • 7391419: Update swc_core to v0.100.0

2.0.13

Patch Changes

  • 9c28afb: Update swc_core to 0.99.x (@swc/core 1.7.0)

2.0.12

Patch Changes

  • 06e1e66: Fix operation name detection

2.0.11

Patch Changes

  • 7984823: Use Arc instead of Config

2.0.10

Patch Changes

  • af25741: Update swc_core to 0.96.0

2.0.9

Patch Changes

  • be5f997: Support multi-project mode

2.0.8

Patch Changes

  • 41a8f56: Update swc_core to v0.95.x

2.0.7

Patch Changes

  • fc30490: Update swc_core to v0.93.0

2.0.6

Patch Changes

  • 67f7bc2: Publish packages

2.0.5

Patch Changes

  • 0f38844: Publish all chanages

2.0.4

Patch Changes

  • 1379d24: Make config parsing typed.

2.0.3

Patch Changes

  • 1cc9eda: Update dependencies

2.0.2

Patch Changes

  • 247cca6: Update rustc to 'nightly-2024-04-16'

2.0.1

Patch Changes

  • 876bbce: Update swc_core to 0.92.x

2.0.0

Major Changes

  • 8e91d39: Update swc_core to 0.91.x

1.6.0

Minor Changes

  • 8c6f890: Always add current directory to relative output paths

1.5.122

Patch Changes

  • f4df366: Update swc_core

1.5.121

Patch Changes

  • c88b22b: Align package metadata

1.5.120

Patch Changes

  • a3cc4fb: Organize pacakge metadata

1.5.119

Patch Changes

  • e9e78ef: Update swc crates

1.5.118

Patch Changes

  • 6096d6d: Fix plugin version schema issue

1.5.117

Patch Changes

  • 37d3aaf: Depend on the swc download counter package

1.5.116

Patch Changes

  • dc0dc6b: Use correct identifier for imports

1.5.115

Patch Changes

  • 8bd92c7: swc_core 0.90.x

1.5.114

Patch Changes

  • 4ef0b7f: Add changelog to the readme

1.5.113

Patch Changes

  • 4e72680: swc_core@0.88.0

1.5.112

Patch Changes