Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/webpack/webpack into Contex…
Browse files Browse the repository at this point in the history
…tExclusionPlugin-types
  • Loading branch information
mohsen1 committed Jul 17, 2018
2 parents d3bbb6d + fa02f3d commit b3a7c4d
Show file tree
Hide file tree
Showing 19 changed files with 1,435 additions and 1,457 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -92,16 +92,19 @@ within webpack itself use this plugin interface. This makes webpack very

|Name|Status|Install Size|Description|
|:--:|:----:|:----------:|:----------|
|[extract-text-webpack-plugin][extract]|![extract-npm]|![extract-size]|Extracts Text (CSS) from your bundles into a separate file (app.bundle.css)|
|[mini-css-extract-plugin][mini-css]|![mini-css-npm]|![mini-css-size]|Extracts CSS into separate files. It creates a CSS file per JS file which contains CSS.|
|[compression-webpack-plugin][compression]|![compression-npm]|![compression-size]|Prepares compressed versions of assets to serve them with Content-Encoding|
|[i18n-webpack-plugin][i18n]|![i18n-npm]|![i18n-size]|Adds i18n support to your bundles|
|[html-webpack-plugin][html-plugin]|![html-plugin-npm]|![html-plugin-size]| Simplifies creation of HTML files (`index.html`) to serve your bundles|

|[extract-text-webpack-plugin][extract]|![extract-npm]|![extract-size]|Extract text from a bundle, or bundles, into a separate file|

