Skip to content

Issues with static files and ESBuild loader #9

@ThiagoFacchini

Description

@ThiagoFacchini

Hello,

I'm having issues configuring esbuild-dev-server to work.

This is my current esBuildDevServer configuration:

esBuildDevServer.start(
    build({
        entryPoints: ['./index.tsx'],
        bundle: true,
        minify: false,
        sourcemap: true,
        incremental: true,
        platform: 'browser',
        target: ['chrome58', 'safari11'],
        loader: { 
            '.png': "file", 
            '.hdr': 'file', 
            '.jpg': 'file',
            '.otf': 'file',
            '.ttf': 'file'
        },
        plugins: [
            stylePlugin({
                postcss: {
                    plugins: [
                        postcssImport,
                        postcssNesting,
                        autoprefixer                        
                    ]
                }
            }),
            copyFilePlugin({
                source: ['utils/reset.css'],
                target: ['../../public/client/static'],
                copyWithFolder: false
            }),
            svgPlugin()
        ],
        outdir: '../../public/client/static'
    }),
    // To run the dev server a permission change is necessary:
    // chmod u+x node_modules/esbuild-dev-server-darwin-x64/devserver
    {
        port: '8080',
        watchDir: './',
        index: '../../public/client/index.html',
        staticDir: '../../public/client/',
        onBeforeRebuild: {},
        onAfterRebuild: {}
    }
)

And this is my current file structure:
Screen Shot 2022-10-25 at 11 41 58 am

As you can see things are apparently in place, although when I open my application, the very first view tries to load the image (logo-DGF6IMCN.png), which fails because the path is wrong as the picture below shows:
Screen Shot 2022-10-25 at 11 43 14 am

I understand my files are going to this path due my outdir configuration right? If I change that parameter to '../../plublic/client', then the files get copied to the 'proper' path but the esbuild-dev-server understands any request on this path to be a route, so I'm kinda lost on how to configure it to work properly.

The only way I can currently get it to work is if I set the loader to data-url, which is far from be ideal.

Can you guys please advise?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions