ice/packages/webpack-modify
ClarkXia fbeaf932cb
chore: update versions (#6509)
2023-09-14 10:58:37 +08:00
..
src chore: add tsconfig for @ice/webpack-modify (#546) 2022-11-15 10:32:43 +08:00
tests feat: support several APIs to modify webpack (#532) 2022-11-15 10:32:43 +08:00
CHANGELOG.md chore: update versions (#6509) 2023-09-14 10:58:37 +08:00
README.md feat: support several APIs to modify webpack (#532) 2022-11-15 10:32:43 +08:00
package.json chore: update versions (#6509) 2023-09-14 10:58:37 +08:00
tsconfig.json chore: add tsconfig for @ice/webpack-modify (#546) 2022-11-15 10:32:43 +08:00

README.md

@ice/webpack-modify

This package providers several APIs to simplify the modification of webpack configurations.

Usage

import { removeLoader, modifyLoader, addLoader, removePlugin } from '@ice/webpack-modify';

let modifiedConfig = {};

const webpackConfig = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [{ loader: "style-loader" }, { loader: "sass-loader" }],
      },
    ],
  },
};

// remove loader
modifiedConfig = removeLoader(webpackConfig, {
  rule: 'css',
  loader: 'style-loader',
});
// modify loader
modifiedConfig = modifyLoader(webpackConfig, {
  rule: 'css',
  loader: 'style-loader',
  options: () => ({}),
});
// add loader
modifiedConfig = addLoader(webpackConfig, {
  rule: 'css',
  before: 'style-loader'
});
modifiedConfig = addLoader(webpackConfig, {
  rule: 'css',
  after: 'style-loader'
});
// modify webpack rule options
modifiedConfig = modifyRule(webpackConfig, {
  rule: 'css',
  options: () => {
    return [
      {
        loader: 'css-loader',
        options: () => ([]),
      },
    ]
  },
})
// remove plugin
modifiedConfig = removePlugin(webpackConfig, {
  pluginName: 'AssetsManifestPlugin',
});