[common-npm]: https://img.shields.io/npm/v/webpack.svg
[extract]: https://github.com/webpack/extract-text-webpack-plugin
[extract-npm]: https://img.shields.io/npm/v/extract-text-webpack-plugin.svg
[extract-size]: https://packagephobia.now.sh/badge?p=extract-text-webpack-plugin
[mini-css]: https://github.com/webpack-contrib/mini-css-extract-plugin
[mini-css-npm]: https://img.shields.io/npm/v/mini-css-extract-plugin.svg
[mini-css-size]: https://packagephobia.now.sh/badge?p=mini-css-extract-plugin
[component]: https://github.com/webpack/component-webpack-plugin
[component-npm]: https://img.shields.io/npm/v/component-webpack-plugin.svg
[component-size]: https://packagephobia.now.sh/badge?p=component-webpack-plugin
Expand Down
1 change: 1 addition & 0 deletions lib/Compilation.js
Expand Up @@ -888,6 +888,7 @@ class Compilation extends Tapable {
// leaking the Compilation object.

if (err) {
// eslint-disable-next-line no-self-assign
err.stack = err.stack;
return callback(err);
}
Expand Down
49 changes: 49 additions & 0 deletions lib/DefinePlugin.js
Expand Up @@ -9,6 +9,11 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
const ParserHelpers = require("./ParserHelpers");
const NullFactory = require("./NullFactory");

/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./Parser")} Parser */
/** @typedef {null|undefined|RegExp|Function|string|number} CodeValuePrimitive */
/** @typedef {CodeValuePrimitive|Record<string, CodeValuePrimitive>|RuntimeValue} CodeValue */

class RuntimeValue {
constructor(fn, fileDependencies) {
this.fn = fn;
Expand Down Expand Up @@ -37,6 +42,12 @@ const stringifyObj = (obj, parser) => {
);
};

/**
* Convert code to a string that evaluates
* @param {CodeValue} code Code to evaluate
* @param {Parser} parser Parser
* @returns {string} code converted to string that evaluates
*/
const toCode = (code, parser) => {
if (code === null) {
return "null";
Expand All @@ -60,6 +71,10 @@ const toCode = (code, parser) => {
};

class DefinePlugin {
/**
* Create a new define plugin
* @param {Record<string, CodeValue>} definitions A map of global object definitions
*/
constructor(definitions) {
this.definitions = definitions;
}
Expand All @@ -68,6 +83,11 @@ class DefinePlugin {
return new RuntimeValue(fn, fileDependencies);
}

/**
* Apply the plugin
* @param {Compiler} compiler Webpack compiler
* @returns {void}
*/
apply(compiler) {
const definitions = this.definitions;
compiler.hooks.compilation.tap(
Expand All @@ -79,7 +99,18 @@ class DefinePlugin {
new ConstDependency.Template()
);

/**
* Handler
* @param {Parser} parser Parser
* @returns {void}
*/
const handler = parser => {
/**
* Walk definitions
* @param {Object} definitions Definitions map
* @param {string} prefix Prefix string
* @returns {void}
*/
const walkDefinitions = (definitions, prefix) => {
Object.keys(definitions).forEach(key => {
const code = definitions[key];
Expand All @@ -98,6 +129,12 @@ class DefinePlugin {
});
};

/**
* Apply define key
* @param {string} prefix Prefix
* @param {string} key Key
* @returns {void}
*/
const applyDefineKey = (prefix, key) => {
const splittedKey = key.split(".");
splittedKey.slice(1).forEach((_, i) => {
Expand All @@ -108,6 +145,12 @@ class DefinePlugin {
});
};

/**
* Apply Code
* @param {string} key Key
* @param {CodeValue} code Code
* @returns {void}
*/
const applyDefine = (key, code) => {
const isTypeof = /^typeof\s+/.test(key);
if (isTypeof) key = key.replace(/^typeof\s+/, "");
Expand Down Expand Up @@ -181,6 +224,12 @@ class DefinePlugin {
});
};

/**
* Apply Object
* @param {string} key Key
* @param {Object} obj Object
* @returns {void}
*/
const applyObjectDefine = (key, obj) => {
parser.hooks.canRename
.for(key)
Expand Down
2 changes: 1 addition & 1 deletion lib/optimize/OccurrenceChunkOrderPlugin.js
Expand Up @@ -49,7 +49,7 @@ class OccurrenceOrderChunkIdsPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down
2 changes: 1 addition & 1 deletion lib/optimize/OccurrenceModuleOrderPlugin.js
Expand Up @@ -91,7 +91,7 @@ class OccurrenceOrderModuleIdsPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/optimize/OccurrenceOrderPlugin.js
Expand Up @@ -91,7 +91,7 @@ class OccurrenceOrderPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down Expand Up @@ -124,7 +124,7 @@ class OccurrenceOrderPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down
14 changes: 7 additions & 7 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "webpack",
"version": "4.16.0",
"version": "4.16.1",
"author": "Tobias Koppers @sokra",
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"license": "MIT",
Expand All @@ -16,7 +16,7 @@
"ajv-keywords": "^3.1.0",
"chrome-trace-event": "^1.0.0",
"enhanced-resolve": "^4.1.0",
"eslint-scope": "^3.7.1",
"eslint-scope": "^4.0.0",
"json-parse-better-errors": "^1.0.2",
"loader-runner": "^2.3.0",
"loader-utils": "^1.1.0",
Expand All @@ -43,11 +43,11 @@
"coveralls": "^2.11.2",
"css-loader": "^0.28.3",
"es6-promise-polyfill": "^1.1.1",
"eslint": "^4.19.1",
"eslint": "^5.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-prettier": "^2.6.2",
"express": "~4.13.1",
"file-loader": "^1.1.6",
"glob": "^7.1.2",
Expand All @@ -61,9 +61,9 @@
"json-loader": "^0.5.7",
"less": "^2.5.1",
"less-loader": "^4.0.3",
"lint-staged": "^7.1.0",
"lint-staged": "^7.2.0",
"lodash": "^4.17.4",
"prettier": "^1.13.5",
"prettier": "^1.13.7",
"pug": "^2.0.3",
"pug-loader": "^2.4.0",
"raw-loader": "~0.5.0",
Expand All @@ -73,7 +73,7 @@
"script-loader": "~0.7.0",
"simple-git": "^1.65.0",
"style-loader": "^0.19.1",
"typescript": "^2.9.1",
"typescript": "^3.0.0-rc",
"url-loader": "^0.6.2",
"val-loader": "^1.0.2",
"vm-browserify": "~0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion schemas/WebpackOptions.json
Expand Up @@ -1592,7 +1592,7 @@
"type": "boolean"
},
"moduleIds": {
"description": "Define the algorithm to choose module ids (natural: numeric ids in order for usage, named: readable ids for better debugging, hashed: short hashes as ids for better long term caching, size: numeric ids focused on minimal initial download size, total-size: numeric ids focused on minimal total download size, false: no algorithm used, as custom one can be provided via plugin)",
"description": "Define the algorithm to choose module ids (natural: numeric ids in order of usage, named: readable ids for better debugging, hashed: short hashes as ids for better long term caching, size: numeric ids focused on minimal initial download size, total-size: numeric ids focused on minimal total download size, false: no algorithm used, as custom one can be provided via plugin)",
"enum": [
"natural",
"named",
Expand Down
6 changes: 3 additions & 3 deletions test/Compiler.test.js
Expand Up @@ -85,7 +85,7 @@ describe("Compiler", () => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./a */ 0);");
expect(bundle).toMatch(/__webpack_require__\(\/\*! \.\/a \*\/ \d\);/);
expect(bundle).toMatch("./c.js");
expect(bundle).toMatch("./a.js");
expect(bundle).toMatch("This is a");
Expand Down Expand Up @@ -145,9 +145,9 @@ describe("Compiler", () => {
it("should compile a file with multiple chunks", done => {
compile("./chunks", {}, (stats, files) => {
expect(stats.chunks).toHaveLength(2);
expect(Object.keys(files)).toEqual(["/0.js", "/main.js"]);
expect(Object.keys(files)).toEqual(["/main.js", "/1.js"]);
const bundle = files["/main.js"];
const chunk = files["/0.js"];
const chunk = files["/1.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./b */");
expect(chunk).not.toMatch("__webpack_require__(/* ./b */");
Expand Down
9 changes: 5 additions & 4 deletions test/HotModuleReplacementPlugin.test.js
Expand Up @@ -50,10 +50,11 @@ describe("HotModuleReplacementPlugin", () => {
output: {
path: path.join(__dirname, "js", "HotModuleReplacementPlugin")
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
]
plugins: [new webpack.HotModuleReplacementPlugin()],
optimization: {
moduleIds: "size",
chunkIds: "size"
}
});
fs.writeFileSync(entryFile, "1", "utf-8");
compiler.run((err, stats) => {
Expand Down
1 change: 0 additions & 1 deletion test/StatsTestCases.test.js
Expand Up @@ -75,7 +75,6 @@ describe("StatsTestCases", () => {
])
);
};
new webpack.optimize.OccurrenceOrderPlugin().apply(c);
});
c.run((err, stats) => {
if (err) return done(err);
Expand Down
20 changes: 10 additions & 10 deletions test/__snapshots__/ConfigTestCases.test.js.snap
Expand Up @@ -4,10 +4,10 @@ exports[`ConfigTestCases records issue-2991 exported tests should write relative
"{
\\"modules\\": {
\\"byIdentifier\\": {
\\"external \\\\\\"path\\\\\\"\\": 0,
\\"external \\\\\\"fs\\\\\\"\\": 1,
\\"ignored pkgs/somepackage/foo\\": 2,
\\"test.js\\": 3
\\"test.js\\": 0,
\\"ignored pkgs/somepackage/foo\\": 1,
\\"external \\\\\\"fs\\\\\\"\\": 2,
\\"external \\\\\\"path\\\\\\"\\": 3
},
\\"usedIds\\": {
\\"0\\": 0,
Expand All @@ -32,12 +32,12 @@ exports[`ConfigTestCases records issue-7339 exported tests should write relative
"{
\\"modules\\": {
\\"byIdentifier\\": {
\\"dependencies/foo.js\\": 0,
\\"dependencies/bar.js\\": 1,
\\"external \\\\\\"path\\\\\\"\\": 2,
\\"external \\\\\\"fs\\\\\\"\\": 3,
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 4,
\\"test.js\\": 5
\\"dependencies/bar.js\\": 0,
\\"dependencies/foo.js\\": 1,
\\"test.js\\": 2,
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 3,
\\"external \\\\\\"fs\\\\\\"\\": 4,
\\"external \\\\\\"path\\\\\\"\\": 5
},
\\"usedIds\\": {
\\"0\\": 0,
Expand Down

0 comments on commit b3a7c4d

Please sign in to comment.