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

API - Using Preloaded Assets with the Compiler #141

Closed
pksjce opened this issue Sep 7, 2016 · 10 comments
Closed

API - Using Preloaded Assets with the Compiler #141

pksjce opened this issue Sep 7, 2016 · 10 comments

Comments

@pksjce
Copy link

pksjce commented Sep 7, 2016

From @danschumann on March 11, 2015 14:0

I have all my files in memory, for various reasons I won't get into ( maybe one is because I wrote a loading module loaddir and tend to use it ), but part of it is re-using code on the front end and back end.

My loaded files look like this (asObject: true):

require('loaddir')({path: './scripts', asObject: true }).then(function(directory) {
  /* directory == {
     'file1': 'console.log("file1");',
     'subDirectory': {
         'file2': 'console.log("subDir/file2");',
     },
  } */
});

or, my loaded files look like this (asObject: false)

require('loaddir')({path: './scripts' }).then(function(directory) {
  /* directory == {
    'file1': 'console.log("file1");',
    'subDirectory/file2': 'console.log("subDir/file2");',
  } */
});

How do I give a manifest like this to webpack, telling it "Hey webpack, I already loaded everything, can you just compile using this data plz?"

Copied from original issue: webpack/webpack#874

@pksjce
Copy link
Author

pksjce commented Sep 7, 2016

From @sokra on March 13, 2015 13:44

You can provide a custom inputFileSystem to the Compiler instance.

@pksjce
Copy link
Author

pksjce commented Sep 7, 2016

From @danschumann on March 16, 2015 17:29

Is it documented anywhere? Or, what structure does it need to be in?

@bebraw bebraw added the Migrate label Sep 7, 2016
hzuhyb pushed a commit to hzuhyb/webpack.js.org that referenced this issue Feb 18, 2017
/content/concepts/loaders.md 校对
@skipjack skipjack changed the title Using preloaded assets API - Using Preloaded Assets with the Compiler Jun 12, 2017
@skipjack
Copy link
Collaborator

skipjack commented Jun 12, 2017

@sokra can you give a little more detail on inputFileSystem (e.g. how/where it's passed and used)? Seems like we could just add the docs to this page.

@skipjack
Copy link
Collaborator

This section seems to be the only one that mentions it so far. Related discussion here as well: webpack/webpack#1562.

It also seems to be somewhat related to the webpack/enhanced-resolve repository and the **InputFileSystem.js modules offered there.

@sokra
Copy link
Member

sokra commented Jul 1, 2017

You can set the compiler.inputFileSystem in the Compiler's enviroment hook.

This should be an object with these methods:

mkdirp(path, callback)
readFile(path, callback) // only Buffer variant needed
readdir(path, callback)
stat(path, callback)

@skipjack
Copy link
Collaborator

skipjack commented Jul 1, 2017

@sokra so I do see the environment event listed in the compiler events table but it says no params are passed to the callback -- is that wrong and it's set like so?

MyCompiler.plugin("environment", function(compiler) {
    compiler.inputFileSystem = {
         mkdirp(path, callback) { ... },
         readFile(path, callback) { ... },
         readdir(path, callback) { ... },
         stat(path, callback) { ... }
    }
});

or differently? Also it seems maybe we should recommend people use or at least take a look at the ***InputFileSystem files in enhanced-resolve?

@sokra
Copy link
Member

sokra commented Jul 1, 2017

I recommend using memory-fs for your own in memory filesystem.

@skipjack
Copy link
Collaborator

skipjack commented Jul 1, 2017

Ok will do -- is that usage example I showed correct or incorrect though?

@skipjack
Copy link
Collaborator

skipjack commented Jul 1, 2017

Related: webpack/webpack#1562

@skipjack
Copy link
Collaborator

skipjack commented Jul 1, 2017

Hmmm I found what looks like a good example here: christianalfoni/webpack-bin#106.

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

5 participants