input filesystem

I am using the node API and would like to take control of the loading of the input files.
I was hoping to be able to do something along the lines of

resolve = function(absPathFrom, includeArgument, cb) {
  var absPathTo = path.resolve(absPathFrom, includeArgument);
  var content = fs.readFileSync(absPathTo, 'utf-8');
  cb(null, content);

but seems like implementing a full filesystem along the lines of is needed.

Is that correct? Or is there an easier way?

Author: Fantashit

3 thoughts on “input filesystem

  1. I struggled with the same. If you take a look into the lib/node/NodeEnvironmentPlugin.js, then you can see that webpack uses multiple file systems for different files. This is very flexible but is not very obvious how to use… But, it’s exactly what you need

    The important lines are:

    compiler.resolvers.normal.fileSystem = compiler.inputFileSystem;
    compiler.resolvers.context.fileSystem = compiler.inputFileSystem;
    compiler.resolvers.loader.fileSystem = compiler.inputFileSystem;

    Most certainly you don’t want to override the loader filesystem (except you want to use dynamic loader implementation, but that sounds sick). Theres also a Watcher filesystem, in case you want to use webpack in watch mode….

    A working configuration looks like

    var compiler = webpack(options);
    compiler.inputFileSystem = fs;
    compiler.resolvers.normal.fileSystem = compiler.inputFileSystem;
    compiler.resolvers.context.fileSystem = compiler.inputFileSystem;
    compiler.outputFileSystem = fs;
  2. I just managed it as well, Some of the loaders are actually also run from from within your bundled code. Like with style and css loader. The way I solved this is to expose the loaders on the same path as on the filesystem, though inside the memory filesystem. That way it does not matter if webpack loads from memory or actual file system, its the same path.

    I also made a video on what we hope to achieve with this:

    There is an issue with babel presets and plugins though, but there is a really easy fix to it. So can fork the project or maybe an option could be exposed.

Comments are closed.