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

Allow disabling of bundleDir from plugin option #274

Closed
amoshydra opened this issue Apr 25, 2019 · 4 comments
Closed

Allow disabling of bundleDir from plugin option #274

amoshydra opened this issue Apr 25, 2019 · 4 comments

Comments

@amoshydra
Copy link
Contributor

Issue description

Allow us to disable/overwrite bundleDir in the plugin option

Currently bundleDir can only be defined in via the command line. In plugin bundleDir is decided in the following logic

getBundleDirFromCompiler() {
return (this.compiler.outputFileSystem.constructor.name === 'MemoryFileSystem') ? null : this.compiler.outputPath;
}

However, compiler.outputFileSystem might not always be MemoryFileSystem.

Use case:

The framework Nuxt 2.5.0 replace MemoryFileSystem with their own implementation of AsyncMFS, which extend MemoryFileSystem, during development.

Current problem

This cause compiler.outputFileSystem.constructor.name to be "AsyncMFS", thus causinggetBundleDirFromCompiler to return this.compiler.outputPath.

Expected behavior

The expectation result here is null. Since nuxt is using webpack-dev-server during development and no real file is being created.

My thoughts

I am not sure if it is possible to detect if real file is created in this case. It might not be reasonable for webpack-bundle-analyzer to keep track of a list of outputFileSystem.constructor.name that should make bundleDir to null.

Thus I am proposing webpack-bundle-analyzer to allow us to overwrite bundleDir to null in the plugin option

Technical info

  • Webpack Bundle Analyzer version: v3.3.2
  • Webpack version: v4.30.0
  • Node.js version: v8.11.3
  • npm/yarn version: v1.12.1
  • OS: Windows 10, 1803 (OS Build 17134.706)

Debug info

How do you use this module? As CLI utility or as plugin?

As plugin

If CLI, what command was used? (e.g. webpack-bundle-analyzer -O path/to/stats.json)

If plugin, what options were provided? (e.g. new BundleAnalyzerPlugin({ analyzerMode: 'disabled', generateStatsFile: true }))

new webpackBundleAnalyzer.BundleAnalyzerPlugin({
  openAnalyzer: false,
}),

What other Webpack plugins were used?

This plugin is used with https://github.com/nuxt/nuxt.js v2.6.2

It would be nice to also attach webpack stats file.
It can be generated using these options:

new BundleAnalyzerPlugin({
  analyzerMode: 'disabled',
  generateStatsFile: true,
  // Excludes module sources from stats file so there won't be any sensitive data
  statsOptions: { source: false }
})

stats.json will be created in Webpack bundle output directory.

not available due to private content in file path and name

@valscion
Copy link
Member

The simplest way to get Nuxt unblocked could be to amend that conditional to also list AsyncMFS and then add a comment above to describe why that check is necessary, preferrably linking also to this issue.

Would you be open to create such a PR?

@amoshydra
Copy link
Contributor Author

amoshydra commented Apr 25, 2019

Hi @valscion, thanks for the prompt response.

I have created 2 PRs for this issue

Would like to have your opinion on which PR is more suitable for webpack-bundle-analyzer.

@valscion
Copy link
Member

valscion commented Apr 25, 2019

Let's go with #275 first as I'm a bit wary on adding new configuration options for something that seems to be quite an edge case. I'd like us to see more concrete use cases than Nuxt before adding a new config option

EDIT: Linked to wrong PR first because you had also put the wrong PR numbers in your message 😄

@th0r
Copy link
Collaborator

th0r commented May 8, 2019

Fixed in #275

@th0r th0r closed this as completed May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants