Skip to content

Jinx-1120/webpack-gen-assets-plugin

Repository files navigation

webpack-gen-assets-plugin

Install

pnpm add webpack-gen-assets-plugin -D

Usage

// webpack.conf.js
const WebpackGenAssetsPlugin = require('webpack-gen-assets-plugin').default;

module.exports = {
  plugins: [
    new WebpackGenAssetsPlugin()
  ]
}

Options

interface IOptions {
  /**
   * Resource matching rules
   * default: /\.(png|jpe?g|gif|webp|svg)$/i
   */
  include?: RegExp;
  /**
   * Resource directory
   * default: src/assets
   */
  assetsDir?: string;
  /**
   * Output path
   *default: src/assets/assets.ts
   */
  outputFilePath?: string;
}

Demo

./src/assets
├── farm
│   ├── add-steps.png
│   ├── add.png
├── item_selected.jpeg
├── pet
│   ├── icon-bg.jpg
export { default as ImagesAddSteps } from './farm/add-steps.png';
export { default as ImagesAdd } from './farm/add.png';
export { default as ImagesItem_selected } from './item_selected.jpeg';
export { default as ImagesPetIconBg } from './pet/icon-bg.jpg';