Intent to implement: Vue SFC integration
See original GitHub issueCurrent State: Research
This ticket will guide the discussion of implementing css-blocks in Vue Single File Components.
Motivation
Vue provides a rich interface for creating single file components. In the ecosystem, vue-loader provides both an implementation of scoped styles and easy hooks into css-modules. Scoped styles work well until they don’t. Css-modules relies on a lot of dynamic class bindings and has its own set of issues making it a non-optimal solution. I think css-blocks has an opportunity to shine.
Scope
- The implementation will only cover SFC style blocks
- The implementation will work with vue-loader 15+
Notes
- vue-template-compiler’s compile method returns an ast for the template. Hopefully that’ll ease the block parsing phase.
- Vue’s templates have the ability to use preprocessors. That means if we integrate with vue-loader we’ll need to being the css-blocks processing after the preprocessor transforms, but before vue-loader compiles the template. I think one option would be to make a wrapper around vue-template-compiler and tell vue-loader to use that compiler instead.
- A personal desire of mine is to have this functionality by default on all style tags in SFCs. No
scoped
attributes needed. I’m uncertain if we should provide an escape hatch to have css-blocks not parse certain style tags.
@chriseppstein I’m sure I’ll have a lot of questions. Once we can work through the basic approach I’ll create a POC PR.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:42
- Comments:18 (11 by maintainers)
Top Results From Across the Web
Using Pre-Processors - Vue Loader
vue-loader allows you to use other webpack loaders to process a part of a Vue component. It will automatically infer the proper loaders...
Read more >Vue 3.2 - Using Composition API with Script Setup
Introduction. Vue 3 introduced the Composition API as a new way to work with reactive state in a Vue application.
Read more >Using the Vue CLI to add Vue.js to Existing ASP.Net Web ...
This isn't really a from scratch Vue tutorial – there are lots and lots of resources out there on how to use Vue...
Read more >How To Generate a Vue.js Single Page App With the Vue CLI
If you do not want to configure your project and opt for the defaults, you can do so with either Vue 2 or...
Read more >Creating a Hybrid Single Page App in WordPress with VueJS
Whether you need to use modern JavaScript or Vue.js will completely ... Integrating a Vue.js App in WordPress with Custom Page Templates.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, I’m also interested in using css-blocks with Vue! There are a couple of notes related to current state notes:
I believe this could be a stop sign for existing Vue projects to start using
css-blocks
.Also plain styles are useful at some point. Mixing them with
scoped
ones also a well-known practice. That’s why limiting style tags to one per file may be not a good choice.Can’t we just introduce a new (
block
) keyword for style tags likescoped
andmodule
? And require only one style withblock
keyword for the component? E.g.Anyway, for SFCs compilation there is a set of utils: https://github.com/vuejs/component-compiler-utils may be useful!
I haven’t got time to fully investigate this topic, but if anything I’d stay away from directives. I’d suggest looking into custom compiler modules that are more powerful then directives. (API type interface)
These modules can be passed to the underlying compiler via
vue-loader
options as well.