Skip to content

Commit 3170b76

Browse files
committed
webpack 1.0 beta
moved many options to plugins webpack#113
1 parent 6d7ac9e commit 3170b76

28 files changed

Lines changed: 341 additions & 230 deletions

bin/config-optimist.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ module.exports = function(optimist) {
7373

7474
.string("provide").describe("provide")
7575

76+
.boolean("labeled-modules").describe("labeled-modules")
77+
7678
.string("plugin").describe("plugin")
7779

7880
.boolean("bail").describe("bail")

bin/convert-argv.js

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@ module.exports = function(optimist, argv, convertOptions) {
1818
argv["optimize-occurence-order"] = true;
1919
}
2020

21-
function ifArg(name, fn, init) {
21+
function ifArg(name, fn, init, finalize) {
2222
if(Array.isArray(argv[name])) {
2323
if(init) init();
2424
argv[name].forEach(fn);
25+
if(finalize) finalize();
2526
} else if(typeof argv[name] != "undefined") {
2627
if(init) init();
2728
fn(argv[name], -1);
29+
if(finalize) finalize();
2830
}
2931
}
3032

31-
function ifArgPair(name, fn, init) {
33+
function ifArgPair(name, fn, init, finalize) {
3234
ifArg(name, function(content, idx) {
3335
var i = content.indexOf("=");
3436
if(i < 0) return fn(null, content, idx);
3537
else return fn(content.substr(0, i), content.substr(i+1), idx);
36-
}, init);
38+
}, init, finalize);
3739
}
3840

3941
function ifBooleanArg(name, fn) {
@@ -139,14 +141,19 @@ module.exports = function(optimist, argv, convertOptions) {
139141
ensureArray(options.module, "postLoaders");
140142
});
141143

144+
var defineObject;
142145
ifArgPair("define", function(name, value) {
143146
if(name === null) {
144147
name = value;
145148
value = true;
146149
}
147-
options.define[name] = value;
150+
defineObject[name] = value;
148151
}, function() {
149-
ensureObject(options, "define");
152+
defineObject = {}
153+
}, function() {
154+
ensureArray(options, "plugins");
155+
var DefinePlugin = require("../lib/DefinePlugin");
156+
options.plugins.push(new DefinePlugin(defineObject));
150157
});
151158

152159
ifArg("output-path", function(value) {
@@ -222,7 +229,12 @@ module.exports = function(optimist, argv, convertOptions) {
222229
options.watchDelay = value;
223230
});
224231

225-
mapArgToBoolean("hot", "hot");
232+
ifBooleanArg("hot", function() {
233+
ensureArray(options, "plugins");
234+
var HotModuleReplacementPlugin = require("../lib/HotModuleReplacementPlugin");
235+
options.plugins.push(new HotModuleReplacementPlugin());
236+
});
237+
226238
mapArgToBoolean("debug", "debug");
227239

228240
ifBooleanArg("progress", function() {
@@ -279,45 +291,60 @@ module.exports = function(optimist, argv, convertOptions) {
279291
});
280292

281293
ifArg("optimize-max-chunks", function(value) {
282-
ensureObject(options, "optimize");
283-
options.optimize.maxChunks = parseInt(value, 10);
294+
ensureArray(options, "plugins");
295+
var LimitChunkCountPlugin = require("../lib/optimize/LimitChunkCountPlugin");
296+
options.plugins.push(new LimitChunkCountPlugin({
297+
maxChunks: parseInt(value, 10)
298+
}));
284299
});
285300

286301
ifArg("optimize-min-chunk-size", function(value) {
287-
ensureObject(options, "optimize");
288-
options.optimize.minChunkSize = parseInt(value, 10);
302+
ensureArray(options, "plugins");
303+
var LimitChunkSizePlugin = require("../lib/optimize/LimitChunkSizePlugin");
304+
options.plugins.push(new LimitChunkSizePlugin(parseInt(value, 10)));
289305
});
290306

291307
ifBooleanArg("optimize-minimize", function() {
292-
ensureObject(options, "optimize");
293-
options.optimize.minimize = true;
308+
ensureArray(options, "plugins");
309+
var UglifyJsPlugin = require("../lib/optimize/UglifyJsPlugin");
310+
options.plugins.push(new UglifyJsPlugin());
294311
});
295312

296313
ifBooleanArg("optimize-occurence-order", function() {
297-
ensureObject(options, "optimize");
298-
options.optimize.occurenceOrder = true;
314+
ensureArray(options, "plugins");
315+
var OccurenceOrderPlugin = require("../lib/optimize/OccurenceOrderPlugin");
316+
options.plugins.push(new OccurenceOrderPlugin());
299317
});
300318

301319
ifBooleanArg("optimize-dedupe", function() {
302-
ensureObject(options, "optimize");
303-
options.optimize.dedupe = true;
320+
ensureArray(options, "plugins");
321+
var DedupePlugin = require("../lib/optimize/DedupePlugin");
322+
options.plugins.push(new DedupePlugin());
304323
});
305324

306325
ifArg("prefetch", function(request) {
307-
ensureArray(options, "prefetch");
308-
options.prefetch.push(request);
326+
ensureArray(options, "plugins");
327+
var PrefetchPlugin = require("../lib/PrefetchPlugin");
328+
options.plugins.push(new PrefetchPlugin(request));
309329
});
310330

311331
ifArg("provide", function(value) {
312-
ensureObject(options, "provide");
332+
ensureArray(options, "plugins");
313333
var idx = value.indexOf("=");
314334
if(idx >= 0) {
315335
var name = value.substr(0, idx);
316336
value = value.substr(idx + 1);
317337
} else {
318338
var name = value;
319339
}
320-
options.provide[name] = value;
340+
var ProvidePlugin = require("../lib/ProvidePlugin");
341+
options.plugins.push(new ProvidePlugin(name, value));
342+
});
343+
344+
ifBooleanArg("labeled-modules", function() {
345+
ensureArray(options, "plugins");
346+
var LabeledModulesPlugin = require("../lib/dependencies/LabeledModulesPlugin");
347+
options.plugins.push(new LabeledModulesPlugin());
321348
});
322349

323350
ifArg("plugin", function(value) {
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
var webpack = require("../../");
12
module.exports = {
2-
optimize: {
3-
dedupe: true
4-
}
3+
plugins: [
4+
new webpack.optimize.DedupePlugin()
5+
]
56
}

examples/dedupe/webpack.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
var webpack = require("../../");
12
module.exports = {
2-
optimize: {
3-
dedupe: true
4-
}
3+
plugins: [
4+
new webpack.optimize.DedupePlugin()
5+
]
56
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var webpack = require("../../");
2+
module.exports = {
3+
plugins: [
4+
new webpack.dependencies.LabeledModulesPlugin()
5+
]
6+
}

examples/mixed/webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var webpack = require("../../");
2+
module.exports = {
3+
plugins: [
4+
new webpack.dependencies.LabeledModulesPlugin()
5+
]
6+
}

lib/FunctionModulePlugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
var FunctionModuleTemplate = require("./FunctionModuleTemplate");
66
var RequestShortener = require("./RequestShortener");
77

8-
function FunctionModulePlugin(context, options) {
9-
this.context = context;
8+
function FunctionModulePlugin(options, requestShortener) {
109
this.options = options;
10+
this.requestShortener = requestShortener;
1111
}
1212
module.exports = FunctionModulePlugin;
1313
FunctionModulePlugin.prototype.apply = function(compiler) {
14-
compiler.moduleTemplate = new FunctionModuleTemplate(this.options, new RequestShortener(this.context));
14+
compiler.moduleTemplate = new FunctionModuleTemplate(this.options, this.requestShortener || new RequestShortener(compiler.context));
1515
};

lib/HotModuleReplacementPlugin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ var ModuleHotAcceptDependency = require("./dependencies/ModuleHotAcceptDependenc
88
var ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDependency");
99
var RawSource = require("webpack-core/lib/RawSource");
1010

11-
function HotModuleReplacementPlugin(outputOptions) {
12-
this.outputOptions = outputOptions;
11+
function HotModuleReplacementPlugin() {
1312
}
1413
module.exports = HotModuleReplacementPlugin;
1514

1615
HotModuleReplacementPlugin.prototype.apply = function(compiler) {
17-
var hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
18-
var hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
16+
var hotUpdateChunkFilename = compiler.options.output.hotUpdateChunkFilename;
17+
var hotUpdateMainFilename = compiler.options.output.hotUpdateMainFilename;
1918
compiler.plugin("compilation", function(compilation, params) {
2019
var hotUpdateChunkTemplate = compilation.compiler.hotUpdateChunkTemplate;
2120
if(!hotUpdateChunkTemplate && !compilation.mainTemplate.renderHotModuleReplacementInit) return;

lib/MovedToPluginWarningPlugin.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
function MovedToPluginWarningPlugin(optionName, pluginName) {
6+
this.optionName = optionName;
7+
this.pluginName = pluginName
8+
}
9+
module.exports = MovedToPluginWarningPlugin;
10+
11+
MovedToPluginWarningPlugin.prototype.apply = function(compiler) {
12+
var optionName = this.optionName;
13+
var pluginName = this.pluginName
14+
compiler.plugin("compilation", function(compilation) {
15+
compilation.warnings.push(new Error("webpack options:\nDEPRECATED option '" + optionName + "' will be moved to the " + pluginName + ". Use this by now.\nFor more info about the usage of the " + pluginName + " see https://github.com/webpack/docs/wiki/webpack-plugins"));
16+
});
17+
};

lib/NoHotModuleReplacementPlugin.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)