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

CSS is output as "main.css", old esbuild w/limited plugins, and esbuild config not watched #50

Open
pjeby opened this issue Jun 4, 2021 · 4 comments

Comments

@pjeby
Copy link

pjeby commented Jun 4, 2021

Running the build or dev commands generates main.css in the target directory, rather than styles.css. This appears to be esbuild's doing. I was able to work around the problem by installing a local, up-to-date copy of esbuild, deleting the bundled esbuild from obsidian-plugin-cli, and using the following esbuild.config.js:

const fs = require('fs');
let plugin = {
    name: "rename-styles",
    setup(build) {
        build.onEnd(() => {
            const {outfile} = build.initialOptions;
            const outcss = outfile.replace(/\.js$/, ".css");
            const fixcss = outfile.replace(/main\.js$/, "styles.css");
            if (fs.existsSync(outcss)) {
                console.log("Renaming", outcss, "to", fixcss);
                fs.renameSync(outcss, fixcss);
            }
        });
    }
}
module.exports = {
    plugins: [plugin],
}

Perhaps something like this plugin should be added to the build process by default? (Also, bumping the esbuild version seems like a good idea, since the bundled version doesn't provide an onEnd hook.)

Last, but not least, it appears that the dev command does not watch esbuild.config.js, so you have to kill and restart it for config changes to take effect.

@zephraph
Copy link
Collaborator

zephraph commented Jun 4, 2021

Thanks for the feedback! Yeah, I'll tackle this.

@zephraph
Copy link
Collaborator

zephraph commented Jun 4, 2021

Okay the esbuild version bump should be going out.

I actually had trouble w/ the .css file being the wrong name on output but I thought I'd fixed that. I'll dig back into that and get it fixed up for the next release.

@pjeby
Copy link
Author

pjeby commented Jun 4, 2021

Sure. By the way, rather than having a special option for a style sheet, shouldn't the plugin just import any css or scss files it needs? There's no need to specify the file externally then.

@zephraph
Copy link
Collaborator

zephraph commented Jun 6, 2021

Yep, that is indeed the ideal. I didn't recommend that b/c of this message from esbuild's docs.

image

That referenced evanw/esbuild#465 which seems to be fixed now. I'll update accordingly.

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