3.0.0 • Published 3 years ago

webpack-multiple-themes-compile v3.0.0

Weekly downloads
85
License
MIT
Repository
github
Last release
3 years ago

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 webpack-multiple-themes-compile@2.x.

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

PropertyType(Default)Description
styleLoadersArray [{ loader: 'css-loader' }, { loader: 'less-loader' }]The loaders to compile less.Details in webpack homepage
themesConfig*ObjectTheme 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.
lessContentString | (themeName:string,config:Object)=> String @import "../index";The content of cache less.
preHeaderString // Generate by Script.The header of generate files.
cacheDirString ./src/less/themesCache Directory.
cwdString __dirnameRelative output directory.
outputNameString theme-[name].cssFinally output pathname.Options similar to the same options in webpackOptions.output.
publicPathString../../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)
 })
3.0.0

3 years ago

2.0.0

4 years ago

2.0.0-beta.5

4 years ago

2.0.0-beta.4

4 years ago

2.0.0-beta.3

4 years ago

2.0.0-beta.2

4 years ago

1.1.1

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago