-
Notifications
You must be signed in to change notification settings - Fork 49
Vue component compiler implementation as... #29
Conversation
src/template-compiler/index.js
Outdated
} | ||
} | ||
|
||
return Promise.resolve(output) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does callback work?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Hey! @jackmellis We are working on a low level (build tool agnostic) SFC compiler. The 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. |
src/style-compiler/index.js
Outdated
plugins.push(scopeId({ id: config.scopeId })) | ||
} | ||
|
||
return postcss(plugins).process(style.code, options).then(result => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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
For the tests, can we assert against stubs? |
@phanan I haven't invested much time in tests. Open to suggestions. |
@eddyerburgh Default API is sync now. 👍 Thanks for helping. |
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. |
I think for something so comprehensive, there needs to be a whole lot more unit tests written though! |
@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.
I will refactor vue-meteor component compiler with this. 😄 |
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! |
@evan would be reviewing it, next few weeks. Hopefully you'll find an alpha release in early January. |
Ok cool, please feel free to reach out if we can help at all! |
Hey @znck - this is really great work! Quite well done. |
Question:
Did you expose them because you needed them in |
I am unsure how to provide extract styles and inject styles functionality. In https://github.com/znck/rollup-plugin-vue/blob/next/src/index.js#L133-L140 I believe all SFC specific functionalities should be in |
...per design discussion thread #28