2.0.0 • Published 3 years ago

css-async-process-webpack-plugin v2.0.0

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

css-async-process-webpack-plugin

NPM version Build Status

A webpack plugin for change the insert position of async loading style which is generated by mini-css-extract-plugin

Install

npm i -D css-async-process-webpack-plugin

NOTE: Should add after mini-css-extract-plugin

Usage

In your webpack configuration (webpack.config.js):

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssAsyncProcessWebpackPlugin = require('css-async-process-webpack-plugin');

module.exports = {
    //...
    plugins: [
        new MiniCssExtractPlugin({
            filename: "[name].[hash:8].css",
            chunkFilename: "[id].[hash:8].css"
        }),
        new CssAsyncProcessWebpackPlugin(),
    ]
}

Options

process

Function.
Change the async loading style insert before document.getElementById("less:theme:color") by default. You can change the logic by setting process.

new CssAsyncProcessWebpackPlugin({
    process: (source) => {
        return source.replace(/head.appendChild\(linkTag\)/, 'head.insertBefore(linkTag, document.getElementById("less:theme:color"))');
    }
}),