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

How do I use syntastica-js on the web? #6

Open
rrthomas opened this issue Sep 18, 2023 · 3 comments
Open

How do I use syntastica-js on the web? #6

rrthomas opened this issue Sep 18, 2023 · 3 comments

Comments

@rrthomas
Copy link

rrthomas commented Sep 18, 2023

I see from the example code that syntastica-js is intended to be used on the web.

However, I can't work out how to access it from the browser.

I tried adding syntastica to my simple webpack-bundled project, and got an error that started:

ERROR in ./node_modules/syntastica/pkg/syntastica-js.js 8:827-843
Module not found: Error: Can't resolve 'module' in '/home/rrt/Software/ursalang.github.io/node_modules/syntastica/pkg'
resolve 'module' in '/home/rrt/Software/ursalang.github.io/node_modules/syntastica/pkg'

Sorry, I'm quite new to modern web JavaScript (more used to Node on the back-end), so apologies if I'm just being clueless, and thanks for syntastica!

@rrthomas rrthomas changed the title How do I use syntactica-js on the web? How do I use syntastica-js on the web? Sep 18, 2023
@RubixDev
Copy link
Owner

RubixDev commented Sep 19, 2023

The syntastica-js package in its current state is over 60 MB big, which is not suitable for the web. This is because all languages are included in one binary. I have not yet figured out a way to split the package into multiple separate packages (one per language plus one core package) and lazily fetch language binaries from the server on demand.

But if that is not a concern for you, a look at the example vite project may help, which uses an old version (the latest on npm) with only a few languages, where the bundle size was "only" ~9 MB. I also encountered a similar issue as you did, but couldn't figure out how to fix it from the package itself (I'm not that experienced with bundlers), but I found a workaround for vite:

// for some reason this seams to be needed when running a development server,
// although I don't see an error in the syntastica package.json
resolve: {
alias: {
syntastica: './node_modules/syntastica/pkg/index.js',
},
},

With some googling there are probably also similar workarounds for other bundlers. I'm pretty sure I already found one for Rollup, but didn't save it anywhere.

@rrthomas
Copy link
Author

Right, I guess I got the wrong idea from the example code writing to innerHTML… Nevertheless, I may well still be in the market, as currently I'm trying Pygments compiled to WASM, which is around 9MB (still, I admit, 60MB is a lot).

Again, thanks very much!

@RubixDev
Copy link
Owner

No you got it right, syntastica-js was meant to be used on the web, it's just that after having added so many more languages I realized the current approach wasn't working and I would have to figure something else out, so it just stayed in limbo since then. I also finally got around to better explaining the current Wasm support here and added two more tiny example projects.

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