maoberlehner / node-sass-magic-importer

Custom node-sass importer for selector specific imports, module importing, globbing support and importing files only once.
MIT License
292 stars 28 forks source link

node-sass-once-importer@5.2.0 triggers webpack@4.16.0 watcher on build #176

Closed joacim-boive closed 6 years ago

joacim-boive commented 6 years ago

The build is invalidated and re-builds - ends up in an endless loop.

I'm guessing it stores some temp files somewhere that I need to configure webpack to ignore(?).

I am already ignoring [/node_modules/, /build/]

If I remove importer: require('node-sass-once-importer')(), then the watcher works as expected.

const watcher = compiler.watch({  // Keep watching files for changes
            aggregateTimeout: 300,
            ignored: [/node_modules/,/build/],
        }, (err, stats) => {
            if (err) {
                console.log(err)
            }

            compilationDoneNotification(stats, config);
        });
{
                    test: /\.(sa|sc|c)ss$/,
                    use: [
                        MiniCssExtractPlugin.loader,
                        {
                            loader: 'css-loader',
                            options: {
                                sourceMap: true,
                                importLoaders: 3
                            }
                        },
                        {
                            loader: 'postcss-loader',
                            options: {
                                ident: 'postcss',
                                sourceMap: true,
                                plugins: [
                                    require('autoprefixer')({
                                        grid: true,
                                        remove: true,
                                    }),
                                    require('postcss-flexbugs-fixes'),
                                ]
                            }
                        },
                        {
                            loader: 'resolve-url-loader',
                            options: {
                                sourceMap: true
                            }
                        },
                        {
                            loader: 'sass-loader',
                            options: {
                                sourceMap: true,
                                importer: require('node-sass-once-importer')(),
                            }
                        }
                    ]
                },
maoberlehner commented 6 years ago

Hey @joacim-boive, node-sass-once-importer doesn't write any files to the file system.

Where is compiler.watch coming from?

joacim-boive commented 6 years ago

@maoberlehner - Huh. That's weird then.

compiler.watch is just Webpack with the current configuration loaded:

        const webpack = require('webpack');
        const compiler = webpack(config);

This is equivalent to: webpack --watch

But I am using the Node.js API of webpack for my build script: https://webpack.js.org/api/node/

maoberlehner commented 6 years ago

It would be great if you could provide me with a minimal setup to reproduce this error (just: webpack.config.js, build.js, entry.js, index.scss). That would make things a lot easier :)

(and all those files containing only the bare minimum code to cause the error)

joacim-boive commented 6 years ago

Yes, I understand. I'll see what I can do - it's part of our big build script the on to "solve all problems". ;)

joacim-boive commented 6 years ago

My bad - I was a configuration issue in my build script.

maoberlehner commented 6 years ago

Thanks for letting me know, and for solving the problem yourself 👍

isaacpz commented 6 years ago

@joacim-boive What ended up being the problem? I'm experiencing the same endless loop issue when I use the SASS magic importer.

joacim-boive commented 6 years ago

@isaacpz In my case I happened to be running the script twice.