vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.75k stars 6.33k forks source link

Error when using alternative outputFileSystem (e.g. memory-fs) #3791

Open clemyan opened 5 years ago

clemyan commented 5 years ago

Version

3.5.5

Reproduction link

https://github.com/clemyan/vue-cli-fs-repro

Environment info

  System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  Binaries:
    Node: 11.7.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.12.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.5.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 42.17134.1.0
  npmPackages:
    @vue/cli-overlay:  3.5.1
    @vue/cli-service: ^3.5.0 => 3.5.3
    @vue/cli-shared-utils:  3.5.1
    @vue/component-compiler-utils:  2.6.0
    @vue/preload-webpack-plugin:  1.1.0
    @vue/web-component-wrapper:  1.2.0
    vue: ^2.6.6 => 2.6.10
    vue-hot-reload-api:  2.3.3
    vue-loader:  15.7.0
    vue-style-loader:  4.1.2
    vue-template-compiler: ^2.5.21 => 2.6.10
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

yarn build

What is expected?

Build finishes without error

What is actually happening?

An error is throw after assets are emitted. All assets are emitted properly.


The error is thrown from @vue\cli-service\lib\commands\build\formatStats.js while trying to print emitted assets info, because it attempts to read the emitted files from the real fs while the Webpack compiler could be using an outputFileSystem that does not write to real fs.

Since formatStats is already passed a Stats instance, in Webpack 4 it can avoid reading the fs by reading the emitted code from the stats object directly.

I have a use case in which I want to use webpack plugins to generate alternative assets (e.g. zip files) and avoid the cost of writing the app to the fs by using a custom outputFileSystem.

clemyan commented 5 years ago

Upon further investigation, the assets prop is considered internal and not part of the public API of Stats. So reading the emitted code from the stats object directly is not compliant.

I guess the "proper" way is to hook into emit using a Webpack plugin then.