enable asset experiment

This commit is contained in:
Tobias Koppers 2020-09-02 15:07:15 +02:00
parent 39d2f8f7f3
commit 0111405198
30 changed files with 72 additions and 153 deletions

View File

@ -64,9 +64,6 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };
``` ```
@ -98,27 +95,30 @@ module.exports = "data:image/svg+xml,%3csvg xmlns='http://www.w3.or...3c/svg%3e"
```js ```js
/************************************************************************/ /************************************************************************/
/******/ // The module cache /******/ // The module cache
/******/ var __webpack_module_cache__ = {}; /******/ var __webpack_module_cache__ = {}; // The require function
/******/ /******/
/******/ // The require function /******/ /******/ function __webpack_require__(moduleId) {
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache /******/ // Check if module is in cache
/******/ if (__webpack_module_cache__[moduleId]) { /******/ if (__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports; /******/ return __webpack_module_cache__[moduleId].exports;
/******/ } /******/
/******/ // Create a new module (and put it into the cache) } // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = { /******/ /******/ var module = (__webpack_module_cache__[moduleId] = {
/******/ // no module.id needed /******/ // no module.id needed
/******/ // no module.loaded needed /******/ // no module.loaded needed
/******/ exports: {} /******/ exports: {}
/******/ };
/******/ /******/
/******/ // Execute the module function }); // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ /******/
/******/ // Return the exports of the module /******/ /******/ __webpack_modules__[moduleId](
/******/ return module.exports; module,
/******/ } module.exports,
__webpack_require__
); // Return the exports of the module
/******/
/******/ /******/ return module.exports;
/******/
}
/******/ /******/
/************************************************************************/ /************************************************************************/
``` ```

View File

@ -24,8 +24,5 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -51,9 +51,6 @@ module.exports = {
type: "asset" type: "asset"
} }
] ]
},
experiments: {
asset: true
} }
}; };
``` ```
@ -109,33 +106,36 @@ module.exports = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDo...vc3ZnPgo="
```js ```js
/************************************************************************/ /************************************************************************/
/******/ // The module cache /******/ // The module cache
/******/ var __webpack_module_cache__ = {}; /******/ var __webpack_module_cache__ = {}; // The require function
/******/ /******/
/******/ // The require function /******/ /******/ function __webpack_require__(moduleId) {
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache /******/ // Check if module is in cache
/******/ if (__webpack_module_cache__[moduleId]) { /******/ if (__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports; /******/ return __webpack_module_cache__[moduleId].exports;
/******/ } /******/
/******/ // Create a new module (and put it into the cache) } // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = { /******/ /******/ var module = (__webpack_module_cache__[moduleId] = {
/******/ // no module.id needed /******/ // no module.id needed
/******/ // no module.loaded needed /******/ // no module.loaded needed
/******/ exports: {} /******/ exports: {}
/******/ };
/******/ /******/
/******/ // Execute the module function }); // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ /******/
/******/ // Return the exports of the module /******/ /******/ __webpack_modules__[moduleId](
/******/ return module.exports; 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/";
/******/ })(); /******/
})();
/******/ /******/
/************************************************************************/ /************************************************************************/
``` ```

View File

