Git Product home page Git Product logo

clean-webpack-plugin's Introduction

Clean plugin for webpack

npm MIT License Linux Build Status Windows Build Status Coveralls Status

A webpack plugin to remove/clean your build folder(s).

NOTE: Node v10+ and webpack v4+ are supported and tested.

About

By default, this plugin will remove all files inside webpack's output.path directory, as well as all unused webpack assets after every successful rebuild.

Coming from v1? Please read about additional v2 information.

Installation

npm install --save-dev clean-webpack-plugin

Usage

const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const webpackConfig = {
    plugins: [
        /**
         * All files inside webpack's output.path directory will be removed once, but the
         * directory itself will not be. If using webpack 4+'s default configuration,
         * everything under <PROJECT_DIR>/dist/ will be removed.
         * Use cleanOnceBeforeBuildPatterns to override this behavior.
         *
         * During rebuilds, all webpack assets that are not used anymore
         * will be removed automatically.
         *
         * See `Options and Defaults` for information
         */
        new CleanWebpackPlugin(),
    ],
};

module.exports = webpackConfig;

Options and Defaults (Optional)

new CleanWebpackPlugin({
    // Simulate the removal of files
    //
    // default: false
    dry: true,

    // Write Logs to Console
    // (Always enabled when dry is true)
    //
    // default: false
    verbose: true,

    // Automatically remove all unused webpack assets on rebuild
    //
    // default: true
    cleanStaleWebpackAssets: false,

    // Do not allow removal of current webpack assets
    //
    // default: true
    protectWebpackAssets: false,

    // **WARNING**
    //
    // Notes for the below options:
    //
    // They are unsafe...so test initially with dry: true.
    //
    // Relative to webpack's output.path directory.
    // If outside of webpack's output.path directory,
    //    use full path. path.join(process.cwd(), 'build/**/*')
    //
    // These options extend del's pattern matching API.
    // See https://github.com/sindresorhus/del#patterns
    //    for pattern matching documentation

    // Removes files once prior to Webpack compilation
    //   Not included in rebuilds (watch mode)
    //
    // Use !negative patterns to exclude files
    //
    // default: ['**/*']
    cleanOnceBeforeBuildPatterns: [
        '**/*',
        '!static-files*',
        '!directoryToExclude/**',
    ],
    cleanOnceBeforeBuildPatterns: [], // disables cleanOnceBeforeBuildPatterns

    // Removes files after every build (including watch mode) that match this pattern.
    // Used for files that are not created directly by Webpack.
    //
    // Use !negative patterns to exclude files
    //
    // default: []
    cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],

    // Allow clean patterns outside of process.cwd()
    //
    // requires dry option to be explicitly set
    //
    // default: false
    dangerouslyAllowCleanPatternsOutsideProject: true,
});

Example Webpack Config

This is a modified version of WebPack's Plugin documentation that includes the Clean Plugin.

const { CleanWebpackPlugin } = require('clean-webpack-plugin'); // installed via npm
const HtmlWebpackPlugin = require('html-webpack-plugin'); // installed via npm
const webpack = require('webpack'); // to access built-in plugins
const path = require('path');

module.exports = {
    entry: './path/to/my/entry/file.js',
    output: {
        /**
         * With zero configuration,
         *   clean-webpack-plugin will remove files inside the directory below
         */
        path: path.resolve(process.cwd(), 'dist'),
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                loader: 'babel-loader',
            },
        ],
    },
    plugins: [
        new webpack.ProgressPlugin(),
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({ template: './src/index.html' }),
    ],
};

clean-webpack-plugin's People

Contributors

alextreppass avatar artfuldev avatar aulisius avatar bebraw avatar chrisblossom avatar cordial-rgee avatar endiliey avatar gajus avatar johnagan avatar kevinlaw91 avatar meikatz avatar mhuggins avatar mkungla avatar neves avatar serzn1 avatar strootje avatar tillsanders avatar tuures avatar tylerhou avatar wujunchuan avatar zdanowiczkonrad avatar zmj97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clean-webpack-plugin's Issues

Is it possible to clean `output.path` ?

Hi! I'm generating output.path dynamically and did not find a way to clean it without saving the path into additional variable. Is it possible?
Something like:

