Skip to content

Conversation

gnulnx
Copy link
Contributor

@gnulnx gnulnx commented Mar 22, 2018

Even though this should have been obvious I had a bit of trouble figuring this out today so I figured I'd update the docs to help others.

I wasn't sure if it made sense to leave the original generic example in place or remove it... so I left it in place and added example below. I'm more than happy to update as necessary based on feedback.

Thanks

docs/webpack.md Outdated
.plugin('html')
.tap(args => {
return [{
template: '/Users/username/proj/app/templates/index.html'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change should extend the existing options (args[0]) so that it doesn't discard other possible options that were already defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Evan I think I'm being a bit dense about this. I've tried both of these.

module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0] = {
            template: '/Users/jfurr/zenperf/public2/index.html'
        }
        return args
      })
  }
}

And

module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        return [{template: '/Users/jfurr/zenperf/public2/index.html'}]
      })
  }
}

In both cases the output results in the HtmlWebackPlugin options dropping env, though the rest of the options seem to be unmodified.

Before modification

/* HtmlWebpackPlugin */ {
      options: {
        template: '/Users/jfurr/zenperf/public/index.html',
        filename: 'index.html',
        hash: false,
        inject: true,
        compile: true,
        favicon: false,
        minify: false,
        cache: true,
        showErrors: true,
        chunks: 'all',
        excludeChunks: [],
        title: 'Webpack App',
        xhtml: false,
        env: {
          NODE_ENV: 'development',
          BASE_URL: '/'
        }
      }
    },

After mod the template is correct, but env is missing..

/* HtmlWebpackPlugin */ {
      options: {
        template: '/Users/jfurr/zenperf/public2/index.html',
        filename: 'index.html',
        hash: false,
        inject: true,
        compile: true,
        favicon: false,
        minify: false,
        cache: true,
        showErrors: true,
        chunks: 'all',
        excludeChunks: [],
        title: 'Webpack App',
        xhtml: false
      }
    },

Am I missing some obvious? Do I need to explicitly set the env back to the default?

Copy link

@abruere abruere Apr 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yyx990803 probably refers to the following way to extend:

EDIT:

module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0].template = '/Users/jfurr/zenperf/public2/index.html'
        return args
      })
  }
}

This should preserve env and just update template option. See https://github.com/mozilla-neutrino/webpack-chain#config-plugins-modify-arguments

@gnulnx
Copy link
Contributor Author

gnulnx commented Apr 1, 2018

@abruere Thanks and that makes total sense now. PR updated.

@yyx990803 yyx990803 merged commit b501dd5 into vuejs:dev Apr 25, 2018
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

Successfully merging this pull request may close these issues.

3 participants