Class DetachExcessStyles

DetachExcessStyles 压缩 UNIAPP 样式的 Webpack 插件

Hierarchy

  • DetachExcessStyles

Constructors

  • 创建DetachExcessStyles实例

    Example

       const path = require('path');
    const { DetachExcessStyles } = require('@itriton/webpack');
    const env = process.env.NODE_ENV === 'development' ? 'dev' : 'build';
    const mainStylePath = path.join(__dirname, `unpackage/dist/${env}/mp-weixin/common/main.wxss`);
    const baseDir = path.join(__dirname, `unpackage/dist/${env}/mp-weixin`);
    let plugins = [];
    if (process.env.UNI_PLATFORM === 'mp-weixin') {
    plugins.push(
    new DetachExcessStyles({
    mainStylePath,
    baseDir,
    startWithDir: ['pages'], // 支持多个起始目录
    endWithFile: '.wxss', // 可选,默认为 '.wxss'
    fullMatch: false, // 可选,默认为 false,设置为 true 时全匹配起始目录文件夹名称
    debug: true // 可选,默认为 false
    })
    )
    }

    module.exports = {
    configureWebpack: {
    plugins
    }
    }

    Parameters

    Returns DetachExcessStyles

Properties

baseDir: string
debug: boolean
endWithFile: string
fullMatch: boolean
mainStylePath: string
startWithDir: string[]

Methods

  • Parameters

    • compiler: any

    Returns void

  • Format CSS content.

    Parameters

    • css: string

      The CSS content to format.

    Returns string

    • The formatted CSS content.
  • Get all .xxss files in the specified directory.

    Parameters

    • dir: string

      The directory to search.

    • Optional further: boolean = false

      Whether to continue searching deeper directories.

    Returns string[]

    • An array of file paths.
  • Remove global styles from the content.

    Parameters

    • content: string

      The content to process.

    • mainStyleContent: string

      The global styles to remove.

    Returns string

    • The processed content.

Generated using TypeDoc