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

Use with Snowpack #95

Open
jcuenod opened this issue Mar 24, 2021 · 2 comments
Open

Use with Snowpack #95

jcuenod opened this issue Mar 24, 2021 · 2 comments

Comments

@jcuenod
Copy link

jcuenod commented Mar 24, 2021

On an initial attempt to get this working with snowpack, I'm running into an issue resolving the mode:

Uncaught (in promise) TypeError: Failed to resolve module specifier 'codemirror/mode/jsx/jsx.js'

My code is minimal boilerplate:

import React from "react"
import CodeMirror from "@uiw/react-codemirror"
import "codemirror/keymap/sublime"
import "codemirror/theme/monokai.css"

const code = `const a = 0`

const App = () =>
	<div>
		<CodeMirror
			value={code}
			options={{
				theme: "monokai",
				keyMap: "sublime",
				mode: "jsx",
				lineNumbers: true,
			}}
		/>
	</div>

export default App
@jaywcjlove
Copy link
Member

jaywcjlove commented Mar 25, 2021

@jcuenod

Snowpack takes a different approach: Instead of bundling your entire application for this one requirement, Snowpack processes your dependencies separately. Here’s how it works:

node_modules/react/**/*     -> https://localhost:3000/web_modules/react.js
node_modules/react-dom/**/* -> https://localhost:3000/web_modules/react-dom.js
node_modules/codemirror/**/* -> https://localhost:3000/web_modules/codemirror.js 

await import(`codemirror/mode/${mode.mode}/${mode.mode}.js`);

Here we are dynamically loading mode js

@jcuenod
Copy link
Author

jcuenod commented Mar 25, 2021

Yes, so I'm wondering whether there's another way to load a mode (like whether I can supply a mode object or something).

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