All Projects → rsuite → webpack-multiple-themes-compile

rsuite / webpack-multiple-themes-compile

Licence: MIT license
Overwrite webpack config to output multiple themes css.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to webpack-multiple-themes-compile

Spicetify Themes
A community-driven collection of themes for customizing Spotify through Spicetify (https://github.com/khanhas/spicetify-cli)
Stars: ✭ 3,034 (+18862.5%)
Mutual labels:  themes-css
Themes
Themes I either made or adapted for Alfred, Connected Text, Folding Text, Golden Dict, Obsidian, OmniOutliner, Outlinely, Scapple, Scrivener, Tinderbox, and Ulysses.
Stars: ✭ 45 (+181.25%)
Mutual labels:  themes-css
DisplayStructureElements
Display the structure of the elements in web template.
Stars: ✭ 17 (+6.25%)
Mutual labels:  themes-css

webpack multiple themes compile

Build Status Coverage Status Packagist webpack

English | 中文版

This library use to overwrite webpack config to output multiple themes in once compile.

If you used webpack version lower than 3 , please use webpack-multiple-themes-compile@1.

If you used Webpack 4, please use [email protected].

Install

npm i webpack-multiple-themes-compile webpack-merge

Example

Origin webpack.config.js

module.exports = {
  output: {
    path: outPutPath,
    filename: '[name].js',
    chunkFilename: '[name].js',
  },
  // There is another options.
};

Change the webpack.config.js file.

+ const merge = require('webpack-merge');
+ const multipleThemesCompile = require('webpack-multiple-themes-compile');
- module.exports = {
+ const webpackConfigs = {
  output: {
    path: outPutPath,
    filename: '[name].js',
    chunkFilename: '[name].js'
  }
  // There is another options.
};

+ module.exports = merge(
+   webpackConfigs,
+   multipleThemesCompile({
+     themesConfig: {
+       green: {
+         color: '#008000'
+       },
+       yellow: {
+         import: [
+           '~thirdpartylibrary/styles/yellow.less'
+         ],
+         color: '#ffff00'
+       }
+     },
+     lessContent: 'body{color:@color}'
+   })
+ );

Output directory tree.

.
├── theme-green.css
├── theme-yellow.css
└── themes.js

API

/**
 * @param configs
 */
multipleThemesCompile(configs);

configs

Property Type(Default) Description
styleLoaders Array [{ loader: 'css-loader' }, { loader: 'less-loader' }] The loaders to compile less.Details in webpack homepage
themesConfig* Object Theme configuration. key for the file name of the generated css, value for the object .The object's key, the value is the name of the variable to be overwritten, and the value of the variable.
lessContent String | (themeName:string,config:Object)=> String @import "../index"; The content of cache less.
preHeader String // Generate by Script. The header of generate files.
cacheDir String ./src/less/themes Cache Directory.
cwd String __dirname Relative output directory.
outputName String theme-[name].css Finally output pathname.Options similar to the same options in webpackOptions.output.
publicPath String../../ publicPath configuration for mini-css-extract-plugin

Notice

If you used html-webpack-plugin,maybe you need added this config:

 new HtmlwebpackPlugin({
   filename: 'index.html',
   template: 'src/index.html',
   inject: 'body',
   // exclude themes.js
+  excludeChunks: Object.keys(themesConfig)
 })
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].