An open API service indexing awesome lists of open source software.

https://github.com/mrminfive/babel-plugin-vue-jsx-scoped-css

:hammer: CSS encapsulation solution for Vue JSX
https://github.com/mrminfive/babel-plugin-vue-jsx-scoped-css

scoped-css vue vue-jsx

Last synced: about 1 year ago
JSON representation

:hammer: CSS encapsulation solution for Vue JSX

Awesome Lists containing this project

README

          

# babel-plugin-vue-jsx-scoped-css


Downloads
Version
License

:hammer: CSS encapsulation solution for Vue JSX

## About

This plugin is used to implement the css scoped effect of template in vue jsx。

For more details, please refer to [react-scoped-css][reactscopedcss]

## Use

You have to add one babel plugin and one webpack loader.

### Babel

```bash
yarn add babel-plugin-vue-jsx-scoped-css --dev
```

and in your babelrc add

```json
{
"presets": ["@vue/babel-preset-jsx"],
"plugins": ["babel-plugin-vue-jsx-scoped-css"]
}
```

also note that you can define your own matching rule like this

```json
{
"plugins": [
[
"babel-plugin-vue-jsx-scoped-css",
{
"include": ".local.(sa|sc|c)ss$"
}
]
]
}
```

**This plugin must be before the vue jsx parsing plugin.**

### Webpack

```bash
yarn add scoped-css-loader --dev
```

and in your webpack.config.js

```json
{
"test": /\.(sc|c|sa)ss$/,
"use": [
{
"loader": "style-loader"
},
{
"loader": "css-loader",
"options": {
"sourceMap": true,
"importLoaders": 2
}
},
// You have to put in after `css-loader` and before any `pre-precessing loader`
{ "loader": "scoped-css-loader" },
{
"loader": "sass-loader"
}
]
}
```

[reactscopedcss]: https://github.com/gaoxiaoliangz/react-scoped-css