mirror of https://github.com/webpack/webpack.git
integrate the delegated module better into the exports flagging process
This commit is contained in:
parent
c8732c8d15
commit
9dbed7360d
|
|
@ -9,6 +9,7 @@ const OriginalSource = require("webpack-sources").OriginalSource;
|
|||
const RawSource = require("webpack-sources").RawSource;
|
||||
const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
||||
|
||||
class DelegatedModule extends Module {
|
||||
constructor(sourceRequest, data, type, userRequest, originalRequest) {
|
||||
|
|
@ -44,10 +45,9 @@ class DelegatedModule extends Module {
|
|||
this.built = true;
|
||||
this.builtTime = Date.now();
|
||||
this.cacheable = true;
|
||||
this.usedExports = true;
|
||||
this.providedExports = this.delegateData.exports || true;
|
||||
this.dependencies.length = 0;
|
||||
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
|
||||
this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true));
|
||||
callback();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
class DelegatedPlugin {
|
||||
constructor(options) {
|
||||
|
|
@ -16,6 +18,7 @@ class DelegatedPlugin {
|
|||
apply(compiler) {
|
||||
compiler.plugin("compilation", (compilation, params) => {
|
||||
compilation.dependencyFactories.set(DelegatedSourceDependency, params.normalModuleFactory);
|
||||
compilation.dependencyFactories.set(DelegatedExportsDependency, new NullFactory());
|
||||
});
|
||||
|
||||
compiler.plugin("compile", (params) => {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
|
||||
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
class DllReferencePlugin {
|
||||
constructor(options) {
|
||||
|
|
@ -17,6 +19,7 @@ class DllReferencePlugin {
|
|||
compiler.plugin("compilation", (compilation, params) => {
|
||||
const normalModuleFactory = params.normalModuleFactory;
|
||||
compilation.dependencyFactories.set(DelegatedSourceDependency, normalModuleFactory);
|
||||
compilation.dependencyFactories.set(DelegatedExportsDependency, new NullFactory());
|
||||
});
|
||||
|
||||
compiler.plugin("before-compile", (params, callback) => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
const NullDependency = require("./NullDependency");
|
||||
|
||||
class DelegatedExportsDependency extends NullDependency {
|
||||
constructor(originModule, exports) {
|
||||
super();
|
||||
this.originModule = originModule;
|
||||
this.exports = exports;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "delegated exports";
|
||||
}
|
||||
|
||||
getReference() {
|
||||
return {
|
||||
module: this.originModule,
|
||||
importedNames: true
|
||||
};
|
||||
}
|
||||
|
||||
getExports() {
|
||||
return {
|
||||
exports: this.exports
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DelegatedExportsDependency;
|
||||
|
|
@ -116,6 +116,10 @@ describe("WatchTestCases", () => {
|
|||
const watching = compiler.watch({
|
||||
aggregateTimeout: 1000
|
||||
}, (err, stats) => {
|
||||
if(err)
|
||||
return done(err);
|
||||
if(!stats)
|
||||
return done(new Error("No stats reported from Compiler"));
|
||||
if(stats.hash === lastHash)
|
||||
return;
|
||||
lastHash = stats.hash;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
import value from "dll/module";
|
||||
|
||||
it("should have the correct default export", function() {
|
||||
value.should.be.eql("ok");
|
||||
});
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import value from "dll/module";
|
||||
|
||||
it("should have still the correct default export", function() {
|
||||
value.should.be.eql("ok");
|
||||
});
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
var webpack = require("../../../../");
|
||||
module.exports = {
|
||||
plugins: [
|
||||
new webpack.DllReferencePlugin({
|
||||
name: "function(id) { return {default: 'ok'}; }",
|
||||
scope: "dll",
|
||||
content: {
|
||||
"./module": {
|
||||
id: 1,
|
||||
meta: {
|
||||
harmonyModule: true
|
||||
},
|
||||
exports: ["default"]
|
||||
}
|
||||
}
|
||||
}),
|
||||
new webpack.optimize.ModuleConcatenationPlugin()
|
||||
]
|
||||
};
|
||||
Loading…
Reference in New Issue