Git Product home page Git Product logo

webpack-theme-color-replacer's Introduction

This plugin can extract theme color styles from all the outputed css files (such as element-ui theme colors), and make a 'theme-colors.css' file which only contains color styles. At runtime in your web page, the client part will help you to download this css file, and then replace the colors into new customized colors dynamicly.

This is a sample: http://test.hz300.com/webpack4/themeColor.html

Implementation (Chinese): https://segmentfault.com/a/1190000016061608

1.Install

npm i -D webpack-theme-color-replacer

2.Cofig for webpack

const ThemeColorReplacer = require('webpack-theme-color-replacer')

module.exports = {
    .....
    plugins: [
        new ThemeColorReplacer({
            fileName: 'css/theme-colors.css', // output css file name
            matchColors: [
                ...ThemeColorReplacer.getElementUISeries('#409EFF'), // primary color of element-ui
                '#0cdd3a',  //other custom color
            ],
            cssPrefix: true  // add a prefix to each class name. This can raise css priority.
        })
    ],
}

You can view this sample: https://github.com/hzsrc/vue-element-ui-scaffold-webpack4/blob/master/build/webpack.base.conf.js

3.Usage in your web page

    import replacer from 'webpack-theme-color-replacer/client';

    export default {
        data() {
            return {
                mainColor: '#409EFF',
                oldColor: '#409EFF',  // primary color of element-ui
            };
        },
        methods: {
            changeColor(newVal) {
                var options = {
                    primary: { // primary color
                        oldColor: this.oldColor,
                        newColor: newVal,
                    },
                    cssUrl: 'css/theme-colors.css',
                    others: { //custom colors
                        oldColors: ['#0cdd3a', '#c655dd'],
                        newColors: ['#ff0000', '#ffff00'],
                    }
                };
                replacer.elementUI.changeColor(options);

                this.oldColor = newVal
            }
        },
    }

You can view this sample: https://github.com/hzsrc/vue-element-ui-scaffold-webpack4/blob/master/src/modules/themeColor/changeColor.vue

webpack-theme-color-replacer's People

Contributors

hzsrc avatar

Watchers

FantasyNJ avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.