All Projects → egoist → Styled Vue

egoist / Styled Vue

Licence: mit
Use dynamic styles in Vue single-file components.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Styled Vue

Moment Locales Webpack Plugin
Easily remove unused Moment.js locales with webpack
Stars: ✭ 396 (-6.82%)
Mutual labels:  webpack
Vue2 Echo
基于vue2 + vue-router + vuex 构建的一个音乐类单页面应用 —— echo回声
Stars: ✭ 408 (-4%)
Mutual labels:  webpack
Cc
一个基于angular5.0.0+ng-bootstrap1.0.0-beta.8+bootstrap4.0.0-beta.2+scss的后台管理系统界面(没基础的同学请先自学基础,谢谢!)
Stars: ✭ 416 (-2.12%)
Mutual labels:  webpack
Framework7 Template Vue Webpack
Deprecated! Framework7 Vue Webpack starter app template with hot-reload & css extraction
Stars: ✭ 399 (-6.12%)
Mutual labels:  webpack
Web Document
前端历程
Stars: ✭ 405 (-4.71%)
Mutual labels:  webpack
Css Loader
CSS Loader
Stars: ✭ 4,067 (+856.94%)
Mutual labels:  webpack
Qikqiak.com
关注容器、kubernetes、devops、python、golang、微服务等技术 🎉🎉🎉
Stars: ✭ 394 (-7.29%)
Mutual labels:  webpack
Vue2 blog
使用vue2.x + vue-cli +vue-router+ vuex + axios + mysql + express + pm2 + webpack+nginx构建的具有登录,注册,留言,用户发帖,用户评论等功能的SPA Blog。注意,注意,注意,后端API全部自己手写,很适合刚学习vue以及express的小伙伴学习,喜欢请Star鼓励一下我,谢谢!项目预览:
Stars: ✭ 417 (-1.88%)
Mutual labels:  webpack
Webpack Boilerplate
A minimal webpack 5 boilerplate with only Babel, SASS and lodash (optional) on board
Stars: ✭ 404 (-4.94%)
Mutual labels:  webpack
Phaser Ce Npm Webpack Typescript Starter Project
Project to get you started with your Phaser-CE (using the npm module) game using Typescript and Webpack for building! No hassle asset management, Google Web Font loader, live server, development vs distribution build pipeline, Electron packaging for desktop builds, and more...
Stars: ✭ 414 (-2.59%)
Mutual labels:  webpack
Rewiremock
The right way to mock dependencies in Node.js or webpack environment.
Stars: ✭ 399 (-6.12%)
Mutual labels:  webpack
Sku
Front-end development toolkit
Stars: ✭ 403 (-5.18%)
Mutual labels:  webpack
Augur Ui
Augur UI
Stars: ✭ 412 (-3.06%)
Mutual labels:  webpack
Vuenode
VueNode 是一套基于 TypeScript + Vue.js + Node.js + MySQL 的前后端分离项目。
Stars: ✭ 396 (-6.82%)
Mutual labels:  webpack
React Lego
React-lego : incrementally add more cool stuff to your react app
Stars: ✭ 417 (-1.88%)
Mutual labels:  webpack
Adminkit
🧰 AdminKit is a free & open source Bootstrap 5 Admin Template
Stars: ✭ 395 (-7.06%)
Mutual labels:  webpack
Stylelint Webpack Plugin
A Stylelint plugin for webpack
Stars: ✭ 411 (-3.29%)
Mutual labels:  webpack
Annotated Webpack Config
This is the companion github repo for the "An Annotated webpack 4 Config for Frontend Web Development" article.
Stars: ✭ 425 (+0%)
Mutual labels:  webpack
After.js
Next.js-like framework for server-rendered React apps built with React Router
Stars: ✭ 4,051 (+853.18%)
Mutual labels:  webpack
Vue Cms
基于 Vue 和 ElementUI 构建的一个企业级后台管理系统
Stars: ✭ 415 (-2.35%)
Mutual labels:  webpack

ATTENTION: this project is not actively maintained for now (I still push some code once in a while), if you want to see improvements or get support, please consider sponsoring me.

styled-vue


NPM version NPM downloads CircleCI chat

Please consider EGOIST, to show your ❤️ and support.

Features

  • Zero-runtime CSS-in-JS for Vue SFC without compromise
  • Scoped CSS by default
  • CSS preprocessors support
  • Dynamic style just works (no IE support)
  • Working with SSR out-of-the-box
  • Hot module replacement still works
  • You get all the features without any config!

Table of Contents

Install

yarn add styled-vue --dev

Then register the Vue plugin (optional):

import Vue from 'vue'
import { StyledVue } from 'styled-vue'

Vue.use(StyledVue)

So far the plugin is only required for globalStyle, if you only need scoped style, you can safely skip this.

Example

<template>
  <div><h1 class="title">hello there!</h1></div>
</template>

<script>
import { css } from 'styled-vue'
import { modularScale } from 'polished'

export default {
  style: css`
    .title {
      /* You can access component's "this" via "vm" */
      color: ${vm => vm.$store.state.themeColor};
      font-size: ${modularScale(2)};
      margin: 0;
    }
  `
}
</script>

And that's it, it's like writing .vue file's scoped CSS in the <script> tag.

How to use

Using with webpack

I did say that styled-vue works without config, that might be a clickbait because you do need a single line of config in your webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          compiler: require('styled-vue/compiler') // <- here
        }
      }
    ]
  }
}

Using with Vue CLI

In your vue.config.js:

module.exports = {
  chainWebpack(config) {
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap(options => {
        options.compiler = require('styled-vue/compiler') // <- here
        return options
      })
  }
}

Using with Poi

In your poi.config.js:

module.exports = {
  plugins: ['styled-vue/poi']
}

Using with Nuxt.js

In your nuxt.config.js:

export default {
  modules: ['styled-vue/nuxt']
}

How does it work

Input:

<template>
  <h1>hello</h1>
</template>

<script>
import { css } from 'styled-vue'

export default {
  style: css`
    h1 {
      color: ${vm => vm.color};
      width: ${200 + 1}px;
    }
  `
}
</script>

Output:

<template>
  <h1 :style="$options.style(this)">hello</h1>
</template>

<script>
export default {
  style: function(vm) {
    var v0 = vm => vm.color
    var v1 = 200 + 1
    return {
      '--v0': v0(vm),
      '--v1': v1 + 'px'
    }
  }
}
</script>

<style scoped>
h1 {
  color: var(--v0);
  width: var(--v1);
}
</style>

Under the hood, it uses CSS variables for dynamic styles, that's why this feature is not supported in IE.

CSS Preprocessors

import { less, sass, scss, stylus } from 'styled-vue'

Just use corresponding exports from styled-vue.

The CSS will be passed to vue-loader and parsed by PostCSS if a postcss.config.js exists in your project, so it really just works like <style scoped>.

Global Styles

Use globalStyle instead of style on your component:

import { css } from 'styled-vue'

export default {
  globalStyle: css`
    body {
      color: ${vm => vm.bodyColor};
    }
  `
}

globalStyle relies on the Vue plugin, make sure to register it first:

import Vue from 'vue'
import { StyledVue } from 'styled-vue'

Vue.use(StyledVue)

For Nuxt users we automatically register it for you.

This only adds ~100 bytes to your application.

TypeScript

We use Babel to parse your code, so TypeScript should work out-of-the-box, however there're some caveats.

Editor Plugins

VSCode

Atom

Inspirations

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

styled-vue © EGOIST, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).

Website · GitHub @EGOIST · Twitter @_egoistlily

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].