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

Support relative assets in a different directory #26

Closed
jasonwilliams opened this issue Mar 4, 2022 · 4 comments
Closed

Support relative assets in a different directory #26

jasonwilliams opened this issue Mar 4, 2022 · 4 comments

Comments

@jasonwilliams
Copy link

So my previous webpack config would generate something which looked like this. html-webpack-plugin

public
├── index.html (with links to the below embedded in)
└── ui-assets
    ├── assets-manifest.json
    ├── main.d2fe0910b8.js
    ├── main.d2fe0910b8.js.map
    ├── vendor.67dfc8f6a1.js
    └── vendor.67dfc8f6a1.js.map

This was useful to us because we didn't want the main entry point (index.html) to be hashed. it also allowed us to serve static assets from a different place.

Is it possible to have the same result with this plugin?

@craftamap
Copy link
Owner

Hey there!

I think this should be possible by using esbuild's entry name (and it's sister asset name and chunk name) option.

Something like this should do the trick:

esbuild.build({
    entryPoints: ['src/index.js'],
    entryNames: "ui-assets/[name]-[hash]",
    chunkNames: "ui-assets/[name]-[hash]", // If needed
    assetNames: "ui-assets/[name]-[hash]", // If needed
    metafile: true,
    outdir: 'dist/',
    plugins: [
        htmlPlugin({
            files: [
                {
                    entryPoints: [
                        'src/index.js',
                    ],
                    filename: 'index.html',
                    htmlTemplate: `
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
            </head>
            <body>
                <div id="root">
                </div>
            </body>
            </html>
          `,
                },
            ]
        })
    ]
})

Does this work for you?

@jasonwilliams
Copy link
Author

jasonwilliams commented Mar 7, 2022

Thanks that works, although --serve seems to fail. Do you know if it's possible to support serve as we will need that for development.

When i use --serve i get a blank white screen, when looking in dev tools the js file has the same contents at the html file. so there's syntax errors.

Clicking ui-assets just refreshes the same directory listing.
I did also raise this the chialab version also but yours looks closer to working chialab/rna#44

@craftamap
Copy link
Owner

craftamap commented Mar 7, 2022

Looks like using serve is not possible right now, because of this bug.

Is anything preventing you from using watch: true instead of serve and starting the server by hand, e.G. using python -m http.server 8080?

@jasonwilliams
Copy link
Author

jasonwilliams commented Mar 7, 2022

@craftamap I think I’ll need to use watch with browsersync. Thanks.
Feel free to close this issue and I’ll keep an eye on that issue you linked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants