1.1.1 • Published 5 years ago

js-inline-css-webpack-plugin v1.1.1

Weekly downloads
46
License
MIT
Repository
github
Last release
5 years ago

js-inline-css-webpack-plugin

MIT Licence PRs Welcome Total downloads npm version

This plugin inspired by html-inline-css-webpack-plugin but instead of injecting directly to the html, it injects css into js (useful for libraries and testing purposes) like:

document.body.appendChild(nodeWithStyles);

Require mini-css-extract-plugin.

Install

NPM

npm i js-inline-css-webpack-plugin -D

Yarn

yarn add js-inline-css-webpack-plugin -D

Minimal example

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const JsInlineCssWebpackPlugin = require("js-inline-css-webpack-plugin").default;

module.exports = {
  plugins: [
    new MiniCssExtractPlugin({
      filename: "[name].css",
      chunkFilename: "[id].css"
    }),
    new HtmlWebpackPlugin(),
    new JsInlineCssWebpackPlugin(),
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader"
        ]
      }
    ]
  }
}

Config

interface Config {
  filter?(fileName: string): boolean
  leaveCSSFile?: boolean
}

filter(optional)

filter?(fileName: string): boolean

Return true to make current file internal, otherwise ignore current file.

example
...
  new JsInlineCssWebpackPlugin({
    filter(fileName) {
      return fileName.includes('main');
    },
  }),
...

leaveCSSFile(optional)

if true, it will leave CSS files where they are when inlining

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago