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

feat: add paths repro/example #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions examples/paths/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2021",
"baseUrl": ".",
"paths": {
"@modules/*": ["./src/modules/*"]
}
},
"module": {
"type": "commonjs"
}
}
15 changes: 15 additions & 0 deletions examples/paths/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Path-alias use case for swc: specifying the paths options in .swcrc

Note that this example also depends on the setup in /WORKSPACE at the root of this repository.
"""

load("@aspect_rules_swc//swc:swc.bzl", "swc")

# Runs `swc src/index.ts > ../../bazel-bin/examples/paths/src/index.js`
# You can run `bazel build --subcommands //examples/paths:transpile`
# to see the exact command line Bazel runs.
# Note that by default, sources are found by glob(["**/*.ts"])
swc(
name = "transpile",
swcrc = ".swcrc",
)
8 changes: 8 additions & 0 deletions examples/paths/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Note: your editor/ide might be complaining about this import path as
it probably does not interpret .swcrc like it normally would a tsconfig.json,
you should safely be able to ignore this
*/
import { moduleA } from "@modules/moduleA";

moduleA();
11 changes: 11 additions & 0 deletions examples/paths/src/modules/moduleA/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Note: your editor/ide might be complaining about this import path as
it probably does not interpret .swcrc like it normally would a tsconfig.json,
you should safely be able to ignore this
*/
import { moduleB } from "@modules/moduleB";

export const moduleA = () => {
console.log("This is module A");
moduleB();
};
1 change: 1 addition & 0 deletions examples/paths/src/modules/moduleB/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const moduleB = () => console.log("This is module B!");