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
}
};
```
@ -95,37 +92,40 @@ module.exports = "data:image/svg+xml,%3csvg xmlns='http://www.w3.or...3c/svg%3e"
<details><summary><code>/* webpack runtime code */</code></summary>
``` 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;
/******/
}
/******/
/************************************************************************/
```
</details>
``` js
```js
(() => {
/*!********************!*\
!*** ./example.js ***!

View File

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

View File

@ -51,9 +51,6 @@ module.exports = {
type: "asset"
}
]
},
experiments: {
asset: true
}
};
```
@ -106,43 +103,46 @@ module.exports = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDo...vc3ZnPgo="
<details><summary><code>/* webpack runtime code */</code></summary>
``` 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/";
/******/
})();
/******/
/************************************************************************/
```
</details>
``` js
```js
(() => {
/*!********************!*\
!*** ./example.js ***!

View File

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

View File

@ -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({

View File

@ -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;
});
};

View File

@ -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 [

View File

@ -19,8 +19,5 @@ module.exports = {
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"
}
]
},
experiments: {
asset: true
}
};

View File

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

View File

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

View File

@ -12,8 +12,5 @@ module.exports = {
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"
}
]
},
experiments: {
asset: true
}
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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