Merge tag 'v4.17.0' into next

4.17.0
This commit is contained in:
Tobias Koppers 2018-08-21 11:02:16 +02:00
commit c21d59f783
63 changed files with 362 additions and 82 deletions

View File

@ -58,8 +58,6 @@ yarn add webpack --dev
<h2 align="center">Introduction</h2>
> This README reflects webpack v2.x and v3.x. The webpack v1.x documentation has been deprecated and deleted.
webpack is a bundler for modules. The main purpose is to bundle JavaScript
files for usage in a browser, yet it is also capable of transforming, bundling,
or packaging just about any resource or asset.

View File

@ -31,7 +31,7 @@ class CompatibilityPlugin {
.for("javascript/auto")
.tap("CompatibilityPlugin", (parser, parserOptions) => {
if (
typeof parserOptions.browserify !== "undefined" &&
parserOptions.browserify !== undefined &&
!parserOptions.browserify
)
return;

View File

@ -61,13 +61,13 @@ class ContextReplacementPlugin {
cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", result => {
if (!result) return;
if (resourceRegExp.test(result.request)) {
if (typeof newContentResource !== "undefined") {
if (newContentResource !== undefined) {
result.request = newContentResource;
}
if (typeof newContentRecursive !== "undefined") {
if (newContentRecursive !== undefined) {
result.recursive = newContentRecursive;
}
if (typeof newContentRegExp !== "undefined") {
if (newContentRegExp !== undefined) {
result.regExp = newContentRegExp;
}
if (typeof newContentCallback === "function") {
@ -83,13 +83,13 @@ class ContextReplacementPlugin {
cmf.hooks.afterResolve.tap("ContextReplacementPlugin", result => {
if (!result) return;
if (resourceRegExp.test(result.resource)) {
if (typeof newContentResource !== "undefined") {
if (newContentResource !== undefined) {
result.resource = path.resolve(result.resource, newContentResource);
}
if (typeof newContentRecursive !== "undefined") {
if (newContentRecursive !== undefined) {
result.recursive = newContentRecursive;
}
if (typeof newContentRegExp !== "undefined") {
if (newContentRegExp !== undefined) {
result.regExp = newContentRegExp;
}
if (typeof newContentCreateContextMap === "function") {

View File

@ -60,7 +60,7 @@ class EnvironmentPlugin {
}
defs[`process.env.${key}`] =
typeof value === "undefined" ? "undefined" : JSON.stringify(value);
value === undefined ? "undefined" : JSON.stringify(value);
return defs;
}, {});

View File

@ -28,7 +28,7 @@ class ExternalModuleFactoryPlugin {
}
if (value === false) return factory(data, callback);
if (value === true) value = dependency.request;
if (typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
if (type === undefined && /^[a-z0-9]+ /.test(value)) {
const idx = value.indexOf(" ");
type = value.substr(0, idx);
value = value.substr(idx + 1);
@ -82,7 +82,7 @@ class ExternalModuleFactoryPlugin {
dependency.request,
(err, value, type) => {
if (err) return callback(err);
if (typeof value !== "undefined") {
if (value !== undefined) {
handleExternal(value, type, callback);
} else {
callback();

View File

@ -109,7 +109,7 @@ module.exports = function() {
// Module API
active: true,
accept: function(dep, callback) {
if (typeof dep === "undefined") hot._selfAccepted = true;
if (dep === undefined) hot._selfAccepted = true;
else if (typeof dep === "function") hot._selfAccepted = dep;
else if (typeof dep === "object" && dep !== null)
for (var i = 0; i < dep.length; i++)
@ -117,7 +117,7 @@ module.exports = function() {
else hot._acceptedDependencies[dep] = callback || function() {};
},
decline: function(dep) {
if (typeof dep === "undefined") hot._selfDeclined = true;
if (dep === undefined) hot._selfDeclined = true;
else if (typeof dep === "object" && dep !== null)
for (var i = 0; i < dep.length; i++)
hot._declinedDependencies[dep[i]] = true;

View File

@ -5,18 +5,30 @@
"use strict";
const validateOptions = require("schema-utils");
const schema = require("../schemas/plugins/IgnorePlugin.json");
/** @typedef {import("./Compiler")} Compiler */
class IgnorePlugin {
/**
* @param {RegExp} resourceRegExp A RegExp to test the request against
* @param {RegExp=} contextRegExp A RegExp to test the context (directory) against
* @param {object} options IgnorePlugin options
* @param {RegExp} options.resourceRegExp - A RegExp to test the request against
* @param {RegExp} options.contextRegExp - A RegExp to test the context (directory) against
* @param {function(string): boolean=} options.checkResource - A filter function for resource
* @param {function(string): boolean=} options.checkContext - A filter function for context
*/
constructor(resourceRegExp, contextRegExp) {
/** @private @type {RegExp} */
this.resourceRegExp = resourceRegExp;
/** @private @type {RegExp} */
this.contextRegExp = contextRegExp;
constructor(options) {
// TODO webpack 5 remove this compat-layer
if (arguments.length > 1 || options instanceof RegExp) {
options = {
resourceRegExp: arguments[0],
contextRegExp: arguments[1]
};
}
validateOptions(schema, options, "IgnorePlugin");
this.options = options;
/** @private @type {Function} */
this.checkIgnore = this.checkIgnore.bind(this);
@ -28,10 +40,13 @@ class IgnorePlugin {
* and the resource given matches the regexp.
*/
checkResource(resource) {
if (!this.resourceRegExp) {
if (this.options.checkResource) {
return this.options.checkResource(resource);
}
if (!this.options.resourceRegExp) {
return false;
}
return this.resourceRegExp.test(resource);
return this.options.resourceRegExp.test(resource);
}
/**
@ -40,10 +55,14 @@ class IgnorePlugin {
* or if context matches the given regexp.
*/
checkContext(context) {
if (!this.contextRegExp) {
if (this.options.checkContext) {
return this.options.checkContext(context);
}
if (!this.options.contextRegExp) {
return true;
}
return this.contextRegExp.test(context);
return this.options.contextRegExp.test(context);
}
/**

View File

@ -189,6 +189,8 @@ class JavascriptModulesPlugin {
const template = chunk.hasRuntime()
? compilation.mainTemplate
: compilation.chunkTemplate;
hash.update(`${chunk.id} `);
hash.update(chunk.ids ? chunk.ids.join(",") : "");
template.updateHashForChunk(hash, chunk);
for (const m of chunkGraph.getOrderedChunkModulesIterable(
chunk,

View File

@ -31,7 +31,7 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
if (idx === accessors.length - 1) return a;
if (idx === 0 && typeof base === "undefined") {
if (idx === 0 && base === undefined) {
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
}
return `${a} = ${a} || {}`;

View File

@ -41,11 +41,11 @@ class MultiStats {
return obj;
});
const showVersion =
typeof options.version === "undefined"
options.version === undefined
? jsons.every(j => j.version)
: options.version !== false;
const showHash =
typeof options.hash === "undefined"
options.hash === undefined
? jsons.every(j => j.hash)
: options.hash !== false;
if (showVersion) {

View File

@ -17,8 +17,7 @@ const getProperty = (obj, name) => {
const setProperty = (obj, name, value) => {
name = name.split(".");
for (let i = 0; i < name.length - 1; i++) {
if (typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined")
return;
if (typeof obj[name[i]] !== "object" && obj[name[i]] !== undefined) return;
if (Array.isArray(obj[name[i]])) return;
if (!obj[name[i]]) obj[name[i]] = {};
obj = obj[name[i]];

View File

@ -24,7 +24,7 @@ module.exports = class RequireJsStuffPlugin {
);
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireJs === "undefined" ||
parserOptions.requireJs === undefined ||
!parserOptions.requireJs
) {
return;

View File

@ -21,7 +21,7 @@ const identifierUtils = require("./util/identifier");
const optionsOrFallback = (...args) => {
let optionValues = [];
optionValues.push(...args);
return optionValues.find(optionValue => typeof optionValue !== "undefined");
return optionValues.find(optionValue => optionValue !== undefined);
};
class Stats {
@ -110,11 +110,7 @@ class Stats {
}
const optionOrLocalFallback = (v, def) =>
typeof v !== "undefined"
? v
: typeof options.all !== "undefined"
? options.all
: def;
v !== undefined ? v : options.all !== undefined ? options.all : def;
const testAgainstGivenOption = item => {
if (typeof item === "string") {

View File

@ -35,7 +35,7 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
if (idx === accessors.length - 1) return a;
if (idx === 0 && typeof base === "undefined")
if (idx === 0 && base === undefined)
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
return `${a} = ${a} || {}`;
})
@ -161,7 +161,7 @@ class UmdMainTemplatePlugin {
if (typeof request === "object") {
request = request[type];
}
if (typeof request === "undefined") {
if (request === undefined) {
throw new Error(
"Missing external configuration for type:" + type
);

View File

@ -7,7 +7,15 @@
const WebpackError = require("./WebpackError");
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("./Module")} Module */
class UnsupportedFeatureWarning extends WebpackError {
/**
* @param {Module} module module relevant to warning
* @param {string} message description of warning
* @param {DependencyLocation} loc location start and end positions of the module
*/
constructor(module, message, loc) {
super(message);

View File

@ -104,8 +104,7 @@ class AMDPlugin {
);
const handler = (parser, parserOptions) => {
if (typeof parserOptions.amd !== "undefined" && !parserOptions.amd)
return;
if (parserOptions.amd !== undefined && !parserOptions.amd) return;
const setExpressionToModule = (outerExpr, module) => {
parser.hooks.expression.for(outerExpr).tap("AMDPlugin", expr => {

View File

@ -89,10 +89,7 @@ class CommonJsPlugin {
);
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.commonjs !== "undefined" &&
!parserOptions.commonjs
)
if (parserOptions.commonjs !== undefined && !parserOptions.commonjs)
return;
const requireExpressions = [

View File

@ -113,10 +113,7 @@ class HarmonyModulesPlugin {
);
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.harmony !== "undefined" &&
!parserOptions.harmony
)
if (parserOptions.harmony !== undefined && !parserOptions.harmony)
return;
new HarmonyDetectionParserPlugin().apply(parser);

View File

@ -55,7 +55,7 @@ class ImportParserPlugin {
}
if (importOptions) {
if (typeof importOptions.webpackIgnore !== "undefined") {
if (importOptions.webpackIgnore !== undefined) {
if (typeof importOptions.webpackIgnore !== "boolean") {
parser.state.module.warnings.push(
new UnsupportedFeatureWarning(
@ -73,7 +73,7 @@ class ImportParserPlugin {
}
}
}
if (typeof importOptions.webpackChunkName !== "undefined") {
if (importOptions.webpackChunkName !== undefined) {
if (typeof importOptions.webpackChunkName !== "string") {
parser.state.module.warnings.push(
new UnsupportedFeatureWarning(
@ -88,7 +88,7 @@ class ImportParserPlugin {
chunkName = importOptions.webpackChunkName;
}
}
if (typeof importOptions.webpackMode !== "undefined") {
if (importOptions.webpackMode !== undefined) {
if (typeof importOptions.webpackMode !== "string") {
parser.state.module.warnings.push(
new UnsupportedFeatureWarning(
@ -103,7 +103,7 @@ class ImportParserPlugin {
mode = importOptions.webpackMode;
}
}
if (typeof importOptions.webpackPrefetch !== "undefined") {
if (importOptions.webpackPrefetch !== undefined) {
if (importOptions.webpackPrefetch === true) {
groupOptions.prefetchOrder = 0;
} else if (typeof importOptions.webpackPrefetch === "number") {
@ -120,7 +120,7 @@ class ImportParserPlugin {
);
}
}
if (typeof importOptions.webpackPreload !== "undefined") {
if (importOptions.webpackPreload !== undefined) {
if (importOptions.webpackPreload === true) {
groupOptions.preloadOrder = 0;
} else if (typeof importOptions.webpackPreload === "number") {
@ -137,7 +137,7 @@ class ImportParserPlugin {
);
}
}
if (typeof importOptions.webpackInclude !== "undefined") {
if (importOptions.webpackInclude !== undefined) {
if (
!importOptions.webpackInclude ||
importOptions.webpackInclude.constructor.name !== "RegExp"
@ -155,7 +155,7 @@ class ImportParserPlugin {
include = new RegExp(importOptions.webpackInclude);
}
}
if (typeof importOptions.webpackExclude !== "undefined") {
if (importOptions.webpackExclude !== undefined) {
if (
!importOptions.webpackExclude ||
importOptions.webpackExclude.constructor.name !== "RegExp"

View File

@ -58,10 +58,7 @@ class ImportPlugin {
);
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.import !== "undefined" &&
!parserOptions.import
)
if (parserOptions.import !== undefined && !parserOptions.import)
return;
new ImportParserPlugin(options).apply(parser);

View File

@ -43,7 +43,7 @@ class RequireContextPlugin {
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireContext !== "undefined" &&
parserOptions.requireContext !== undefined &&
!parserOptions.requireContext
)
return;

View File

@ -42,7 +42,7 @@ class RequireEnsurePlugin {
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireEnsure !== "undefined" &&
parserOptions.requireEnsure !== undefined &&
!parserOptions.requireEnsure
)
return;

View File

@ -29,7 +29,7 @@ class RequireIncludePlugin {
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireInclude !== "undefined" &&
parserOptions.requireInclude !== undefined &&
!parserOptions.requireInclude
)
return;

View File

@ -34,10 +34,7 @@ class SystemPlugin {
);
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.system === "undefined" ||
!parserOptions.system
) {
if (parserOptions.system === undefined || !parserOptions.system) {
return;
}

View File

@ -152,6 +152,9 @@ const getFinalName = (
} else if (!info.module.isExportUsed(moduleGraph, exportName)) {
return "/* unused export */ undefined";
}
if (info.globalExports.has(directExport)) {
return directExport;
}
const name = info.internalNames.get(directExport);
if (!name) {
throw new Error(
@ -285,7 +288,7 @@ const getPathInAst = (ast, node) => {
if (Array.isArray(ast)) {
for (i = 0; i < ast.length; i++) {
const enterResult = enterNode(ast[i]);
if (typeof enterResult !== "undefined") return enterResult;
if (enterResult !== undefined) return enterResult;
}
} else if (ast && typeof ast === "object") {
const keys = Object.keys(ast);
@ -293,10 +296,10 @@ const getPathInAst = (ast, node) => {
const value = ast[keys[i]];
if (Array.isArray(value)) {
const pathResult = getPathInAst(value, node);
if (typeof pathResult !== "undefined") return pathResult;
if (pathResult !== undefined) return pathResult;
} else if (value && typeof value === "object") {
const enterResult = enterNode(value);
if (typeof enterResult !== "undefined") return enterResult;
if (enterResult !== undefined) return enterResult;
}
}
}
@ -609,6 +612,7 @@ class ConcatenatedModule extends Module {
globalScope: undefined,
moduleScope: undefined,
internalNames: new Map(),
globalExports: new Set(),
exportMap: exportMap,
reexportMap: reexportMap,
hasNamespaceObject: false,
@ -990,6 +994,19 @@ class ConcatenatedModule extends Module {
}
}
}
// add exported globals
if (info.type === "concatenated") {
const variables = new Set();
for (const variable of info.moduleScope.variables) {
variables.add(variable.name);
}
for (const [, variable] of info.exportMap) {
if (!variables.has(variable)) {
info.globalExports.add(variable);
}
}
}
}
// generate names for symbols

View File

@ -65,13 +65,13 @@ exports.makePathsRelative = (context, identifier, cache) => {
let cachedResult;
let contextCache = relativePaths.get(context);
if (typeof contextCache === "undefined") {
if (contextCache === undefined) {
relativePaths.set(context, (contextCache = new Map()));
} else {
cachedResult = contextCache.get(identifier);
}
if (typeof cachedResult !== "undefined") {
if (cachedResult !== undefined) {
return cachedResult;
} else {
const relativePath = _makePathsRelative(context, identifier);

View File

@ -117,7 +117,7 @@ const getCountImportedFunc = ast => {
const getNextTypeIndex = ast => {
const typeSectionMetadata = t.getSectionMetadata(ast, "type");
if (typeof typeSectionMetadata === "undefined") {
if (typeSectionMetadata === undefined) {
return t.indexLiteral(0);
}
@ -138,7 +138,7 @@ const getNextTypeIndex = ast => {
const getNextFuncIndex = (ast, countImportedFunc) => {
const funcSectionMetadata = t.getSectionMetadata(ast, "func");
if (typeof funcSectionMetadata === "undefined") {
if (funcSectionMetadata === undefined) {
return t.indexLiteral(0 + countImportedFunc);
}
@ -280,7 +280,7 @@ const rewriteImports = ({ ast, usedDependencyMap }) => bin => {
path.node.module + ":" + path.node.name
);
if (typeof result !== "undefined") {
if (result !== undefined) {
path.node.module = result.module;
path.node.name = result.name;
}

View File

@ -0,0 +1,31 @@
{
"type": "object",
"oneOf": [
{
"additionalProperties": false,
"properties": {
"resourceRegExp": {
"description": "A RegExp to test the request against",
"instanceof": "RegExp"
},
"contextRegExp": {
"description": "A RegExp to test the context (directory) against",
"instanceof": "RegExp"
}
}
},
{
"additionalProperties": false,
"properties": {
"checkResource": {
"description": "A filter function for resource",
"instanceof": "Function"
},
"checkContext": {
"description": "A filter function for context",
"instanceof": "Function"
}
}
}
]
}

View File

@ -47,7 +47,7 @@ function checkSymlinkExistsAsync() {
}
function ensureYarnInstalledAsync() {
var semverPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/;
const semverPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/;
return execGetOutput("yarn", ["-v"], "Check yarn version")
.then(stdout => semverPattern.test(stdout), () => false)
.then(hasYarn => hasYarn || installYarnAsync());

View File

@ -62,7 +62,7 @@ Please follow the approach described bellow:
* jest will automatically add the output from your test code to ```StatsTestCases.test.js.snap``` and you can always check your results there
* Next time test will run -> runner will compare results against your output written to snapshot previously
You can read more about SnapShot testing [right here](https://facebook.github.io/jest/docs/en/snapshot-testing.html)
You can read more about SnapShot testing [right here](https://jestjs.io/docs/snapshot-testing)
## Questions? Comments?
If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on!

View File

@ -0,0 +1 @@
module.exports = "chunk";

View File

@ -0,0 +1,5 @@
it("should compile and run the test", function () {});
if(Math.random() < -1) {
import(/* webpackChunkName: "chunk" */ "./chunk");
}

View File

@ -0,0 +1,32 @@
var fs = require("fs");
var findFile = function(files, regex) {
return files.find(function(file) {
if (regex.test(file)) {
return true;
}
});
};
const allFilenameHashes = new Set();
const allChunkHashes = new Set();
module.exports = {
findBundle: function(i, options) {
var files = fs.readdirSync(options.output.path);
const filename = findFile(files, new RegExp(`^bundle${i}`));
const filenameHash = /\.([a-f0-9]+)\.js$/.exec(filename)[1];
allFilenameHashes.add(filenameHash);
const chunk = findFile(files, new RegExp(`^chunk${i}`));
const chunkHash = /\.([a-f0-9]+)\.js$/.exec(chunk)[1];
allChunkHashes.add(chunkHash);
return "./" + filename;
},
afterExecute: () => {
expect(allFilenameHashes.size).toBe(2);
expect(allChunkHashes.size).toBe(2);
}
};

View File

@ -0,0 +1,26 @@
module.exports = [
{
mode: "production",
name: "normal-ids",
output: {
filename: "bundle0.[contenthash:6].js",
chunkFilename: "chunk0.[contenthash:6].js"
},
optimization: {
chunkIds: "size",
moduleIds: "named"
}
},
{
mode: "production",
name: "normal-ids",
output: {
filename: "bundle1.[contenthash:6].js",
chunkFilename: "chunk1.[contenthash:6].js"
},
optimization: {
chunkIds: "named",
moduleIds: "named"
}
}
];

View File

@ -8,5 +8,9 @@ module.exports = {
output: {
filename: "[name].js"
},
plugins: [new IgnorePlugin(new RegExp(/intentionally-missing-module/))]
plugins: [
new IgnorePlugin({
resourceRegExp: new RegExp(/intentionally-missing-module/)
})
]
};

View File

@ -0,0 +1 @@
module.exports = "ignored";

View File

@ -0,0 +1 @@
module.exports = require("./normal-module");

View File

@ -0,0 +1 @@
module.exports = "ignored";

View File

@ -0,0 +1 @@
module.exports = require("./ignored-module");

View File

@ -0,0 +1 @@
module.exports = "should be fine";

View File

@ -0,0 +1 @@
module.exports = require("./only-context-match-require");

View File

@ -0,0 +1,20 @@
/* globals it */
"use strict";
it("should ignore resources that match resource regex and context", function() {
expect(function() {
require("./folder-b/normal-module");
}).toThrowError();
});
it("should not ignore resources that match resource but not context", function() {
expect(function() {
require("./folder-a/normal-module");
}).not.toThrowError();
});
it("should not ignore resources that do not match resource but do match context", function() {
expect(function() {
require("./folder-b/only-context-match");
}).not.toThrowError();
});

View File

@ -0,0 +1,17 @@
"use strict";
const IgnorePlugin = require("../../../../lib/IgnorePlugin");
module.exports = {
entry: "./test.js",
plugins: [
new IgnorePlugin({
checkResource: function(resource) {
return /ignored-module/.test(resource);
},
checkContext: function(context) {
return /folder-b/.test(context);
}
})
]
};

View File

@ -0,0 +1 @@
module.exports = "ignored";

View File

@ -0,0 +1 @@
module.exports = "normal";

View File

@ -0,0 +1,13 @@
/* globals it */
"use strict";
it("should ignore ignored resources", function() {
expect(function() {
require("./ignored-module");
}).toThrowError();
});
it("should not ignore resources that do not match", function() {
expect(function() {
require("./normal-module");
}).not.toThrowError();
});

View File

@ -0,0 +1,14 @@
"use strict";
const IgnorePlugin = require("../../../../lib/IgnorePlugin");
module.exports = {
entry: "./test.js",
plugins: [
new IgnorePlugin({
checkResource: function(resource) {
return /ignored-module/.test(resource);
}
})
]
};

View File

@ -0,0 +1 @@
module.exports = "ignored";

View File

@ -0,0 +1 @@
module.exports = require("./normal-module");

View File

@ -0,0 +1 @@
module.exports = "ignored";

View File

@ -0,0 +1 @@
module.exports = require("./ignored-module");

View File

@ -0,0 +1 @@
module.exports = "should be fine";

View File

@ -0,0 +1 @@
module.exports = require("./only-context-match-require");

View File

@ -0,0 +1,36 @@
/* globals it */
"use strict";
// TODO: remove in webpack 5
it("should ignore context modules that match resource regex and context (compat-layer)", function() {
const folderBContext = function(mod) {
require("./folder-b/" + mod);
};
expect(function() {
folderBContext("normal-module");
}).toThrowError();
});
it("should not ignore context modules that dont match the resource (compat-layer)", function() {
const folderBContext = function(mod) {
require("./folder-b/" + mod);
};
expect(function() {
folderBContext("only-context-match");
}).not.toThrowError();
});
it("should not ignore context modules that dont match the context (compat-layer)", function() {
const folderBContext = function(mod) {
require("./folder-a/" + mod);
};
expect(function() {
folderBContext("normal-module");
}).not.toThrowError();
expect(function() {
folderBContext("ignored-module");
}).not.toThrowError();
});

View File

@ -0,0 +1,8 @@
"use strict";
const IgnorePlugin = require("../../../../lib/IgnorePlugin");
module.exports = {
entry: "./test.js",
plugins: [new IgnorePlugin(/ignored-module/, /folder-b/)]
};

View File

@ -4,5 +4,9 @@ const IgnorePlugin = require("../../../../lib/IgnorePlugin");
module.exports = {
entry: "./test.js",
plugins: [new IgnorePlugin(/ignored-module/)]
plugins: [
new IgnorePlugin({
resourceRegExp: /ignored-module/
})
]
};

View File

@ -4,5 +4,9 @@ const IgnorePlugin = require("../../../../lib/IgnorePlugin");
module.exports = {
entry: "./test.js",
plugins: [new IgnorePlugin(/ignored-module/)]
plugins: [
new IgnorePlugin({
resourceRegExp: /ignored-module/
})
]
};

View File

@ -4,5 +4,10 @@ const IgnorePlugin = require("../../../../lib/IgnorePlugin");
module.exports = {
entry: "./test.js",
plugins: [new IgnorePlugin(/ignored-module/, /folder-b/)]
plugins: [
new IgnorePlugin({
resourceRegExp: /ignored-module/,
contextRegExp: /folder-b/
})
]
};

View File

@ -4,5 +4,10 @@ const IgnorePlugin = require("../../../../lib/IgnorePlugin");
module.exports = {
entry: "./test.js",
plugins: [new IgnorePlugin(/ignored-module/, /folder-b/)]
plugins: [
new IgnorePlugin({
resourceRegExp: /ignored-module/,
contextRegExp: /folder-b/
})
]
};

View File

@ -0,0 +1,7 @@
import { process as p } from "./module";
import { process as p2 } from "./module2";
it("should export globals correctly", () => {
expect(p).toBe(42);
expect(p2).toBe(process);
});

View File

@ -0,0 +1,2 @@
const process = 42;
export { process };

View File

@ -0,0 +1 @@
export { process };

View File

@ -0,0 +1,5 @@
module.exports = {
optimization: {
concatenateModules: true
}
};