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

Modes cannot be imported in bundler #25

Open
tpluscode opened this issue Aug 5, 2020 · 2 comments
Open

Modes cannot be imported in bundler #25

tpluscode opened this issue Aug 5, 2020 · 2 comments

Comments

@tpluscode
Copy link
Contributor

I want to use wc-codemirror with webpack and it's not possible to import a mode

import '@vanillawc/wc-codemirror/mode/javascript/javascript.js'

This fails because the original source tries to require('../../lib/codemirror').

While I would not like to modify all those mode modules, I propose to create dummy commonjs (sic!) module at that path so that webpack and possibly other bundler can import do their thing

It can be simply

module.exports = window.CodeMirror

Ugly but it works

@evanplaice
Copy link
Member

The issue I have with this approach is I'd like to maintain the ability to update codemirror by bumping the dep and running a simple command to copy the source files over. It would require re-running this modification after each update.

What I'd much much rather do is implicitly import any dependencies necessary using import.meta.url. It looks like Webpack finally added import.meta support (after 2+ years of waiting) so that may be a viable option now.

Ex, if mode=javascript is selected then it should automatically add a script tag to the HTML header if one doesn't already exist there @therealadityashankar already has a way to handle this that guarantees there will be no dupes.

We could even modify the API to introduce a new language attribute where you just have to specify which language will be used and the web component automagically handles all necessary imports. The same can be done for themes as well.

The real question is... Does webpack support for import.meta.url actually work?

@ia3andy
Copy link

ia3andy commented Aug 18, 2023

I have the same problem with esbuild, any solution?

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

3 participants