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
Next steps for 0.9 #41
Comments
I'm looking forward to these changes. Let me know if I can help somehow. |
I like that you are going to rethink the options object. Try to use convention over configuration when possible, find good default values. |
Current state of design: The There is are new public The The In a Some classes inherit from a So the The
Also node.js / IO specific stuff is in the classes There is more stuff, this is just a overview. Any comments? Any stuff whichs should be extendable? |
Which loaders should be included in webpack? Here is a list. |
I favor your attempts to simplify the API. The current options-object is very complex and seemed a little odd to me (e.g. the resolve/postprocess-thing). I'm not sure if I got your explanation right, but I like your idea of a Such as var webpack = require("webpack"),
Compiler = webpack.Compiler,
ModuleTemplate = webpack.ModuleTemplate,
MyModuleFactory = require("../MyModuleFactory.js"),
myModuleFactory = new MyModuleFactory(),
compiler = new Compiler();
var compilation = compiler.run("/my/folder");
compilation.on("dependency", function (dependency) {
myModuleFactory.resolve(dependency);
// etc
}); So what happens to loaders? How do they fit in the new architecture? |
Loaders are the best thing :) and will stay. I think I will ship webpack without the loaders, and you have to install every loader you need... So it stay more lightweight. The standard usage of webpack will be (as before) the webpack({
context: __dirname,
entry: "./file.js",
output: {
path: path.join(__dirname, "public"),
filename: "mybundle.js"
}
}, function(err, stats) {
if(err) throw err;
console.log(stats.toString({
colors: true
}));
}); The options have been refactored. There is a plugin interface, so i hope many stuff can move into a plugin. (at An example plugin for changing a path after resolving: function MyPlugin() {
};
module.exports = MyPlugin;
MyPlugin.prototype.apply = function(compiler) {
compiler.resolver.plugin("module-resolved", function(result, callback) {
callback(null, result.replace(/x/g, "y"));
});
}; var MyPlugin = require("./myPlugin.js");
webpack({
// ...
plugins: [new MyPlugin()]
}, callback); The other (more advanded) way is the var c = new Compiler();
c.context = __dirname;
c.entry = new SingleEntryDependency("./file.js");
// or: new SingleEntryPlugin(__dirname, "./file.js").apply(c);
c.options.output = {
path: path.join(__dirname, "public"),
filename: "mybundle.js"
};
// or: new OutputLocationPlugin(path.join(__dirname, "public"), "mybundle.js").apply(c);
new NodeEnvironmentPlugin().apply(c);
new JsonpTemplatePlugin().apply(c);
new FunctionModulePlugin().apply(c);
new EvalDevToolModulePlugin().apply(c);
new MyPlugin().apply(c);
c.run(function(err, stats) {
// ...
}); The plugin system has the intend that a library could provide a plugin which does the configuration... I. e. a jade plugin which binds the extension to the correct loader. The user just have to use the plugin. (maybe with |
Progress:
|
Seems reasonable to me. 😄 How does the compiler interface look like? Don't make it too granular and complicated. For me there are two important parts:
I wouldn't separate path lookup and compilation (as it was with webpack 0.6.x). A loader may change the path and/or compile a module. I like the idea of loaders, but I'm still not a big fan of enhanced-require. It is not CommonJS-style and makes the module unconsumable for other bundlers. It's ok to depend on a specific bundler when developing an application. But a library should not depend on a specific bundler. |
Compiler interface: var compiler = new Compiler();
// <- Attach plugins to the compiler
// Choose one of "run", "watch" oder "compile"
compiler.compile(function(err, compilation) { /* ... */ }); // compile and return a Compilation
compiler.run(function(err, stats) { /* ... */ }); // compile and write to files
compiler.watch(function(err, stats) { /* ... */ }); // like run, but rerun on change At least you have to attach this plugins:
Even better is if you attach a plugin for a require style, i. e. Some of the plugins take options. Example: var compiler = new Compiler();
var context = __dirname; // root for resolving entry and shortening stuff
var plugins = [
new NodeEnvironmentPlugin(outputPath, resolveOptions),
new JsonpTemplatePlugin({ filename: "bundle.js" }),
new FunctionModulePlugin(context),
new SingleEntryPlugin(context, "./entry.js"),
new CommonJsPlugin()
];
plugins.forEach(function(p) { p.apply(compiler) });
compiler.run(function(err, stats) {
if(err) return console.error(err);
console.log(stats.toString({ colors: true }));
}); This would be a very basic build. The |
Here is a bit of documentation for the current plugins: https://github.com/webpack/webpack/wiki/Plugins |
Looks good! But I'm not sure about the |
Currently not, but I may want to add an online demo, so it would be cool if it could run in the browser (of couse bundled with itself ;) ). Maybe to worker loader also need another environment, not sure yet. |
Ahh headache ^^ |
Next week I may have some time to make good progress with 0.9 |
Yeah! 🚀 |
🚀 🚀 🚀 |
Webpack become bigger than initially excepted (like many other growing projects ;) ), and the current design is not longer suitable for planed features...
So a important step must be a big refactoring to a better design!
This will also result in a API change, because the current API is weird in some aspects and many options are not logical named/ordered/categorized. (I'll offer a deprecated backward compatible API, will warnings as hints for migration)
It's cool that we have a good bunch of tests so that we can test the new design. I'll to add only a few new features with 0.9, but I'll prepare the design for source maps and hot code replacement. It would be good if we could share more code with enhanced-require.
I'll move some stuff out of enhanced-resolve to keep this library more reuseable.
This (API) stuff is weird and will be changed:
loaders
option in theresolve
object?postprocess
is weird. OO-Solution: Extend a factory class.and this (internal) stuff:
I'll post more stuff on progress in the issue, so keep watching
The text was updated successfully, but these errors were encountered: