From 0111405198d452c2ad51d9efb3a35ca8ab904430 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 2 Sep 2020 15:07:15 +0200 Subject: [PATCH] enable asset experiment --- examples/asset-advanced/README.md | 56 ++++++++-------- examples/asset-advanced/webpack.config.js | 3 - examples/asset-simple/README.md | 66 +++++++++---------- examples/asset-simple/webpack.config.js | 3 - lib/WebpackOptionsApply.js | 7 +- lib/config/defaults.js | 16 ++--- test/Defaults.unittest.js | 5 +- .../assetModuleFilename/webpack.config.js | 3 - .../custom-condition/webpack.config.js | 3 - .../custom-encoder/webpack.config.js | 3 - .../asset-modules/data-url/webpack.config.js | 3 - .../asset-modules/opus/webpack.config.js | 3 - .../overridePath/webpack.config.js | 3 - .../asset-modules/path/webpack.config.js | 3 - .../publicPath/webpack.config.js | 3 - .../webpack.config.js | 3 - .../webpack.config.js | 3 - .../asset-modules/query/webpack.config.js | 3 - .../real-content-hash/webpack.config.js | 3 - .../asset-modules/source/webpack.config.js | 3 - .../asset-modules/types/webpack.config.js | 3 - .../asset-url/target-node1/webpack.config.js | 3 - .../asset-url/target-node2/webpack.config.js | 3 - .../asset-url/target-node3/webpack.config.js | 3 - .../asset-url/target-web1/webpack.config.js | 3 - .../asset-url/target-web2/webpack.config.js | 3 - .../target-webworker1/webpack.config.js | 3 - .../target-webworker2/webpack.config.js | 3 - test/statsCases/asset/webpack.config.js | 3 - .../real-content-hash/webpack.config.js | 3 - 30 files changed, 72 insertions(+), 153 deletions(-) diff --git a/examples/asset-advanced/README.md b/examples/asset-advanced/README.md index e25880fcd..a7b128f09 100644 --- a/examples/asset-advanced/README.md +++ b/examples/asset-advanced/README.md @@ -64,9 +64,6 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; ``` @@ -95,37 +92,40 @@ module.exports = "data:image/svg+xml,%3csvg xmlns='http://www.w3.or...3c/svg%3e"
/* webpack runtime code */ -``` js +```js /************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ if(__webpack_module_cache__[moduleId]) { -/******/ return __webpack_module_cache__[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; // The require function +/******/ +/******/ /******/ function __webpack_require__(moduleId) { + /******/ // Check if module is in cache + /******/ if (__webpack_module_cache__[moduleId]) { + /******/ return __webpack_module_cache__[moduleId].exports; + /******/ + } // Create a new module (and put it into the cache) + /******/ /******/ var module = (__webpack_module_cache__[moduleId] = { + /******/ // no module.id needed + /******/ // no module.loaded needed + /******/ exports: {} + /******/ + }); // Execute the module function + /******/ + /******/ /******/ __webpack_modules__[moduleId]( + module, + module.exports, + __webpack_require__ + ); // Return the exports of the module + /******/ + /******/ /******/ return module.exports; + /******/ +} +/******/ /************************************************************************/ ```
-``` js +```js (() => { /*!********************!*\ !*** ./example.js ***! diff --git a/examples/asset-advanced/webpack.config.js b/examples/asset-advanced/webpack.config.js index 42efe0b13..a607befdd 100644 --- a/examples/asset-advanced/webpack.config.js +++ b/examples/asset-advanced/webpack.config.js @@ -24,8 +24,5 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; diff --git a/examples/asset-simple/README.md b/examples/asset-simple/README.md index 1e72693e2..0de60dbd6 100644 --- a/examples/asset-simple/README.md +++ b/examples/asset-simple/README.md @@ -51,9 +51,6 @@ module.exports = { type: "asset" } ] - }, - experiments: { - asset: true } }; ``` @@ -106,43 +103,46 @@ module.exports = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDo...vc3ZnPgo="
/* webpack runtime code */ -``` js +```js /************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ if(__webpack_module_cache__[moduleId]) { -/******/ return __webpack_module_cache__[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; // The require function +/******/ +/******/ /******/ function __webpack_require__(moduleId) { + /******/ // Check if module is in cache + /******/ if (__webpack_module_cache__[moduleId]) { + /******/ return __webpack_module_cache__[moduleId].exports; + /******/ + } // Create a new module (and put it into the cache) + /******/ /******/ var module = (__webpack_module_cache__[moduleId] = { + /******/ // no module.id needed + /******/ // no module.loaded needed + /******/ exports: {} + /******/ + }); // Execute the module function + /******/ + /******/ /******/ __webpack_modules__[moduleId]( + module, + module.exports, + __webpack_require__ + ); // Return the exports of the module + /******/ + /******/ /******/ return module.exports; + /******/ +} /* webpack/runtime/publicPath */ +/******/ /************************************************************************/ -/******/ /* webpack/runtime/publicPath */ -/******/ (() => { -/******/ __webpack_require__.p = "dist/"; -/******/ })(); -/******/ +/******/ /******/ (() => { + /******/ __webpack_require__.p = "dist/"; + /******/ +})(); +/******/ /************************************************************************/ ```
-``` js +```js (() => { /*!********************!*\ !*** ./example.js ***! diff --git a/examples/asset-simple/webpack.config.js b/examples/asset-simple/webpack.config.js index eac635188..8b935943f 100644 --- a/examples/asset-simple/webpack.config.js +++ b/examples/asset-simple/webpack.config.js @@ -9,8 +9,5 @@ module.exports = { type: "asset" } ] - }, - experiments: { - asset: true } }; diff --git a/lib/WebpackOptionsApply.js b/lib/WebpackOptionsApply.js index d401105d3..11bbb49c2 100644 --- a/lib/WebpackOptionsApply.js +++ b/lib/WebpackOptionsApply.js @@ -7,6 +7,7 @@ const OptionsApply = require("./OptionsApply"); +const AssetModulesPlugin = require("./asset/AssetModulesPlugin"); const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin"); const JsonModulesPlugin = require("./json/JsonModulesPlugin"); @@ -234,6 +235,7 @@ class WebpackOptionsApply extends OptionsApply { new JavascriptModulesPlugin().apply(compiler); new JsonModulesPlugin().apply(compiler); + new AssetModulesPlugin().apply(compiler); if (!options.experiments.outputModule) { if (options.output.module) { @@ -253,11 +255,6 @@ class WebpackOptionsApply extends OptionsApply { } } - if (options.experiments.asset) { - const AssetModulesPlugin = require("./asset/AssetModulesPlugin"); - new AssetModulesPlugin().apply(compiler); - } - if (options.experiments.syncWebAssembly) { const WebAssemblyModulesPlugin = require("./wasm/WebAssemblyModulesPlugin"); new WebAssemblyModulesPlugin({ diff --git a/lib/config/defaults.js b/lib/config/defaults.js index a9bd5c4f7..7f7c9c81a 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -159,7 +159,6 @@ const applyWebpackOptionsDefaults = options => { mjs: options.experiments.mjs, syncWebAssembly: options.experiments.syncWebAssembly, asyncWebAssembly: options.experiments.asyncWebAssembly, - asset: options.experiments.asset, webTarget }); @@ -246,7 +245,6 @@ const applyWebpackOptionsDefaults = options => { * @returns {void} */ const applyExperimentsDefaults = experiments => { - D(experiments, "asset", false); D(experiments, "mjs", false); D(experiments, "topLevelAwait", false); D(experiments, "syncWebAssembly", false); @@ -359,13 +357,12 @@ const applySnapshotDefaults = (snapshot, { production }) => { * @param {boolean} options.mjs is mjs enabled * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled - * @param {boolean} options.asset is asset experiment enabled * @param {boolean} options.webTarget is web target * @returns {void} */ const applyModuleDefaults = ( module, - { cache, mjs, syncWebAssembly, asyncWebAssembly, asset, webTarget } + { cache, mjs, syncWebAssembly, asyncWebAssembly, webTarget } ) => { D(module, "unknownContextRequest", "."); D(module, "unknownContextRegExp", false); @@ -408,6 +405,10 @@ const applyModuleDefaults = ( { mimetype: "application/json", type: "json" + }, + { + dependency: "url", + type: "asset/resource" } ]; if (mjs) { @@ -511,13 +512,6 @@ const applyModuleDefaults = ( ...wasm }); } - if (asset) { - rules.push({ - dependency: "url", - type: "asset/resource" - }); - } - return rules; }); }; diff --git a/test/Defaults.unittest.js b/test/Defaults.unittest.js index e0c2391b2..f426b9995 100644 --- a/test/Defaults.unittest.js +++ b/test/Defaults.unittest.js @@ -89,7 +89,6 @@ describe("Defaults", () => { }, }, "experiments": Object { - "asset": false, "asyncWebAssembly": false, "mjs": false, "outputModule": false, @@ -121,6 +120,10 @@ describe("Defaults", () => { "mimetype": "application/json", "type": "json", }, + Object { + "dependency": "url", + "type": "asset/resource", + }, Object { "mimetype": Object { "or": Array [ diff --git a/test/configCases/asset-modules/assetModuleFilename/webpack.config.js b/test/configCases/asset-modules/assetModuleFilename/webpack.config.js index 8b85060f9..ebf88f8a3 100644 --- a/test/configCases/asset-modules/assetModuleFilename/webpack.config.js +++ b/test/configCases/asset-modules/assetModuleFilename/webpack.config.js @@ -19,8 +19,5 @@ module.exports = { type: "asset/resource" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/custom-condition/webpack.config.js b/test/configCases/asset-modules/custom-condition/webpack.config.js index bb0895768..d0cdeb9c2 100644 --- a/test/configCases/asset-modules/custom-condition/webpack.config.js +++ b/test/configCases/asset-modules/custom-condition/webpack.config.js @@ -44,8 +44,5 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/custom-encoder/webpack.config.js b/test/configCases/asset-modules/custom-encoder/webpack.config.js index 86ac26b83..e65597781 100644 --- a/test/configCases/asset-modules/custom-encoder/webpack.config.js +++ b/test/configCases/asset-modules/custom-encoder/webpack.config.js @@ -31,8 +31,5 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/data-url/webpack.config.js b/test/configCases/asset-modules/data-url/webpack.config.js index de87d5817..924725978 100644 --- a/test/configCases/asset-modules/data-url/webpack.config.js +++ b/test/configCases/asset-modules/data-url/webpack.config.js @@ -17,8 +17,5 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/opus/webpack.config.js b/test/configCases/asset-modules/opus/webpack.config.js index 6966d01e2..7e76d203b 100644 --- a/test/configCases/asset-modules/opus/webpack.config.js +++ b/test/configCases/asset-modules/opus/webpack.config.js @@ -8,8 +8,5 @@ module.exports = { type: "asset" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/overridePath/webpack.config.js b/test/configCases/asset-modules/overridePath/webpack.config.js index fa4a01def..47481e0aa 100644 --- a/test/configCases/asset-modules/overridePath/webpack.config.js +++ b/test/configCases/asset-modules/overridePath/webpack.config.js @@ -18,8 +18,5 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/path/webpack.config.js b/test/configCases/asset-modules/path/webpack.config.js index cbf6b2eba..6255f7186 100644 --- a/test/configCases/asset-modules/path/webpack.config.js +++ b/test/configCases/asset-modules/path/webpack.config.js @@ -11,8 +11,5 @@ module.exports = { type: "asset" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/publicPath/webpack.config.js b/test/configCases/asset-modules/publicPath/webpack.config.js index 4962cb1ec..70d5e4bf8 100644 --- a/test/configCases/asset-modules/publicPath/webpack.config.js +++ b/test/configCases/asset-modules/publicPath/webpack.config.js @@ -12,8 +12,5 @@ module.exports = { type: "asset" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js b/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js index 004284041..f59559e80 100644 --- a/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js +++ b/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js @@ -12,8 +12,5 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/query-and-custom-encoder/webpack.config.js b/test/configCases/asset-modules/query-and-custom-encoder/webpack.config.js index 061791828..dc97257e6 100644 --- a/test/configCases/asset-modules/query-and-custom-encoder/webpack.config.js +++ b/test/configCases/asset-modules/query-and-custom-encoder/webpack.config.js @@ -26,8 +26,5 @@ module.exports = { } } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/query/webpack.config.js b/test/configCases/asset-modules/query/webpack.config.js index 6a3d44276..2b54b8bf6 100644 --- a/test/configCases/asset-modules/query/webpack.config.js +++ b/test/configCases/asset-modules/query/webpack.config.js @@ -7,8 +7,5 @@ module.exports = { type: "asset/resource" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/real-content-hash/webpack.config.js b/test/configCases/asset-modules/real-content-hash/webpack.config.js index cf5511ab5..185587c16 100644 --- a/test/configCases/asset-modules/real-content-hash/webpack.config.js +++ b/test/configCases/asset-modules/real-content-hash/webpack.config.js @@ -12,8 +12,5 @@ module.exports = { type: "asset/resource" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/source/webpack.config.js b/test/configCases/asset-modules/source/webpack.config.js index 5a81c18d0..1d0399ec2 100644 --- a/test/configCases/asset-modules/source/webpack.config.js +++ b/test/configCases/asset-modules/source/webpack.config.js @@ -8,8 +8,5 @@ module.exports = { type: "asset/source" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-modules/types/webpack.config.js b/test/configCases/asset-modules/types/webpack.config.js index b1de2ea22..94be94f16 100644 --- a/test/configCases/asset-modules/types/webpack.config.js +++ b/test/configCases/asset-modules/types/webpack.config.js @@ -12,8 +12,5 @@ module.exports = { type: "asset/resource" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-url/target-node1/webpack.config.js b/test/configCases/asset-url/target-node1/webpack.config.js index e1bbe0eb8..315a9e602 100644 --- a/test/configCases/asset-url/target-node1/webpack.config.js +++ b/test/configCases/asset-url/target-node1/webpack.config.js @@ -15,8 +15,5 @@ module.exports = { loader: "url-loader" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-url/target-node2/webpack.config.js b/test/configCases/asset-url/target-node2/webpack.config.js index 3dedddb20..14934d113 100644 --- a/test/configCases/asset-url/target-node2/webpack.config.js +++ b/test/configCases/asset-url/target-node2/webpack.config.js @@ -5,8 +5,5 @@ module.exports = { devtool: false, output: { assetModuleFilename: "[name][ext]" - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-url/target-node3/webpack.config.js b/test/configCases/asset-url/target-node3/webpack.config.js index fb6076c97..499de2fe5 100644 --- a/test/configCases/asset-url/target-node3/webpack.config.js +++ b/test/configCases/asset-url/target-node3/webpack.config.js @@ -6,8 +6,5 @@ module.exports = { output: { assetModuleFilename: "[name][ext]", publicPath: "https://example.com/" - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-url/target-web1/webpack.config.js b/test/configCases/asset-url/target-web1/webpack.config.js index 8aea73468..35e16e26f 100644 --- a/test/configCases/asset-url/target-web1/webpack.config.js +++ b/test/configCases/asset-url/target-web1/webpack.config.js @@ -14,8 +14,5 @@ module.exports = { loader: "url-loader" } ] - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-url/target-web2/webpack.config.js b/test/configCases/asset-url/target-web2/webpack.config.js index ec1b003a1..2cbfe9bdd 100644 --- a/test/configCases/asset-url/target-web2/webpack.config.js +++ b/test/configCases/asset-url/target-web2/webpack.config.js @@ -6,8 +6,5 @@ module.exports = { output: { assetModuleFilename: "[name][ext]", publicPath: "/path2/" - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-url/target-webworker1/webpack.config.js b/test/configCases/asset-url/target-webworker1/webpack.config.js index 7e8a9dcfe..5182520e7 100644 --- a/test/configCases/asset-url/target-webworker1/webpack.config.js +++ b/test/configCases/asset-url/target-webworker1/webpack.config.js @@ -6,8 +6,5 @@ module.exports = { output: { filename: "deep/path/[name].js", assetModuleFilename: "[path][name][ext]" - }, - experiments: { - asset: true } }; diff --git a/test/configCases/asset-url/target-webworker2/webpack.config.js b/test/configCases/asset-url/target-webworker2/webpack.config.js index 75d1f534e..ef13370aa 100644 --- a/test/configCases/asset-url/target-webworker2/webpack.config.js +++ b/test/configCases/asset-url/target-webworker2/webpack.config.js @@ -6,8 +6,5 @@ module.exports = { output: { assetModuleFilename: "[name][ext]", publicPath: "/" - }, - experiments: { - asset: true } }; diff --git a/test/statsCases/asset/webpack.config.js b/test/statsCases/asset/webpack.config.js index be774ea86..2b664c67f 100644 --- a/test/statsCases/asset/webpack.config.js +++ b/test/statsCases/asset/webpack.config.js @@ -19,8 +19,5 @@ module.exports = { }, output: { filename: "bundle.js" - }, - experiments: { - asset: true } }; diff --git a/test/statsCases/real-content-hash/webpack.config.js b/test/statsCases/real-content-hash/webpack.config.js index 6fca04179..9baf37c96 100644 --- a/test/statsCases/real-content-hash/webpack.config.js +++ b/test/statsCases/real-content-hash/webpack.config.js @@ -17,9 +17,6 @@ const base = { }, stats: { relatedAssets: true - }, - experiments: { - asset: true } };