preactjs / preact-cli

😺 Your next Preact PWA starts in 30 seconds.
MIT License
4.68k stars 376 forks source link

preact.config.js with webpack watchOptions #1593

Closed moszeed closed 3 years ago

moszeed commented 3 years ago

Hello everyone, first i will thank for your support and work on this awesome tool. But i`m running into a Problem i cant get resolved alone.

I just want to extend the preact.config.js . All i want is to add following:

watchOptions: {
    ignored: '/node_modules/',
    poll: 1000 // Check for changes every second
}

but i cant find a solution that is working... my latest attempt looks like this:

// these props are both optional
export default {
    /**
     * Function that mutates the original webpack config.
     * Supports asynchronous changes when a promise is returned (or it's an async function).
     *
     * @param {object} config - original webpack config.
     * @param {object} env - options passed to the CLI.
     * @param {WebpackConfigHelpers} helpers - object with useful helpers for working with the webpack config.
     * @param {object} options - this is mainly relevant for plugins (will always be empty in the config), default to an empty object
     **/
    webpack(config, env, helpers, options) {
        config.devServer.watchOptions: {
            ignored: '/node_modules/',
            poll: 1000 // Check for changes every second
        }
    },
};

but i'm still getting a SyntaxError: Invalid or unexpected token error. Thank you for your Help.

rschristian commented 3 years ago

What you want is:

config.devServer.watchOptions = {
    ignored: '/node_modules/',
    poll: 1000 // Check for changes every second
}

Your editor should make pretty clear that the colon you have there is invalid syntax.

We do also have a number of config recipes, including one that's quite similar to your use (syntactically, at least). Certainly feel free to ask though if something doesn't make sense.

moszeed commented 3 years ago

big thank you =)