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

element-theme-js

v1.0.1

Published

Theme generator cli tool for Element UI using SCSS + JS

Downloads

4

Readme

element-theme-js

Customized for a specific Vue project - I don't recommend using this, but if you must, I hope the examples make some sense. Good luck 🙏

Installation

npm i element-theme-js --save-dev

Description

For general description of how the original works, see element-theme.

The reason for this fork was to modify the gulp-pipeline it uses for compiling Element UI's theme on the fly alongside a global stylesheet written in JS.

Essentially, it combines SCSS with JS object(s) into a combined stylesheet that can be used in the element-theme template you generate. Here's the general flow:

  1. Generate an Element UI SCSS template-stylesheet (made with et --init [file path])

  2. Create a JS file with your global styles in nested objects (examples below on what this might look like)

  3. Put your JS variables (that will be turned to SCSS variables) into your generated template-stylesheet

  4. Create a file called element-theme.config.js in your root. This is where element-theme options will go

  5. Specify your files in the element-theme.config.js (as seen in the config at the bottom) in their respective fields

  6. Provide element-theme.config.js with a "config" path, which is where you will expect a newly-concatenated file named _combined.scss (the compilation process will use this sheet to create CSS files for your Element UI components)

  7. Provide element-theme.config.js with an "out" path, which is where all your newly generated CSS files will be generated and accessed for the components (specified in your babel config)

  8. Specify in your babel.config.js where your newly generated CSS files are.

This allows us to modify app styles in one place and those styles are accessible in both SCSS and JS from anywhere in the app.

Examples

We provide a JS file of styles that look something like this:

const defaultTheme = {
  colors: {
    primary: '#162752',
    secondary: '#7F8FA4',
    warning: '#E6A23C',
    success: '#0F9D58',
    danger: '#DB4437',
    info: '#909399',
    wht: '#FFFFFF',
    blk: '#000000',
  },
  breakpoints: {
    sm: '768px',
    md: '992px',
    lg: '1200px',
    xl: '1920px',
  },
  fonts: {
    primary: '\'Futura-PT\'',
  },
};

module.exports = defaultTheme;

Then we get SCSS variables that look like this:

$colors: (
  primary: #1e3570,
  secondary: #7F8FA4,
  warning: #E6A23C,
  success: #0F9D58,
  danger: #DB4437,
  info: #909399,
  wht: #FFFFFF,
  blk: #000000,
);
$breakpoints: (
  sm: 768px,
  md: 992px,
  lg: 1200px,
  xl: 1920px,
);
$fonts: (
  futura: "Futura-PT",
);

These can be used in your source element-theme SCSS file like so:

/* Color
-------------------------- */
$--color-primary: map-get($colors, primary) !default;
$--color-success: map-get($colors, success) !default;
$--color-warning: map-get($colors, warning) !default;
$--color-danger: map-get($colors, danger) !default;
$--color-info: map-get($colors, info) !default;
$--color-white: map-get($colors, wht) !default;
$--color-black: map-get($colors, blk) !default;

/* Break-point
--------------------------*/
$--sm: map-get($breakpoints, sm) !default;
$--md: map-get($breakpoints, md) !default;
$--lg: map-get($breakpoints, lg) !default;
$--xl: map-get($breakpoints, xl) !default;

Don't expect much from the JS-to-SCSS conversion going on here, it's extremely rudimentary, and I woudln't expect it to hold up with more complex tooling

Config

Here are some (highly specific for my project) examples of what your config files may look like:

element-theme.config.js

The configuration for this should look something like this in element-theme.config.js:

// element-theme.config.js
module.exports = {
    // Optional
    browsers: ["ie > 9", "last 2 versions"],
    components: ["button", "input"],
    minimize: false,
    
    // Required ()
    out: "./<path-to-styles>/element-ui/css",
    config: "./<path-to-styles>/element-ui/scss/generated", // where `_combined.scss` will go
    sassVariables: "./<path-to-styles>/element-ui/scss/_element-ui.scss",
    jsVariables: "./<path-to-styles>/theme/index.js",
    
    // Dont change
    theme: "element-theme-chalk"
}

babel.config.js

Your babel config should reflect a change in path for where your app can access your custom Element UI theme:

plugins: [
    [
      'component',
      {
        libraryName: 'element-ui',
        
        // Path specified in element-theme.config.js
        styleLibraryName: '~src/assets/styles/vendor/element-ui/css',
      },
    ],
  ],

Misc

Some additional reading or additions that can be made to make better use of this workflow:

License

MIT