lukeed / pwa

(WIP) Universal PWA Builder
https://pwa.cafe
3.13k stars 100 forks source link

[question] pwa.config.js override breaks pwa build #37

Closed tuananh closed 6 years ago

tuananh commented 6 years ago

I'm not sure if this is the expected behavior.

take preact for example, there are a bunch of default resolve.alias for webpack. as soon as i add more alias, the other default, required aliases were gone, leaving pwa build to fail.

                'react': 'preact-compat',
        'react-dom': 'preact-compat',
        'preact': opts.production ? 'preact/dist/preact.min.js' : 'preact',
        'react-addons-css-transition-group': 'preact-css-transition-group',
        'create-react-class': 'preact-compat/lib/create-react-class'

i have to copy them and add to my override config to make it work.

lukeed commented 6 years ago

Hey, ya, that's the tricky part with mutable config objects.

You have to change as little as possible. I have another response to this example here: https://github.com/lukeed/pwa/issues/28#issuecomment-418539968

In your example, which is very similar, you should write into keys directly instead of overwriting the whole config.resolve object.

module.exports = function (config) {
  // Right 
  config.resolve.alias.newAlias = 'hello';

  // Wrong
  config.resolve.alias = {
    newAlias: 'hello'
  }

Lemme know if that helps 👍

tuananh commented 6 years ago

Thank you. It works.