webpack-contrib / file-loader

File Loader
MIT License
1.86k stars 257 forks source link

Infinite recompilation with `output.path` and `webpack --watch` #322

Closed StanAngeloff closed 5 years ago

StanAngeloff commented 5 years ago

Expected Behavior

When using output.path in webpack.config.js I expect webpack --watch to react to file changes only once.

Actual Behavior

file-loader puts webpack --watch in a constant re-compilation cycle.

Code

#!/bin/sh

# Put this in script.sh in an empty directory and execute via $ sh script.sh

echo '{}' > package.json

npm i --save-dev webpack@4 webpack-cli@3 file-loader@3

cat > webpack.config.js <<-'EOF'
module.exports = {
    mode: 'development',
    entry: './images/pixel.png',
    output: {
        path: __dirname,
    },
    module: {
        rules: [
            {
                test: /\.png/,
                loaders: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: path => '/compiled/[name].[ext]?[hash]',
                        }
                    },
                ],
            },
        ],
    },
};
EOF

mkdir -p images/
touch images/pixel.png

NODE_ENV=development ./node_modules/.bin/webpack -w --progress --hide-modules

How Do We Reproduce?

Run the script above which will install all Node dependencies, create the necessary webpack.config.js file and run the --watch sub-command.

Note how output is constantly printed and erased below the line Entrypoint main = main.js

If output.path or module.rules.0.loaders.0.options.name is omitted, this bug does not manifest itself.

Originally reported as part of https://github.com/JeffreyWay/laravel-mix/issues/1942

alexander-akait commented 5 years ago

Problem solved?

StanAngeloff commented 5 years ago

I'm not sure, the original issue in Laravel Mix is still outstanding, I just can't get to a minimal reproducible state :(

alexander-akait commented 5 years ago

@StanAngeloff i think problem deeply than in file-loader, plugin or loader add new file to graph so webpack recompile, we it is happens again and webpack recompile, start to debug with plugins