Giter Site home page Giter Site logo

Comments (7)

AndersDJohnson avatar AndersDJohnson commented on March 29, 2024 1

How to do this with webpack 1.x or later? emitFile and noWrite seem gone. Already changed absoluteFile arg to entry: absoluteFile in config options.

Only possible with memory file system, e.g. https://webpack.github.io/docs/node.js-api.html#compile-to-memory? Or custom read from filesystem after compile?

from webpack.

sokra avatar sokra commented on March 29, 2024

yes. There is an option noWrite and you need to pass the option emitFile to get the source of a file.

Here is a working example: https://github.com/webpack/worker-loader/blob/master/index.js

It's a webpack loader which compiles to WebWorker.
It's called from the parent webpack and executes a embedded webpack. The embeddend webpack do not write out files, but the worker-loader grabs the emitted files and pass them to the parent webpack.

Good luck.

from webpack.

sokra avatar sokra commented on March 29, 2024

The API which returns the source in the callback was deprecated in webpack 0.5 and I removed it in 0.6. The reason for removing was that many loader would not work with the old API because they emit files. I. e. file-loader.

The webpack-dev-middleware also do webpack in memory: https://github.com/webpack/webpack-dev-middleware/blob/master/middleware.js#L15

from webpack.

topa avatar topa commented on March 29, 2024

Thank you for your fast response. I'm not sure if I got it, but are the following steps correct?

  • first: set noWrite to true
  • second: define with emitFile a function that collects the source of each file, like function collectSources(filename, content) { /* do some collecting stuff */ }
  • third: execute webpack(absolutePath, options, function(err, stats) { /* nothing really to do here */})
  • fourth: on "bundle"-event webpack has finished and I can return in any way the collected sources

If I try it like described I get the following error:

Error: options.output is required

from webpack.

sokra avatar sokra commented on March 29, 2024

Set output to the name of the bundled file, i. e. bundle.js.

You don't need the "bundle" event just use the callback in third.

webpack(absoluteFile, {
  output: "bundle.js",
  noWrite: true,
  emitFile: function(name, stringOrBuffer) {
    files[name] = stringOrBuffer;
  }
}, function(err, stats) {
  if(err) return handleError(err);
  processFiles(files);
})

from webpack.

topa avatar topa commented on March 29, 2024

Thank you again for your fast response and help. It works now. If you like to you can take a look my implementation here: WebpackBundler

from webpack.

sokra avatar sokra commented on March 29, 2024

peerigon/nof5#10
peerigon/nof5#11

from webpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.