Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

File system methods bundled in a webpack plugin package

License

Notifications You must be signed in to change notification settings

chronoDave/fs-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fs-webpack-plugin

Native file system methods bundled in a webpack plugin package

Why?

Both copy-webpack-plugin and clean-webpack-plugin recreate existing native functionality so why not use those?

Note: clean can be replaced with Webpack's output.clean

Usage

webpack.config.js

const FsWebpackPlugin = require('fs-webpack-plugin');

module.exports = {
  plugins: [
    new FsWebpackPlugin([{
      // Delete folder `build` recursively
      type: 'delete',
      files: ['build'] // process.cwd() + build
    }, {
      // Delete file `build/index.test.js`
      type: 'delete',
      files: ['build/index.test.js'] // process.cwd() + build/index.test.js
    }, {
      // Delete file `build/index.test.js`,
      type: 'delete',
      files: ['index.test.js'],
      root: path.resolve(__dirname, 'build') // Must be absolute
    }, {
      // Delete file `build/index.test.js` and folder `build/test`
      type: 'delete',
      files: [
        'index.test.js',
        'test'
      ],
      root: path.resolve(__dirname, 'build')
    }, {
      // Copy folder `assets` recursively to `build/assets`
      type: 'copy',
      files: [{ from: 'assets', to: 'build' }]
    }, {
      // Copy file `assets/image.png` to `build/image.png`
      type: 'copy',
      files: [{ from: 'assets/image.png', to: 'build' }]
    }])
  ]
}

Options

new FsWebpackPlugin(actions, options)

  • actions (Action[]) - Array of action objects
  • options.verbose (Boolean) - Enable logging (default true)
  • options.strict (Boolean) - Should throw errors instead of logging them (default false)
  • options.dry (Boolean) - Enable dry run (default false). Please note that options.dry will not output to console if options.verbose is false

Action

  • type (String) - Action type, must be one of copy, delete
  • files (String[]|{ from: String, to: String}[] - Files or directorys to delete. copy only accepts { from, to }. If paths are relative, uses root
  • root (String) - Absolute path used by files, defaults to process.cwd()
  • hooks (String[]) - Webpack hooks to run action on, defaults to ['beforeRun']

About

File system methods bundled in a webpack plugin package

Topics

Resources

License

Stars

Watchers

Forks