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

Patterns not working #128

Closed
jaschaio opened this issue Apr 21, 2019 · 6 comments
Closed

Patterns not working #128

jaschaio opened this issue Apr 21, 2019 · 6 comments

Comments

@jaschaio
Copy link

jaschaio commented Apr 21, 2019

Issue description

The patterns have no effect for me. I tried with different ones taking in mind this overview, but it still deletes files it shouldn't delete.

From my understanding this should only delete css and js files starting with bundle or app:

cleanAfterEveryBuildPatterns: [ 
    '/js/bundle.*.min.js',
    '/js/app.*.min.js',
    '/css/app.*.min.css'

But the output I get is:

clean-webpack-plugin: removed ../public/js/app.f4d092e0.min.js
clean-webpack-plugin: removed ../public/js/bundle.21.42b6a945.min.js
clean-webpack-plugin: removed ../public/js/nprogress.aa99ef98.min.js
clean-webpack-plugin: removed ../public/js/skins/content/default/content.css
clean-webpack-plugin: removed ../public/js/skins/content/default/content.min.css
clean-webpack-plugin: removed ../public/js/skins/content/document/content.css
clean-webpack-plugin: removed ../public/js/skins/content/document/content.min.css
clean-webpack-plugin: removed ../public/js/skins/content/writer/content.css
clean-webpack-plugin: removed ../public/js/skins/content/writer/content.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide-dark/content.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide-dark/content.inline.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide-dark/content.inline.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide-dark/content.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide-dark/skin.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide-dark/skin.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/content.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/content.inline.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/content.inline.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/content.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/content.mobile.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/fonts/tinymce-mobile.woff
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/skin.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/skin.min.css
clean-webpack-plugin: removed ../public/js/skins/ui/oxide/skin.mobile.min.css

I tried explicit excluding the js/skins/ folder via:

cleanAfterEveryBuildPatterns: [ 
    '/js/*.min.js',
    '/js/*.min.css',
    '!/js/skins/'

But it still removes files from within the skins folder.

It almost seems like its not taking effect at all (even tho its only deleting .js and .css files and leaves other files untouched).

Webpack Config

const path = require( 'path' );

const webpack = require( 'webpack' );

const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );

const OptimizeCSSAssetsPlugin = require( 'optimize-css-assets-webpack-plugin' );

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

const copyWebpackPlugin = require( 'copy-webpack-plugin' );

module.exports = ( env ) => ( {
        entry: {
            app: './app.js',
        },
        output: {
            path: path.join( __dirname, '..', 'public' ),
            filename: 'js/[name].[contenthash:8].min.js',
            chunkFilename: 'js/bundle.[id].[contenthash:8].min.js',
            publicPath: '/'
        },
        target: 'web',
        module: {
            rules: [
                {
                    test: /\.js$/,
                    exclude: /node_modules/,
                    loader: 'babel-loader',
                    options: {
                        plugins: [
                            '@babel/plugin-proposal-object-rest-spread',
                            '@babel/plugin-syntax-dynamic-import'
                        ]
                    }
                },
                {
                    test: /\.s?css$/,
                    exclude: /node_modules/,
                    use: [
                        {
                            loader: MiniCssExtractPlugin.loader,
                            options: {
                                url: false
                            }
                        },
                        {
                            loader: 'css-loader',
                            options: {
                                url: false
                            }
                        },

                        {
                            loader: 'sass-loader',
                            options: {
                                url: false
                            }
                        }
                    ],
                }
            ]
        },
        plugins: [
            new MiniCssExtractPlugin( {
                filename: ( env.NODE_ENV === 'prod' ) ? 'css/[name].min.css' : 'css/[name].min.css'
            } ),
            // Copy tinymce files
            new copyWebpackPlugin([
                { from: './node_modules/tinymce/skins', to: './js/skins' }
            ] ),
            // Clean build directory
            new CleanWebpackPlugin(
                {
                    verbose: true,
                    cleanOnceBeforeBuildPatterns: [],
                    cleanAfterEveryBuildPatterns: [
                        '/js/bundle.*.min.js',
                        '/js/app.*.min.js',
                        '/css/app.*.min.css'
                    ]
                }
            )
        ]
    } )

Environment

  System:
    OS: macOS Mojave 10.14.4
    CPU: (4) x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
    Memory: 51.84 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 8.11.1 - ~/.nvm/versions/node/v8.11.1/bin/node
    npm: 6.9.0 - ~/.nvm/versions/node/v8.11.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  npmPackages:
    clean-webpack-plugin: ^2.0.1 => 2.0.1 
    webpack: ^4.29.6 => 4.29.6 
@chrisblossom
Copy link
Collaborator

Can you provide a minimal reproducible repository?

@Nelathan
Copy link

I had the same problem and fixed it temporarily by excluding the folder AND the underlying files:
['!js/skins', '!js/skins/**/*']
also i removed the preceding "/"

@chrisblossom
Copy link
Collaborator

I think issue you are having is pattern matching being relative to webpack's output.path as described in the documentation.

@Schlammsuhler's solution is correct, although I'm not sure about needing to also include '!js/skins'.

I'm going to close this. Please reopen if you are still having an issue.

@Nelathan
Copy link

Nelathan commented May 2, 2019

I still think that if the folder js/skins is ignored, all underlying files should be automatically ignored too like in gitignore. Which is not the case. Please look into this

@chrisblossom
Copy link
Collaborator

@Schlammsuhler This package uses del, which uses globby for pattern matching.

I think you're wanting globby's expandDirectories option to work on !negative patterns, which it doesn't seem to currently. It would be helpful if you could open an issue there. Keep in mind that del uses version 6 of globby.

@nakedtoast
Copy link

nakedtoast commented Oct 18, 2019

+1 for files should be automatically ignored too like in gitignore.

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