@ -9,8 +9,5 @@ module.exports = {
type: "asset" type: "asset"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -7,6 +7,7 @@
const OptionsApply = require("./OptionsApply"); const OptionsApply = require("./OptionsApply");
const AssetModulesPlugin = require("./asset/AssetModulesPlugin");
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin"); const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
const JsonModulesPlugin = require("./json/JsonModulesPlugin"); const JsonModulesPlugin = require("./json/JsonModulesPlugin");
@ -234,6 +235,7 @@ class WebpackOptionsApply extends OptionsApply {
new JavascriptModulesPlugin().apply(compiler); new JavascriptModulesPlugin().apply(compiler);
new JsonModulesPlugin().apply(compiler); new JsonModulesPlugin().apply(compiler);
new AssetModulesPlugin().apply(compiler);
if (!options.experiments.outputModule) { if (!options.experiments.outputModule) {
if (options.output.module) { 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) { if (options.experiments.syncWebAssembly) {
const WebAssemblyModulesPlugin = require("./wasm/WebAssemblyModulesPlugin"); const WebAssemblyModulesPlugin = require("./wasm/WebAssemblyModulesPlugin");
new WebAssemblyModulesPlugin({ new WebAssemblyModulesPlugin({

View File

@ -159,7 +159,6 @@ const applyWebpackOptionsDefaults = options => {
mjs: options.experiments.mjs, mjs: options.experiments.mjs,
syncWebAssembly: options.experiments.syncWebAssembly, syncWebAssembly: options.experiments.syncWebAssembly,
asyncWebAssembly: options.experiments.asyncWebAssembly, asyncWebAssembly: options.experiments.asyncWebAssembly,
asset: options.experiments.asset,
webTarget webTarget
}); });
@ -246,7 +245,6 @@ const applyWebpackOptionsDefaults = options => {
* @returns {void} * @returns {void}
*/ */
const applyExperimentsDefaults = experiments => { const applyExperimentsDefaults = experiments => {
D(experiments, "asset", false);
D(experiments, "mjs", false); D(experiments, "mjs", false);
D(experiments, "topLevelAwait", false); D(experiments, "topLevelAwait", false);
D(experiments, "syncWebAssembly", false); D(experiments, "syncWebAssembly", false);
@ -359,13 +357,12 @@ const applySnapshotDefaults = (snapshot, { production }) => {
* @param {boolean} options.mjs is mjs enabled * @param {boolean} options.mjs is mjs enabled
* @param {boolean} options.syncWebAssembly is syncWebAssembly enabled * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
* @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
* @param {boolean} options.asset is asset experiment enabled
* @param {boolean} options.webTarget is web target * @param {boolean} options.webTarget is web target
* @returns {void} * @returns {void}
*/ */
const applyModuleDefaults = ( const applyModuleDefaults = (
module, module,
{ cache, mjs, syncWebAssembly, asyncWebAssembly, asset, webTarget } { cache, mjs, syncWebAssembly, asyncWebAssembly, webTarget }
) => { ) => {
D(module, "unknownContextRequest", "."); D(module, "unknownContextRequest", ".");
D(module, "unknownContextRegExp", false); D(module, "unknownContextRegExp", false);
@ -408,6 +405,10 @@ const applyModuleDefaults = (
{ {
mimetype: "application/json", mimetype: "application/json",
type: "json" type: "json"
},
{
dependency: "url",
type: "asset/resource"
} }
]; ];
if (mjs) { if (mjs) {
@ -511,13 +512,6 @@ const applyModuleDefaults = (
...wasm ...wasm
}); });
} }
if (asset) {
rules.push({
dependency: "url",
type: "asset/resource"
});
}
return rules; return rules;
}); });
}; };

View File

@ -89,7 +89,6 @@ describe("Defaults", () => {
}, },
}, },
"experiments": Object { "experiments": Object {
"asset": false,
"asyncWebAssembly": false, "asyncWebAssembly": false,
"mjs": false, "mjs": false,
"outputModule": false, "outputModule": false,
@ -121,6 +120,10 @@ describe("Defaults", () => {
"mimetype": "application/json", "mimetype": "application/json",
"type": "json", "type": "json",
}, },
Object {
"dependency": "url",
"type": "asset/resource",
},
Object { Object {
"mimetype": Object { "mimetype": Object {
"or": Array [ "or": Array [

View File

@ -19,8 +19,5 @@ module.exports = {
type: "asset/resource" type: "asset/resource"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -44,8 +44,5 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -31,8 +31,5 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -17,8 +17,5 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -8,8 +8,5 @@ module.exports = {
type: "asset" type: "asset"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -18,8 +18,5 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -11,8 +11,5 @@ module.exports = {
type: "asset" type: "asset"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -12,8 +12,5 @@ module.exports = {
type: "asset" type: "asset"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -12,8 +12,5 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -26,8 +26,5 @@ module.exports = {
} }
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -7,8 +7,5 @@ module.exports = {
type: "asset/resource" type: "asset/resource"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -12,8 +12,5 @@ module.exports = {
type: "asset/resource" type: "asset/resource"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -8,8 +8,5 @@ module.exports = {
type: "asset/source" type: "asset/source"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -12,8 +12,5 @@ module.exports = {
type: "asset/resource" type: "asset/resource"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -15,8 +15,5 @@ module.exports = {
loader: "url-loader" loader: "url-loader"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -5,8 +5,5 @@ module.exports = {
devtool: false, devtool: false,
output: { output: {
assetModuleFilename: "[name][ext]" assetModuleFilename: "[name][ext]"
},
experiments: {
asset: true
} }
}; };

View File

@ -6,8 +6,5 @@ module.exports = {
output: { output: {
assetModuleFilename: "[name][ext]", assetModuleFilename: "[name][ext]",
publicPath: "https://example.com/" publicPath: "https://example.com/"
},
experiments: {
asset: true
} }
}; };

View File

@ -14,8 +14,5 @@ module.exports = {
loader: "url-loader" loader: "url-loader"
} }
] ]
},
experiments: {
asset: true
} }
}; };

View File

@ -6,8 +6,5 @@ module.exports = {
output: { output: {
assetModuleFilename: "[name][ext]", assetModuleFilename: "[name][ext]",
publicPath: "/path2/" publicPath: "/path2/"
},
experiments: {
asset: true
} }
}; };

View File

@ -6,8 +6,5 @@ module.exports = {
output: { output: {
filename: "deep/path/[name].js", filename: "deep/path/[name].js",
assetModuleFilename: "[path][name][ext]" assetModuleFilename: "[path][name][ext]"
},
experiments: {
asset: true
} }
}; };

View File

@ -6,8 +6,5 @@ module.exports = {
output: { output: {
assetModuleFilename: "[name][ext]", assetModuleFilename: "[name][ext]",
publicPath: "/" publicPath: "/"
},
experiments: {
asset: true
} }
}; };

View File

@ -19,8 +19,5 @@ module.exports = {
}, },
output: { output: {
filename: "bundle.js" filename: "bundle.js"
},
experiments: {
asset: true
} }
}; };

View File

@ -17,9 +17,6 @@ const base = {
}, },
stats: { stats: {
relatedAssets: true relatedAssets: true
},
experiments: {
asset: true
} }
}; };