pkgs icon indicating copy to clipboard operation
pkgs copied to clipboard

Missing feature resolveFullPaths

Open luas10c opened this issue 1 year ago • 1 comments

I'm using swc to build a project that works with modules

{
// ...
"type": "module"
// ...
}

when I build using the swc cli it doesn't resolve all the paths and puts .js at the end

examples

import { database } from '#/database/drizzle'

should look like this when the build is complete

import { database } from './database/drizzle.js'

There should be an option to resolve fullpaths like this package implements. Using this package you can use an argument that resolves all paths

https://www.npmjs.com/package/tsc-alias

// ...
  "tsc-alias": {
    "resolveFullPaths": true
  }
/// ....

luas10c avatar Oct 12 '24 01:10 luas10c

I need to do it this way to solve the problem.

\\ ...
  "scripts": {
    // ...
    "build": "swc src -d dist --strip-leading-paths --delete-dir-on-start && tsc-alias"
    // ...
  }
// ...

.swcrc

{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "baseUrl": ".",
    "parser": {
      "syntax": "typescript"
    },
    "target": "es2020",
    "paths": {
      "#/*": ["./src/*"]
    }
  },
  "module": {
    "type": "es6",
    "strict": true
  }
}

tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "skipLibCheck": true,
    "esModuleInterop": true,

    "target": "es2022",
    "module": "es2020",
    "moduleResolution": "node",

    "outDir": "dist",

    "allowSyntheticDefaultImports": true,

    "paths": {
      "#/*": ["./src/*"]
    }
  },
  "tsc-alias": {
    "resolveFullPaths": true
  }
}

luas10c avatar Oct 12 '24 01:10 luas10c