0.16.2 • Published 1 month ago

css-mqpacker-webpack-plugin v0.16.2

Weekly downloads
97
License
MIT
Repository
github
Last release
1 month ago

css-mqpacker-webpack-plugin

npm version

The Webpack plugin for pack same CSS media query rules into one using PostCSS.

node-css-mqpacker

Before:

.foo {
  width: 240px;
}

@media (max-width: 768px) {
  .foo {
    width: 576px;
  }
}

.bar {
  width: 160px;
}

@media (max-width: 768px) {
  .bar {
    width: 384px;
  }
}

After:

.foo {
  width: 240px;
}

.bar {
  width: 160px;
}

@media (max-width: 768px) {
  .foo {
    width: 576px;
  }

  .bar {
    width: 384px;
  }
}

Install

npm i css-mqpacker-webpack-plugin --save-dev
# or
yarn add css-mqpacker-webpack-plugin -D

Example

webpack.config.js

const CssMqpackerPlugin = require('css-mqpacker-webpack-plugin');

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new CssMqpackerPlugin(),
    ],
  },
};

Options

test

Type: String|RegExp|Array<String|RegExp> Default: /\.css(\?.*)?$/i

Test to match files against.

webpack.config.js

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new CssMqpackerPlugin({
        test: /\.foo\.css$/i,
      }),
    ],
  },
};

include

Type: String|RegExp|Array<String|RegExp> Default: undefined

Files to include.

webpack.config.js

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new CssMqpackerPlugin({
        include: /\/includes/,
      }),
    ],
  },
};

exclude

Type: String|RegExp|Array<String|RegExp> Default: undefined

Files to exclude.

webpack.config.js

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new CssMqpackerPlugin({
        exclude: /\/excludes/,
      }),
    ],
  },
};

sort

Type: Boolean|Function Default: false

By default, CSS MQPacker pack and order media queries as they are defined (the “first win” algorithm). If you want to sort media queries automatically, pass sort: true.

webpack.config.js

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new CssMqpackerPlugin({
        sort: true,
      }),
    ],
  },
};

License

MIT

0.16.2

1 month ago

0.16.0

1 month ago

0.16.1

1 month ago

0.15.0

2 months ago

0.13.0

6 months ago

0.14.0

6 months ago

0.12.8

1 year ago

0.12.9

1 year ago

0.12.7

1 year ago

0.12.5

1 year ago

0.12.6

1 year ago

0.12.4

2 years ago

0.12.2

2 years ago

0.12.3

2 years ago

0.11.0

3 years ago

0.12.0

3 years ago

0.12.1

3 years ago

0.10.0-rc.0

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.2

3 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago