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

Overview: Porting preactjs.com to WMR #809

Closed
13 tasks done
marvinhagemeister opened this issue Aug 29, 2021 · 7 comments
Closed
13 tasks done

Overview: Porting preactjs.com to WMR #809

marvinhagemeister opened this issue Aug 29, 2021 · 7 comments

Comments

@marvinhagemeister
Copy link
Member

marvinhagemeister commented Aug 29, 2021

Today I've attempted to port https://preactjs.com over from preact-cli to wmr. These are the issues I ran into:

@developit
Copy link
Member

IIRC, ~ is a prefix in Less that indicates "use the host to resolve this import". My guess is that, in WMR, we could just strip that prefix unconditionally when processing less?

@developit
Copy link
Member

developit commented Aug 29, 2021

I threw together a quick implementation of the async! prefix as a WMR plugin here:
https://github.com/developit/babel-preset-modernize/blob/website/website/plugins/async-prefix.js

(though I think just changing the code is likely the more logical approach)

@developit
Copy link
Member

Not sure which AST transforms you're running into, but if it's when processing things like babel-standalone or Codemirror, that was breaking in Webpack and Rollup too - IIRC preact-www is using Webpack's module.noParse feature to bypass this (also because it took forever to bundle). If that's what it is, I have a noParse plugin here:
https://github.com/developit/babel-preset-modernize/blob/website/website/plugins/noparse.js

@developit
Copy link
Member

developit commented Aug 29, 2021

For the Worker stuff, Comlink feels like it'd be a better option here. Bundling can be done by adding this config:

import OMT from '@surma/rollup-plugin-off-main-thread';

export default function({ mode, plugins }) {
  if (mode === 'build') {
    let omt = OMT({ silenceESMWorkerWarning: true });
    omt.outputOptions({ format: 'esm' });  // this plugin method does validation that breaks in Rollup 2+
    delete omt.outputOptions;  // ... so we spoof it and delete the method (since it was just for validation)
    omt.enforce = 'pre';
    plugins.push(omt);
  }
};

... the using new Worker(new URL('./path.js', import.meta.url), { type: 'module' }):

import { wrap } from 'comlink';

function createWorker() {
  let worker = wrap(new Worker(new URL('./worker.js', import.meta.url), { type: 'module' }));
  return worker;
}
// ...
let transformed = await worker.process(code);

@marvinhagemeister
Copy link
Member Author

marvinhagemeister commented Aug 29, 2021

Not sure which AST transforms you're running into, but if it's when processing things like babel-standalone or Codemirror, that was breaking in Webpack and Rollup too - IIRC preact-www is using Webpack's module.noParse feature to bypass this (also because it took forever to bundle). If that's what it is, I have a noParse plugin here:
https://github.com/developit/babel-preset-modernize/blob/website/website/plugins/noparse.js

It looks like the double transform issue we've been observing for a while. It happens with the markdown parser:

function applyEmoji(content) {
    // ... snip

	if (!pendingEmojiProcessor) {
	    // BAD replacement
		pendingEmojiProcessor = import(
/@alias/~/lib/gh-emoji/index.js'./gh-emoji'
		).then(({ replace }) => (processEmojis = replace || String));
	}
	return pendingEmojiProcessor.then(processEmojis => processEmojis(content));
}

@marvinhagemeister
Copy link
Member Author

Turns out the wrong AST was caused by an offset issue in our import specifier logic. See #823

@marvinhagemeister
Copy link
Member Author

With WMR 3.7.0 all those issues are no fixed 🎉

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