Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Vue component compiler implementation as... #29

Merged
merged 21 commits into from
Dec 15, 2017
Merged

Conversation

znck
Copy link
Member

@znck znck commented Oct 3, 2017

...per design discussion thread #28

@znck znck requested review from yyx990803 and chrisvfritz October 3, 2017 02:55
}
}

return Promise.resolve(output)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, Jest needs synchronous compilation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does callback work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, I'll need to check. The docs say the transformers need to be synchronous

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Can you point me to the transformer docs? I'll experiment with jest and async transformer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it could be sync if there is sync API for postcss.process

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A transformer is a module that provides a synchronous function for transforming source files

https://facebook.github.io/jest/docs/en/configuration.html#transform-object-string-string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could provide a synchronous version by default and an async wrapper for template-compiler.

Looks like we can do the same with style-compiler - postcss/postcss#595.

You can call .css on the result of process instead of .then. This makes it act sycnhronously

const hash = require('hash-sum')
const { SourceMapGenerator } = require('source-map')

const cache = LRU(100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 100 max items in cache? Do you think memory will be a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've kept same as vue-loader.

@eddyerburgh
Copy link
Member

eddyerburgh commented Oct 3, 2017

It looks good 🙂

But the compilers are async, so they can't be used in a Jest transformer (according to Jest docs, I'll read the code to make sure this is true)

@@ -0,0 +1,47 @@
var load = require('postcss-load-config')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading postcss config is not in scope of this project.

I'll remove this file.

Copy link

@chrisvfritz chrisvfritz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the experience of integrating single-file component compilation into another package, so I'm not sure I can offer a well-informed review. 😅

Something that might be a good idea though: having all the package authors who might need to consume this review the tests. Then they can provide feedback on any use cases they don't see covered there.

@znck znck requested a review from phanan October 7, 2017 20:31
@znck
Copy link
Member Author

znck commented Oct 7, 2017

Hey! @jackmellis

We are working on a low level (build tool agnostic) SFC compiler. The vue-component-compiler is multi-step decoupled compiler (loosely described in #28 (comment)).

Please go through the PR and if you have any concerns with respect to (https://www.npmjs.com/package/require-extension-hooks-vue) please notify.

plugins.push(scopeId({ id: config.scopeId }))
}

return postcss(plugins).process(style.code, options).then(result => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling process.css will give us css, and process.map gives you the map. The result of process is a LazyResult, which is synchronous

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'll make changes.

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I think we should provide a synchronous API by default and an optional asynchronous API for the compilers. It's possible with postCSS process

@phanan
Copy link
Member

phanan commented Oct 8, 2017

For the tests, can we assert against stubs?

@znck
Copy link
Member Author

znck commented Oct 8, 2017

@phanan I haven't invested much time in tests. Open to suggestions.

@znck
Copy link
Member Author

znck commented Oct 8, 2017

@eddyerburgh Default API is sync now. 👍 Thanks for helping.

@jackmellis
Copy link

I was wondering why there wasn't a universal compile tool (and assumed I just couldn't find it). This looks really promising. For extension-hooks it looks like it'll almost be a drop-in-and-run job.

Definitely makes sense to have a synchronous api by default.

I'll probably try to write an implementation of rehv using this PR just as a POC if I ever get a minute.

@jackmellis
Copy link

I think for something so comprehensive, there needs to be a whole lot more unit tests written though!

@znck
Copy link
Member Author

znck commented Oct 8, 2017

@jackmellis After Evan reviews it, I'd add tests.

To keep API akin to template-compiler, style style-compiler should
process one style block at a time.
@Akryum
Copy link
Member

Akryum commented Oct 27, 2017

I will refactor vue-meteor component compiler with this. 😄

@wadetandy
Copy link

Hey @znck, what's the status on this? We're working on some stuff right now that would greatly benefit from this being released, and I'd love to help push this across the finish line. Please let me know whether there's anything we do to chip in!

@znck
Copy link
Member Author

znck commented Dec 1, 2017

@evan would be reviewing it, next few weeks. Hopefully you'll find an alpha release in early January.

@wadetandy
Copy link

Ok cool, please feel free to reach out if we can help at all!

@yyx990803
Copy link
Member

Hey @znck - this is really great work! Quite well done.
I noticed there are few places out of sync with latest vue-loader, but I'll merge this as-is and use it as the starting point. I'll try to work on a branch of vue-loader using this to finalize the implementation.

@yyx990803 yyx990803 merged commit 977b947 into vuejs:master Dec 15, 2017
@yyx990803
Copy link
Member

Question:

  • I see the runtime includes the code from vue-style-loader but not used anywhere else.
  • It also exposes gen-id which isn't used anywhere in the codebase itself.

Did you expose them because you needed them in rollup-plugin-vue?

@znck
Copy link
Member Author

znck commented Dec 16, 2017

gen-id is exposed to tools.

I am unsure how to provide extract styles and inject styles functionality. In rollup-plugin-vue, I tried something but I don't like it.

https://github.com/znck/rollup-plugin-vue/blob/next/src/index.js#L133-L140

I believe all SFC specific functionalities should be in vue-component-compiler, so style injection code would be used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants