Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what is the type of result after merge operator? #106

Closed
DYSDF opened this issue Nov 9, 2018 · 1 comment
Closed

what is the type of result after merge operator? #106

DYSDF opened this issue Nov 9, 2018 · 1 comment

Comments

@DYSDF
Copy link

DYSDF commented Nov 9, 2018

At first I thought it was a normal object data, when i use push method, I found that I was wrong.

for example:

const path = require('path')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

const conf1 = {
  entry: {
    page1: 'src/page1',
    page2: 'src/page2'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/'
  }
}

const conf2 = {
  entry: {
    page3: 'src/page3',
    page4: 'src/page4'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/'
  }
}

const enhance = {
  plugins: [
    new BundleAnalyzerPlugin({
      analyzerMode: 'server',
    })
  ]
}

const result1 = merge(conf1, enhance)
const result2 = merge(conf2, enhance)

console.log(result1.plugins.length)
console.log(result2.plugins.length)

the result is:
image

When I use the push method to add HtmlWebpackPlugin,the result has change.

const path = require('path')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

const conf1 = {
  entry: {
    page1: 'src/page1',
    page2: 'src/page2'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/'
  }
}

const conf2 = {
  entry: {
    page3: 'src/page3',
    page4: 'src/page4'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/'
  }
}

const enhance = {
  plugins: [
    new BundleAnalyzerPlugin({
      analyzerMode: 'server',
    })
  ]
}

const result1 = merge(conf1, enhance)
const result2 = merge(conf2, enhance)

result1.plugins.push(
  new HtmlWebpackPlugin()
)

console.log(result1.plugins.length)
console.log(result2.plugins.length)

image

I have not operated another, but the plugins is changed.

when i use merge method, the result is correct.

const path = require('path')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

const conf1 = {
  entry: {
    page1: 'src/page1',
    page2: 'src/page2'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/'
  }
}

const conf2 = {
  entry: {
    page3: 'src/page3',
    page4: 'src/page4'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/'
  }
}

const enhance = {
  plugins: [
    new BundleAnalyzerPlugin({
      analyzerMode: 'server',
    })
  ]
}

let result1 = merge(conf1, enhance)
const result2 = merge(conf2, enhance)

result1 = merge(result1, {
  plugins: [
    new HtmlWebpackPlugin()
  ]
})

console.log(result1.plugins.length)
console.log(result2.plugins.length)

image

why?

@bebraw bebraw closed this as completed in 559292d Jan 4, 2019
@bebraw
Copy link
Member

bebraw commented Jan 4, 2019

Thanks for the report. Resolved in 4.2.1. Sorry for the delay. Super busy year with work.

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

No branches or pull requests

2 participants