remorses / esbuild-plugins

Collection of useful esbuild js plugins
276 stars 31 forks source link

How does '@esbuild-plugins/tsconfig-paths' work? #6

Open RyannGalea opened 3 years ago

RyannGalea commented 3 years ago

Really trying to solve an issue with resolving paths when building with esbuild and it seems this project will do that? At some point, not sure how to use it in its current form?

acidoxee commented 2 years ago

Hi, same question here! Is this plugin ready for consumption? The checkmark in the readme seems to indicate so, but I don't think it is yet? At least it doesn't seem to work out of the box for me. A little help would be greatly appreciated 😉

RyannGalea commented 2 years ago

@acidoxee I resorted to using 'tsc-alias' & babel, couldn't get esbuild to work with my Typescript project.

kritzware commented 2 years ago

The tsconfig-paths plugin also seems to do nothing for me out of the box. Is this plugin working for anyone else?

rickklaasboer commented 2 years ago

Managed to get it working as follows:

const esbuild = require('esbuild');
const {TsconfigPathsPlugin} = require('@esbuild-plugins/tsconfig-paths');

esbuild
    .serve(
        {servedir: 'public', port: 3000},
        {
            bundle: true,
            outfile: 'public/js/app.js',
            entryPoints: ['./src/index.tsx'],
            minify: true,
            define: {
                global: 'window',
            },
            inject: ['./esbuild/react-shim.js'],
            plugins: [TsconfigPathsPlugin({tsconfig: './tsconfig.json'})],
        },
    )
    .catch((err) => console.log(err));
{
    "compilerOptions": {
        "target": "es2020",
        "lib": ["dom", "dom.iterable", "esnext"],
        "allowJs": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": true,
        "jsx": "react-jsx",
        "baseUrl": "./",
        "paths": {
            "@/*": ["./src/*"]
        }
    },
    "include": ["src"]
}

The default export coming from @esbuild-plugins/tsconfig-paths doesn't seem to work.

AllanOricil commented 2 months ago

@rickklaasboer I had the same problem and your solution solved it. Thank you.