module.exports = {
    entry: './src',
    output: {
        path: path.join(path.resolve('dist'), vendor),
        filename: 'bundle.js',
    },
 plugins: [
        new CleanWebpackPlugin(['.'], {
            root: 'dist/[output.path]' // use `output.path` from config
        }),
}

Thanks!

Error: EPERM: operation not permitted, mkdir 'c:\***\webpack3-demo\dist'

'mkdir' command in windows

c:\Project\wamp\www\webpack3-demo  ([email protected])
Ξ» npm run build
> [email protected] build c:\Project\wamp\www\webpack3-demo
> webpack

clean-webpack-plugin: C:\Project\wamp\www\webpack3-demo\dist has been removed.
Error: EPERM: operation not permitted, mkdir 'c:\Project\wamp\www\webpack3-demo\dist'

I think:
wrong: mkdir 'c:\Project\wamp\www\webpack3-demo\dist'
right: mkdir c:\Project\wamp\www\webpack3-demo\dist

With 'watch' option enabled ALL chunks are removed after each new compilation

I wanted to try this new watch option, but it doesn't act as I expected.

When using webpack --watch with this option enabled ALL of the previously created chunks are removed after new compilation.

I am using CommonsChunkPlugin in order to apply long-term cache support. So when I use webpack --watch not all of my chunks are updated, but only those, which were affected by the last changes.

So I expected for clean-webpack-plugin to remove only obsolete chunks.

This would be very nice, cause I will be able to use webpack watch mode along with karma watch mode.

The problem is that I use [name].[chunkhash].js pattern for my app.js chunk (and others). So at the moment it is not very efficiently to use karma watch mode along with webpack watch mode, karma will include all my chunks (old and new), because it uses app*.js pattern for files to include in it's config.

I suppose this issue is related to this PR

work in production only

Hi how i can make clean run in production only
below is my package json and webpack config file

`var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var webpack = require('webpack');
var path = require('path');

var isProd = process.env.NODE_ENV === 'production'
var cssDev = ['style-loader','css-loader','sass-loader']
var cssProd = ExtractTextPlugin.extract({
fallback:'style-loader',
use: ['css-loader', 'sass-loader'],
publicPath: './dist'
})
var cssConfig = isProd ? cssProd : cssDev

module.exports = {
entry: './src/app.js',
output: {
path: path.resolve( __dirname , './dist'),
filename: '[name].bundle.js'
},
module: {
rules: [
{
test: /.scss$/,
use: cssConfig
},
{ test: /.js$/, exclude: /node_modules/, loader: "babel-loader" },
{ test: /.pug$/, loaders: ['html-loader', 'pug-html-loader'] },
{ test: /.(jpe?g|png|gif|svg)$/i,
use:['file-loader?name=images/[name].[ext]','image-webpack-loader'] }
//file-loader?name=[name].[ext]&outputPath=images/&publicPath=images/
]
},
devtool: 'inline-source-map',
devServer:{
contentBase: path.join(__dirname, "dist"),
compress: true,
hot:true,
port: 9000,
stats: "errors-only",
open: true
},
plugins: [
// new CleanWebpackPlugin(['dist/.','dist//.','dist//**/.']),
new CleanWebpackPlugin(['dist/.']),
new HtmlWebpackPlugin({
title: 'Webpack Project Demo',
// minify: {
// collapseWhitespace:true
// },
hash: true,
template: './src/index.pug', // Load a custom template (lodash by default see the FAQ for details)
}),
new ExtractTextPlugin({
filename:'app.css',
disable: !isProd ,
allChunks:true
}),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
]
}`

my json is
{ "name": "bcreation", "version": "1.0.0", "description": "Building Wordpress site using Bedrock", "main": "index.js", "scripts": { "dev": "webpack-dev-server", "prod": "cross-env NODE_ENV=production webpack -p" }, "repository": { "type": "git", "url": "git+ssh://[email protected]/rashanoureldin/bcreations.git" }, "author": "Rasha Noureldin", "license": "ISC", "homepage": "https://bitbucket.org/rashanoureldin/bcreations#readme", "devDependencies": { "babel": "^6.23.0", "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "bootstrap-loader": "^2.2.0", "bootstrap-sass": "^3.3.7", "clean-webpack-plugin": "^0.1.17", "cross-env": "^5.1.1", "css-loader": "^0.28.7", "extract-text-webpack-plugin": "^3.0.2", "file-loader": "^1.1.5", "html-loader": "^0.5.1", "html-webpack-plugin": "^2.30.1", "image-webpack-loader": "^3.4.2", "imports-loader": "^0.7.1", "jquery": "^3.2.1", "node-sass": "^4.7.2", "pug": "^2.0.0-rc.4", "pug-html-loader": "^1.1.5", "react": "^16.1.1", "react-dom": "^16.1.1", "resolve-url-loader": "^2.2.0", "rimraf": "^2.6.2", "sass-loader": "^6.0.6", "style-loader": "^0.19.0", "url-loader": "^0.6.2", "webpack": "^3.8.1", "webpack-dev-server": "^2.9.4" } }

Possible to prevent downtime while deploying?

When deploying, my server pulls from the remote, and compiles a fresh build. I am using clean-webpack-plugin to clean up old build.

However, clean-webpack-plugin cleans the previous build at the start of the new build, and until the build is done, none of the assets will be accessible. Is it possible to delay clean up to prevent this downtime?

Also related is erikras/react-redux-universal-hot-example#1093

Plugin doesn't seem to run.. are there further install steps?

Hi,
I have npm installed, and instantiated Clean in my config, and my 'compile' task runs without errors, but I don't see stale files being deleted... Any tips?

Config snippet:

webpackConfig.plugins.push(
  new Clean(['dist']),
  new ExtractTextPlugin('[name].[contenthash].css', {allChunks: true})
);

Error: ENOTEMPTY: directory not empty

Pretty regularly, I see the following error when starting webpack. My dist folder is typically a few folders deep. I usually just run webpack again and it works fine, but I thought I'd log an issue in case anyone else is seeing this as well:

C:\path\to\project\node_modules\webpack-dev-server\bin\webpack-dev-server.js:345
                throw e;
                ^

Error: ENOTEMPTY: directory not empty, rmdir 'C:\path\to\project\dist\Views'
    at Object.fs.rmdirSync (fs.js:856:18)
    at rmkidsSync (C:\path\to\project\node_modules\clean-webpack-plugin\node_modules\rimraf\rimraf.js:342:11)
    at rmdirSync (C:\path\to\project\node_modules\clean-webpack-plugin\node_modules\rimraf\rimraf.js:332:7)
    at rimrafSync (C:\path\to\project\node_modules\clean-webpack-plugin\node_modules\rimraf\rimraf.js:303:9)
    at C:\path\to\project\node_modules\clean-webpack-plugin\node_modules\rimraf\rimraf.js:340:5
    at Array.forEach (native)
    at rmkidsSync (C:\path\to\project\node_modules\clean-webpack-plugin\node_modules\rimraf\rimraf.js:339:26)
    at rmdirSync (C:\path\to\project\node_modules\clean-webpack-plugin\node_modules\rimraf\rimraf.js:332:7)
    at Function.rimrafSync [as sync] (C:\path\to\project\node_modules\clean-webpack-plugin\node_modules\rimraf\rimraf.js:303:9)
    at C:\path\to\project\node_modules\clean-webpack-plugin\index.js:164:16
    at Array.forEach (native)
    at CleanWebpackPlugin.clean (C:\path\to\project\node_modules\clean-webpack-plugin\index.js:90:15)
    at CleanWebpackPlugin.apply (C:\path\to\project\node_modules\clean-webpack-plugin\index.js:191:20)
    at Compiler.apply (C:\path\to\project\node_modules\tapable\lib\Tapable.js:306:16)
    at webpack (C:\path\to\project\node_modules\webpack\lib\webpack.js:32:19)
    at startDevServer (C:\path\to\project\node_modules\webpack-dev-server\bin\webpack-dev-server.js:339:14)
    at C:\path\to\project\node_modules\webpack-dev-server\bin\webpack-dev-server.js:330:3
    at C:\path\to\project\node_modules\portfinder\lib\portfinder.js:160:14
    at C:\path\to\project\node_modules\portfinder\node_modules\async\lib\async.js:52:16
    at C:\path\to\project\node_modules\portfinder\node_modules\async\lib\async.js:269:32
    at C:\path\to\project\node_modules\portfinder\node_modules\async\lib\async.js:44:16
    at C:\path\to\project\node_modules\portfinder\lib\portfinder.js:122:16
error Command failed with exit code 1.

OS: Windows 10
clean-webpack-plugin version: 0.1.16
rimraf version: 2.5.4

Prevent auto run when call webpack()

It seems this plugin auto run when we call webpack(options).

How to to configure this plugin to not auto run ?

ex:

//This plugin auto run and the directory now clean after call webpack(). But I don't want it.
compiler = webpack(options);

//How to configure this plugin, so it run when compiler.run() called?
compiler.run()

the plugin run twice

clean-webpack-plugin: C:\Githome\fptigovuinodeweb\client**. has been removed.
clean-webpack-plugin: C:\Githome\fptigovuinodeweb\client**. has been removed.

any idea why?

My problem that it deletes js/css files which webpack is creating. So at the end I don't have css/js files in the project. Looks like it cleans files before the webpack run and after

Do not log to console if `--profile --json` is set?

Just noticed that if you use clean-webpack-plugin with the default settings while extracting stats out of webpack, it will still log to console. This leads to malformed stats JSON. Maybe it would be a good idea to disable logging in this case? Here's the full webpack command by the way: webpack --profile --json > stats.json".

Support to specify exclude files/directories

In my project I usually check in version control the /dist directory in order for it to be ready for deploy without the need for installing dependencies and running the build step. In that directory should also reside a config.js file with project configurations that varies from installation to installation. It would be nice to preserve that file between project rebuilds. Is there any support for this?

Thanks!

Add emitted flag checking, before directory removing

When error occur in webpack compilation and we're using NoErrorsPlugin(), there are no bundles emitted, but directory is removed. Maybe you can add any check of emitted to your plugin, so when no files are generated old ones still stay in place.

Webpack Watch Freezes Periodically After Running Plugin

I run webpack --watch with the clean Webpack plugin configured. Clean webpack plugin does what it's supposed to do most of the time, but every once in a while Webpack freezes and compilation / watch stops. The last outputted message in terminal is:

clean-webpack-plugin /c/myuser/project/build has been removed

When I check my folder, the contents have indeed been deleted. It seems like Webpack loses its place and watch freezes. Webpack watch is still running in terminal, but no more compilation takes place when I change any of my source files.

This only happens when I have clean webpack plugin running.

Has anyone else run into this issue? I am running Windows 10.

Clean only just before webpack output?

Would it be possible to make it clean only right before Webpack starts writing? That way, if the build fails before that point, the files are still there…

Add an option to run after instead of just before

It would be nice to clean up some build files as the very last step as well, not just wait to clean up until the next build is run. I think there should be a "after:true" option that tells the plugin to use one of the final webpack hooks. I assume there is a "build complete" hook or something like that.

Plugin does not clean output directory in watch mode

Steps to reproduce:

  1. Clone my repo here
  2. npm install
  3. Run webpack --watch in the project dir. The output is generated as expected:
ls -l dist
index.html  main.e4ff9438d89750f15374.js  runtime~main.297929bbe0221ed990a6.js
  1. Modify main.js and save. The output is rebuilt, with 4 files instead of 3:
ls -l dist
index.html                    main.e4ff9438d89750f15374.js
main.64d950fb1144a8614c58.js  runtime~main.297929bbe0221ed990a6.js

If you repeat step 4, you get 5 files, then 6...

Is there something wrong with my build? Isn't this a supported use case?

Win10 x64 - Dist does not get deleted - ENOENT

I am using webpack4 and clean-webpack-plugin v0.1.19
Same configuration as in my webpack3 project. It works in webpack3 project but not anymore in v4.

rimraf.js

 try {
      var st = options.lstatSync(p)
    } catch (er) {
      if (er.code === "ENOENT")  // <-- hitting 
        return

Exclude folders

Hello, I need to remove all content of dist folder except letters folder. I have read #41, but it didn't work for me. With the current settings, the entire content of the folder are deleted.

// project structure
my-project
  dist
    assets
    letters
    index.html
  src
// webpack config
new CleanWebpackPlugin(
  ['dist/*'],
  {
    root: 'my-project', // root works, simplified example
    verbose: true,
    dry: false,
    watch: false,
    exclude: ['letters']
  }
)

Possible to exclude folders in addition to files?

I want to delete all files in /build/ except everything in /build/vendor

new CleanWebpackPlugin([
    `${config.dist}*`  // user builds
], {
    exclude: ['vendor/']
}),

Is something like this possible yet?

Cannot install module on windows 10

When I install this module on windows 10 I get error:

> npm install --save clean-webpack-plugin npm WARN optional Skipping failed optional dependency /chokidar/fsevents: npm WARN notsup Not compatible with your operating system or architecture: [email protected] npm WARN [email protected] requires a peer of react@^15.0.2 but none was installed. npm WARN [email protected] requires a peer of react@^15.0.2 but none was installed. npm WARN [email protected] No repository field.

[Discussion] Plugin goals

@johnagan I think a lot of issues people have are created because there is confusion when/why to use this plugin.

A webpack plugin to remove your build folder(s) before building

Is this plugin meant to clean the build only once before the first webpack build? Is the goal clean project files before every compilation?

I personally do not see much value in a webpack plugin that cleans a project once before the build. I think it makes webpack more complicated/error prone, and is better solved with existing solutions and build tools.

Here is an extremely simple example how to integrate a clean directly with a webpack config without a plugin:

import webpack from 'webpack';
import path from 'path';
import del from 'del';

const outputPath = path.resolve(process.cwd(), 'build');

/*
 * Remove project files here when webpack is loaded. Be sure it is not async.
 * 
 * Popular existing packages:
 * https://github.com/isaacs/rimraf
 * https://github.com/sindresorhus/del -- I prefer this one, great glob support and has CLI (del-cli package)
 * https://github.com/jprichardson/node-fs-extra
 *
 */
del.sync([path.resolve(outputPath, '**/*')]);

const webpackConfig = {
    entry: path.resolve(process.cwd(), 'src/index.js'),
    output: {
        path: outputPath,
        filename: 'bundle.js',
    },
};

export default webpackConfig;

If the goal of the project is to clean webpack's compilation files, I think it would be a good idea to talk about merging this plugin with gpbl/webpack-cleanup-plugin if both you and @gpbl would be open to it. In addition I think it would help if we add better documentation to clarify the goals of this plugins and put an example of how to clean the build directory before webpack starts (such as the one I wrote above).

Thoughts?

Why plugin can clear a directory only BEFORE build?

What if I need to clear directory at the end of the build?

I need to build assets, create a zip file and remove everything in a directory except the zip file.
But looks like CleanWebpackPlugin everytime runs before all other plugins...

plugins: [
    new CleanWebpackPlugin(...),
    new CopyWebpackPlugin
    new StringReplacePlugin(),
    new ZipWebpackPlugin(...),
    new CleanWebpackPlugin(...)
]

Can you help me?

Will fail if config is not in the same folder as project root.

I have my project organized in various folders. One of them is app. Within there, I have a folder leading to all internal configuration files, including WebPack:

app/
  System/
    Config/
      webpack.js

Unfortunately, this breaks this plugin. Because the folder I want to delete is on the same level as the app folder - and that is cdn, my public assets.

app/ ...
cdn/
  app/
    [hash]-[name].(js|css)

Adding an option to the plugin to gently force a delete would be nice. I use an automated Surge.sh uploader, and it now uploads everything...

Setting options.root makes http response status 404

I am facing a problem which seems setting options.root conflicts with webpack-dev-server.

I have a project with the following structure:

project-root/
  package.json
  build/
    webpack.config.js
  dist/
    (webpack output files)
  ...

The brief content of build/webpack.config.js:

const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
  ...
  plugins: [
    new CleanWebpackPlugin([path.resolve(__dirname, '..', 'dist')])
  ]
  ...
};

At the begining I encountered the following message:
clean-webpack-plugin: /path/to/my/project-root is outside of the project root. Skipping...

So I set options.root of CleanWebpackPlugin to my project-root folder, and it solved the above problem.

But when I ran npm using webpack-dev-server --mode development my-entry.js --config build/webpack.config.js and directed my browser to http://localhost:port/, it gave me a 404 status response which will not show if options.root is not set.

I am curious about am I doing something wrong and how this isssue happened. Is there a way to avoid both two situations without changing the project structure?

I am using:

npm 5.7.1
node 9.9.0
webpack 4.1.1
webpack-dev-server 3.1.0
clean-webpack-plugin 0.1.19

Thank for reply!

Small docs update suggestions

For paths, maybe add a couple more examples, including how to remove the contents of the folder, rather than the folder itself:

[
  'dist',      // removes 'dist' folder
  'build/*.*', // removes all files in 'build' folder
  'web/*.js'   // removes all JavaScript files in 'web' folder
]

For the root option, make it clear that it's the root of your package. The webpack.config file currently mentioned could actually sit anywhere, it doesn't have to sit in your package root folder (mine is in /webpack/index.js).

{
  root: __dirname // absolute path - your package root folder (paths appended to this)
}

I guess you could change webpack.config to package.json.

EPERM on windows when chokidar is watching

When webpack is trying to clean up and target folder is watched from chokidar I'm getting EPERM error.
I've replaced rimraf with simple function and works without errors.

const deleteRecursive = function(path) {
    if (fs.existsSync(path)) {
        if (fs.statSync(path).isDirectory()) {
            fs.readdirSync(path).forEach(function(file) {
                var curPath = path + "/" + file;
                deleteRecursive(curPath);
            });
            fs.rmdirSync(path);
        } else {
            fs.unlinkSync(path);
        }
    }
};

and replaced

    if (_this.options.dry !== true) {
      if (_this.options.exclude && excludedChildren.length) {
        childrenAfterExcluding.forEach(function (child) {
          rimraf.sync(child);
        });
      } else {
        rimraf.sync(rimrafPath);
      }
    }

with

    if (_this.options.dry !== true) {
      if (_this.options.exclude && excludedChildren.length) {
        childrenAfterExcluding.forEach(function (child) {
          deleteRecursive(child);
        });
      } else {
        deleteRecursive(removePath);
      }
    }

Delete files on watch not working in Webpack 2

Cleaning of files works perfectly every time I build, or start the watch function, but when watching and editing files I just end up with a ton of files after every re-compile. I'm using option watch: true but it seems to have no effect. Also using webpack 2.

My config:

new CleanWebpackPlugin('./dist/*.*', [{
            root: __dirname,
            watch: true,
            verbose: true
        }])

Plugin cleaning after bundle is built

Hi!

I'm using this in combination with django-webpack-loader, and often times (especially if I accidentally save two times in a row) the plugin removes the bundle after it was compiled. Which leaves me with a blank page. Any idea on how to fix that?

Problems when using the plugin in Windows

When I run my builder in TeamCity CI, I get an argument, which directory should be deleted.

  • Windows
    C:\Users\splincode\Git\blackbox/core-adapter-web/target/classes/webapp

  • Linux
    /home/splincode/Git/blackbox/core-adapter-web/target/classes/webapp

So, the path arrives absolute and I can not know exactly where the script can run from. If I use current configuration, it's work in Linux:

var CleanWebpackPlugin = require('clean-webpack-plugin');
var dist = process.env["remove-temporary-folder"];

module.exports = {
  plugins: [
    new CleanWebpackPlugin([dist], {
      root: '/',
      verbose: true
    })
  ]
}

But, does not work in Windows, because I need set root as value "C:/". What should I do to make it cross-platform and work?

Benefit of this plugin vs rimraf

Just trying to understand what benefit you get from using this plugin over just a simple rimraf command to clean your dist?

I would have thought that the plugin would be "smart" and only clean stuff that Webpack no longer needs / isn't detected in the build chain any longer... some kind of prune type functionality, but my understanding is this plugin offers no much more functionality other than a basic remove (with some options to exclude etc)?

Proposal for a v2.0 in ES6

πŸ‘‹ Hello everyone. Thank you for ongoing support of this project. It's been a while since I used webpack, but now that I'm coming back into it, I would love to modernize this project. Ideally in ES6 and not one massive file 😎

Since I haven't used it recently, I'd love some feedback on if we should do this and what it needs.

Error: "project root is outside of project"

Hi,

Due to various reasons in our project, the client builds into the 'public' folder of our rails app. For illustration purposes:

  • server/client - client dir (where webpack.config.js lives), and where the build is run from
  • server/public - webpack config.output.path dir, where webpack builds relative to

It looks like this plugin relies on workingDir (i.e. process.cwd()) over webpack's config.output.path.

Would it be ok to change this? Webpack is building happily into a folder that isn't the cwd.

What I'm looking for is to remove / clean the files pre-build, in:

  • server/public/scripts and server/public/styles
  • leave anything else in server/public intact

Thanks!

Broken when webpack is called outside of project root

quangv@d32e1b3 does not work for paths outside of where webpack.config is called even when specifying root.

// /project/webpack/webpack.config.js
new Clean(['/project/dist/'], '/project/')
// /project/dist/ will not be deleted

Here is an example where it would fail.
https://github.com/erikras/react-redux-universal-hot-example/blob/master/webpack/prod.config.js

I fixed this, as well as added tests, options, and heavily refactored as a result. PR incoming.

Does not ignore deleting files outside of the root

I'm trying to prevent the plugin from removing a specific file in an output directory above the current context. This seems to work if it's within the current context, but not in a parent or adjacent folder. Here is my config:

 new CleanWebpackPlugin(['build/*', '../api/build/*'],{
            root:     path.resolve(__dirname), // set root to parent so we can clean ../api/build/
            allowExternal: true,
            exclude:  ['app.js'],
            verbose:  true,
            dry:      false,
            watch: true
}),

There is the file 'app.js' within '../api/build/' that it keeps deleting. I have also tried to put the full path of the file, ie: path.resolve(__dirname, '../api/build') + '/app.js' and similar things, but can't prevent it from deleting.

I've also tried just making a separate plugin definition for the parent folder, but it seems to still delete it, oddly:

new CleanWebpackPlugin(['build/**.js'],{
            root:     path.resolve(__dirname, '../api'), // set root to parent so we can clean ../api/build/
            exclude:  ['app.js'],
            verbose:  true,
            watch: true
}),

Any ideas?

plugin clean folder even on re-build

I have this config:

new CleanWebpackPlugin(['dist'], {
    root: projectRoot,
    watch: false
})

But when the watcher run it deletes the folder and start the whole Webpack's build from scratch.
I know the watch flag is false by default, I added that to make sure it's settled.

I'm using Webpack version 1 due to some IE backward compatibilities, maybe this is the issue?

Thanks.

Behavior changed? Gets removed every rebuild.

Hello there,
I've been used this module since Jan or Feb, 2016. (v0.1.4-v0.1.10)
Recently I re-installed this module (updated), and things changed.

Dist directory gets removed after every single rebuild.
My expected behavior was to clean just at the first time.
I couldn't find any documentation.

It's dosen't work sometimes

Thank you for this plugin.

My configuration is like this:

// webpack.config.js
...
var CleanWebpackPlugin = require('clean-webpack-plugin');
...
new CleanWebpackPlugin(
      [
        'dist'
      ]
    )

Most of the time you can delete the dist directory.and sometimes the CLI prompt has removed the dist directory, but the dist folder has not actually been removed. I wonder if I have met the same problems as I have.

my work environment following this:

System: window7
Webpack:2.5.1

Watch mode deletes all files regardless of changes

Hey,

An issue I've run into is that watch: true deletes the entire directory contents each time even if one bundle has changed. As you can imagine this causes a problem with my site trying to load scripts that have now been removed:

Example:

- build
--- script1.bundle.234567.js
--- script2.bundle.678987.js
--- script3.bundle.123456.js

// A change causes only `script3.bundle.[chunkhash].js` to be built

- build
--- script3.bundle.432312.js

Is it possible for watch mode to hook into the bundles that changed and remove just those?

Edit: I have found that https://github.com/GProst/webpack-clean-obsolete-chunks solves the problem, but the behaviour described does feel like a bug with the way you might expect watch to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.