npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-elementui-demand

v1.1.4

Published

Element UI 按需加载组件时使用 scss 以能直接修改主题色

Downloads

11

Readme

babel-plugin-elementui-demand

NPM version

用于 Element 按需引入组件后引入对应的样式。
使直接修改 Element 里定义的主题 scss 变量后能直接在开发模式直接生效。

安装

npm i babel-plugin-elementui-demand -D

使用

通过 .babelrcbabel.config.js 或者 babel-loader 配置

例子

/babel.config.js

module.exports = {
  "plugins": [
    [
      "elementui-demand",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk",
        "ext": ".scss", // 此处指明加载的样式文件后缀为 scss
        "isElementUI": true // 指明为加载 element-ui 的样式
      }
    ]
  ]
}

/vue.config.js

module.exports = {
    css: {
        loaderOptions: {
            scss: {
                // 加载 scss 文件前会引入的 scss 文件(此文件不要使用样式,仅用于存储变量及其他不会生成 css 文件的内容)
                // (此处就是用于修改 element-ui 的样式变量。( src/assets 下新建一个 element-variables.scss 文件)
                // 文件内容可参见:https://github.com/ElementUI/theme-chalk/blob/master/src/common/var.scss
                prependData: `@import "~@/assets/element-variables.scss";`
            }
        }
    }
}

/src/assets/element-variables.scss

// 改变变量后立即生效

/* 改变主题色变量 */
$--color-primary: #f00;

/src/main.js

// 将要使用的组件,增加到 main.js 或者其他地方

import { Button } from 'element-ui'

Vue.use(Button)

以下为原插件内容

例子

插件会将下面的

import { Button } from 'components'

转换为

var button = require('components/lib/button')
require('components/lib/button/style.css')

styleLibraryName 例子

插件会将下面的

import Components from 'components'
import { Button } from 'components'

转换为

require('components/lib/styleLibraryName/index.css')
var button = require('components/lib/styleLibraryName/button.css')

使用

通过 .babelrc 或者 babel-loader 配置

{
  "plugins": [["component", options]]
}

多模块

{
  "plugins": [xxx,
    ["component", {
      libraryName: "antd",
      style: true,
    }, "antd"],
    ["component", {
      libraryName: "test-module",
      style: true,
    }, "test-module"]
  ]
}

组件目录结构

- lib // 'libDir'
  - index.js // or custom 'root' relative path
  - style.css // or custom 'style' relative path
  - componentA
    - index.js
    - style.css
  - componentB
    - index.js
    - style.css

主题库目录结构

- lib
  - theme-default // 'styleLibraryName'
    - base.css // required
    - index.css // required
    - componentA.css
    - componentB.css
  - theme-material
    - ...
  - componentA
    - index.js
  - componentB
    - index.js

或者

- lib
  - theme-custom // 'styleLibrary.name'
    - base.css // if styleLibrary.base true
    - index.css // required
    - componentA.css // default 
    - componentB.css
  - theme-material
    - componentA
      -index.css  // styleLibrary.path  [module]/index.css
    - componentB
      -index.css
  - componentA
    - index.js
  - componentB
    - index.js

选项

  • ["component"]: 导入 js 的模块
  • ["component", { "libraryName": "component" }]: 模块名称
  • ["component", { "styleLibraryName": "theme_package" }]: 样式模块名称
  • ["component", { "styleLibraryName": "~independent_theme_package" }]: 导入独立的主题包
  • ["component", { "styleLibrary": {} }]: 导入具有更多配置的独立主题包
    styleLibrary: {
      "name": "xxx", // 与 styleLibraryName 相同
      "base": true,  // 如果主题包中有 base.css 文件
      "path": "[module]/index.css",  // the style path. e.g. module Alert =>  alert/index.css
      "mixin": true  // 如果主题包中找不到 css 文件,则使用 [libraryName] 的 css 文件
    }
  • ["component", { "style": true }]: 从 'style.css' 中导入 js 和 css
  • ["component", { "style": cssFilePath }]: 从文件路径(filePath)导入 style css
  • ["component", { "libDir": "lib" }]: lib 目录
  • ["component", { "root": "index" }]: 主文件目录
  • ["component", { "camel2Dash": false }]: 是否将名称解析为破折号模式,默认为 true