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

Possibility change filesystem optionaly in ChunkExtractor #315

Closed
furryablack opened this issue Apr 22, 2019 · 2 comments · Fixed by #318
Closed

Possibility change filesystem optionaly in ChunkExtractor #315

furryablack opened this issue Apr 22, 2019 · 2 comments · Fixed by #318

Comments

@furryablack
Copy link

🚀 Feature Proposal

At now ChunkExtractor uses default node fs package:

// @loadable/server/lib/ChunkExtractor.js
var _fs = _interopRequireDefault(require("fs"));

In development mode with ssr server (aka express) i'm using MFS (memory-fs), but ChunkExtractor knows nothing about it.

What do i think (generalized code parts):

  let loadableServerStats;
  let loadablClientStats;

  ...

  /*
    Server config factory
   */

  const serverConfigCompiler = webpack(serverConfigFactory);

  const mfs = new MFS();

  serverConfigCompiler.outputFileSystem = mfs;

  serverConfigCompiler.watch({}, (err, stats) => {
    if (err) {
      throw err;
    }

    stats = stats.toJson();

    if (stats.errors.length) {
      return;
    }

    loadableServerStats = JSON.parse(readFile(
      mfs,
      loadableServerStatsFilename,
      serverConfigFactory,
    ));
    
    /*
       As example, for client side its will be devMiddleware.fileSystem
       (const devMiddleware = require('webpack-dev-middleware')(clientConfigCompiler))       
    */
    update(mfs);
  });

  ...

  const update = (fsSource) => {
    if (loadableServerStats && loadableClientStats) {
      ready();
      /*
         cb works with ChunkExtractor already
      */
      cb({
        template,
        loadableClientStats,
        loadableServerStats,
        mountId,
        fsSource,
      });
    }
  };

  ...

  createExtractor(stats, fsSource) {
      // at here i want say to extractor "use this source"
      return new ChunkExtractor({ fsSource, stats, entrypoints: this.getEntrypoints() });
   },

Motivation

Makes faster development process

Example

See higher pls

Pitch

We give the opportunity to specify a different fs (mfs) for loading assets.

@gregberge
Copy link
Owner

Hello @furryablack, good idea, I implement it.

@furryablack
Copy link
Author

Wow, so fast =) Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants