NakedJSX/core

JavaScript code bundling is not working for local files imports

Closed this issue · 15 comments

Hello! Thanks for an amazing library.

Will there be an option to use import / export in JS (-client) files, and bundling in single <script> block on build stage?
For now js code is included 'as-is', with imports, and there is an error: RollupError: Could not resolve [module path].

dqh-au commented

Hi, thanks for your kind words!

Yes I want to support this - can I ask what you are trying to import? i.e. is it a local file in the project, or a commonjs / esm dependency?

I'm trying to split one large <script> into smaller blocks. So, it's a local file in project.

By the way, I don't think it is needed for external dependencies, because I can always use them in global scope from explicit <script> tag with CDN link.

dqh-au commented

Oh right - well if that's not working that's a bug. I'll take a look

I'll provide a repo example then.

dqh-au commented

if it's as you describe it should be easy to replicate, so you might as well save your effort unless I don't get the same result

dqh-au commented

I've replicated, will work on a fix now

dqh-au commented

As a workaround, use the path alias feature:

npx nakedjsx src --out out --path-alias \$SRC src

And lets say your *-client.mjs file in src currently has an import like:

import { SomeTag } from './some-file.mjs'

Change it to

import { SomeTag } from '$SRC/some-file.mjs'

dqh-au commented

Ok - I have released 0.12.5 - can you please check if it's fixed for you?

Yeah, it is working now! Thanks a lot.

dqh-au commented

Cool, thanks for reporting the issue :)

Since I only released this tool recently, I'm quite curious to know what you are using it for, if you're willing to share?

I wrote a SPA for a specialists schedule table. It started as single index.html, but was problematic then, especially when I needed two copies of file with slight table structure correction.
So your project is suited very well, because one single HTML file was a hard requirement for me.
Im not ready to open it for public, but sent you an invite to see the code.
(Rewriting in NakedJSX is in progress.)

dqh-au commented

Nice, you're making a real thing with it :)

If you haven't thought of this already, you could consider using a .css file for the global css, and:

npx nakedjsx src/general --out dist/general --pretty --css-common src/general/style.css

But obviously Page.AppendCss() works too.

dqh-au commented

By the way I just released a test version of 0.13 - if you could try it with your project and let me know if all ok I'd appreciate it. To test just change npx nakedjsx to npx nakedjsx@test.

Yeah, dev server and build is going without errors. Assuming numbers near Finished build. is time, build went faster, from 0.545 to 0.437.

dqh-au commented

Thanks for testing! It's good to know the optimisations I've been working on are helping with static site build times as well.