Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I keep a directory? #173

Open
ben4d85 opened this issue Feb 18, 2020 · 3 comments
Open

How can I keep a directory? #173

ben4d85 opened this issue Feb 18, 2020 · 3 comments

Comments

@ben4d85
Copy link

ben4d85 commented Feb 18, 2020

Issue description or question

When using webpack-clean, what option do I need to pass to keep a whole directory, i.e. to ensure the directory does not get deleted?

Example

My output directory is dist. I want index.js to be deleted, but I want to keep the .git folder.

- dist
-- .git
-- index.js

Attempt

I have tried the following. But this stops it from deleting anything at all. Might it have to do with the . in .git? What is the correct way to use this, please?

        new CleanWebpackPlugin({
            cleanOnceBeforeBuildPatterns: ['!.git'],
        }),
@csymlstd
Copy link

I was confused as well. I think this setting overrides the default include so you have to put it back.

To clean your output, but exclude a whole directory, this should do the trick:

new CleanWebpackPlugin({
    cleanOnceBeforeBuildPatterns: ['**/*', '!.git', '!.git/**/*']
})

@kaysonwu
Copy link

kaysonwu commented Mar 9, 2020

@johnagan Can you simplify the option to exclude directories?

Now

cleanOnceBeforeBuildPatterns: ['**/*', '!dir', '!dir/**/*']

Expect

cleanOnceBeforeBuildPatterns: ['**/*', '!dir']

If a directory is allowed to be emptied, then this directory should also be deleted.

@stepbackj
Copy link
Contributor

I was able to exclude a directory and all its subdirectories/files using

cleanOnceBeforeBuildPatterns: ['**/*', '!dir/**']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants