diff --git a/README.md b/README.md index df899293..c958ec0a 100644 --- a/README.md +++ b/README.md @@ -499,7 +499,22 @@ module.exports = { }; ``` -### Module Filename Option +### Disable Extracting Specified CSS from Chunks + +You may disable extracting css modules programmatically by passing a function. + +```javascript +const miniCssExtractPlugin = new MiniCssExtractPlugin({ + disableExtract({ module, isAsync }) { + // Do whatever you want. Disable by content size for example: + // return module.content.length < 10 * 1024; + // Or disable extracting from all async chunks + return isAsync; + }, +}); +``` + +#### Module Filename Option With the `moduleFilename` option you can use chunk data to customize the filename. This is particularly useful when dealing with multiple entry points and wanting to get more control out of the filename for a given entry point/chunk. In the example below, we'll use `moduleFilename` to output the generated css into a different directory. diff --git a/package-lock.json b/package-lock.json index 8af4e953..d21d2d09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13234,6 +13234,16 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true }, + "style-loader": { + "version": "0.23.1", + "resolved": "https://registry.npm.taobao.org/style-loader/download/style-loader-0.23.1.tgz?cache=0&sync_timestamp=1589720795120&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fstyle-loader%2Fdownload%2Fstyle-loader-0.23.1.tgz", + "integrity": "sha1-y5FUYG8+dxq2xKtjcCahBJF02SU=", + "dev": true, + "requires": { + "loader-utils": "^1.1.0", + "schema-utils": "^1.0.0" + } + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", diff --git a/package.json b/package.json index e82590f2..66ac2fea 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "npm-run-all": "^4.1.5", "prettier": "^1.19.1", "standard-version": "^7.0.1", + "style-loader": "^0.23.1", "webpack": "^4.41.4", "webpack-cli": "^3.3.6", "webpack-dev-server": "^3.7.2" diff --git a/src/index.js b/src/index.js index d9f6bf2d..8357b47f 100644 --- a/src/index.js +++ b/src/index.js @@ -24,6 +24,16 @@ const REGEXP_NAME = /\[name\]/i; const REGEXP_PLACEHOLDERS = /\[(name|id|chunkhash)\]/g; const DEFAULT_FILENAME = '[name].css'; +function isInitialOrHasNoParents(chunk) { + let parentCount = 0; + + for (const chunkGroup of chunk.groupsIterable) { + parentCount += chunkGroup.getNumberOfParents(); + } + + return chunk.isOnlyInitial() || parentCount === 0; +} + class CssDependencyTemplate { apply() {} } @@ -129,6 +139,20 @@ class MiniCssExtractPlugin { apply(compiler) { compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { + let moduleToBeRebuild = new Set(); + // eslint-disable-next-line no-param-reassign + compilation[MODULE_TYPE] = { + moduleToBeRebuild, + }; + + compilation.hooks.normalModuleLoader.tap(pluginName, (lc, m) => { + const loaderContext = lc; + const module = m; + loaderContext[`${MODULE_TYPE}/disableExtract`] = () => { + return !!module[`${MODULE_TYPE}/disableExtract`]; + }; + }); + compilation.dependencyFactories.set( CssDependency, new CssModuleFactory() @@ -390,9 +414,65 @@ class MiniCssExtractPlugin { return source; } ); + + compilation.hooks.optimizeTree.tapAsync( + pluginName, + (chunks, modules, callback) => { + const promises = []; + + for (const chunk of chunks) { + const isAsync = !isInitialOrHasNoParents(chunk); + for (const module of chunk.modulesIterable) { + if (module.type === MODULE_TYPE) { + if (this.shouldDisableExtract({ module, isAsync })) { + moduleToBeRebuild.add(module); + } + } + } + } + + for (const currentModuleToBeRebuild of moduleToBeRebuild) { + const { issuer } = currentModuleToBeRebuild; + if (!issuer[`${MODULE_TYPE}/disableExtract`]) { + issuer[`${MODULE_TYPE}/disableExtract`] = true; + promises.push( + new Promise((resolve) => { + compilation.rebuildModule(issuer, (err) => { + if (err) { + compilation.errors.push(err); + } + resolve(); + }); + }) + ); + } + } + + Promise.all(promises).then(() => callback()); + } + ); + + // Trigger seal again if there are modules to be rebuilt + compilation.hooks.needAdditionalSeal.tap(pluginName, () => { + if (moduleToBeRebuild.size > 0) { + moduleToBeRebuild = new Set(); + return true; + } + return false; + }); }); } + shouldDisableExtract({ module, isAsync }) { + const { disableExtract } = this.options; + let shouldDisable = false; + if (typeof disableExtract === 'function') { + shouldDisable = disableExtract({ module, isAsync }); + } + + return shouldDisable; + } + getCssChunkObject(mainChunk) { const obj = {}; diff --git a/src/loader.js b/src/loader.js index 17bf97c8..ac356ce4 100644 --- a/src/loader.js +++ b/src/loader.js @@ -14,6 +14,7 @@ import CssDependency from './CssDependency'; import schema from './loader-options.json'; +const MODULE_TYPE = 'css/mini-extract'; const pluginName = 'mini-css-extract-plugin'; function hotLoader(content, context) { @@ -66,6 +67,10 @@ export function pitch(request) { this.addDependency(this.resourcePath); + if (this[`${MODULE_TYPE}/disableExtract`]()) { + return; + } + const childFilename = '*'; const publicPath = typeof options.publicPath === 'string' @@ -223,4 +228,6 @@ export function pitch(request) { }); } -export default function() {} +export default function(source) { + return source; +} diff --git a/test/cases/disable-extract-func/async-import.css b/test/cases/disable-extract-func/async-import.css new file mode 100644 index 00000000..107a6a79 --- /dev/null +++ b/test/cases/disable-extract-func/async-import.css @@ -0,0 +1,3 @@ +.async-import { + background: black; +} diff --git a/test/cases/disable-extract-func/async.css b/test/cases/disable-extract-func/async.css new file mode 100644 index 00000000..65bdcfa7 --- /dev/null +++ b/test/cases/disable-extract-func/async.css @@ -0,0 +1,3 @@ +.async { + background: blue; +} diff --git a/test/cases/disable-extract-func/async.js b/test/cases/disable-extract-func/async.js new file mode 100644 index 00000000..9da9a541 --- /dev/null +++ b/test/cases/disable-extract-func/async.js @@ -0,0 +1,9 @@ +import './in-async'; +import './in-async2.css'; +import './in-async.css'; +import './both-async.css'; + +import './both-page-async-disabled.css'; +import './both-page-async.css'; + +// console.log('async.js'); diff --git a/test/cases/disable-extract-func/async2.js b/test/cases/disable-extract-func/async2.js new file mode 100644 index 00000000..f3b92994 --- /dev/null +++ b/test/cases/disable-extract-func/async2.js @@ -0,0 +1,5 @@ +import './both-page-async-disabled.css'; +import './both-page-async.css'; +import './is-async1.css'; + +// console.log('async2.js'); diff --git a/test/cases/disable-extract-func/both-async.css b/test/cases/disable-extract-func/both-async.css new file mode 100644 index 00000000..8a2b22cc --- /dev/null +++ b/test/cases/disable-extract-func/both-async.css @@ -0,0 +1,5 @@ +@import 'shared.css'; + +.both-async { + color: red; +} diff --git a/test/cases/disable-extract-func/both-page-async-disabled.css b/test/cases/disable-extract-func/both-page-async-disabled.css new file mode 100644 index 00000000..c4e99243 --- /dev/null +++ b/test/cases/disable-extract-func/both-page-async-disabled.css @@ -0,0 +1,3 @@ +.both-page-async-disabled { + color: yellow; +} diff --git a/test/cases/disable-extract-func/both-page-async.css b/test/cases/disable-extract-func/both-page-async.css new file mode 100644 index 00000000..b3336101 --- /dev/null +++ b/test/cases/disable-extract-func/both-page-async.css @@ -0,0 +1,3 @@ +.both-page-async { + color: cyan; +} diff --git a/test/cases/disable-extract-func/expected/1.css b/test/cases/disable-extract-func/expected/1.css new file mode 100644 index 00000000..ed97cafe --- /dev/null +++ b/test/cases/disable-extract-func/expected/1.css @@ -0,0 +1,12 @@ +.async-import { + background: black; +} + +.in-async-2 { + background: green; +} + +.both-page-async { + color: cyan; +} + diff --git a/test/cases/disable-extract-func/expected/1.js b/test/cases/disable-extract-func/expected/1.js new file mode 100644 index 00000000..87620fb6 --- /dev/null +++ b/test/cases/disable-extract-func/expected/1.js @@ -0,0 +1,199 @@ +(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[1],[ +/* 0 */, +/* 1 */, +/* 2 */, +/* 3 */, +/* 4 */, +/* 5 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _in_async__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6); +/* harmony import */ var _in_async__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_in_async__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _in_async2_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7); +/* harmony import */ var _in_async2_css__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_in_async2_css__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _in_async_css__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8); +/* harmony import */ var _in_async_css__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_in_async_css__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _both_async_css__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2); +/* harmony import */ var _both_async_css__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_both_async_css__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _both_page_async_disabled_css__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9); +/* harmony import */ var _both_page_async_disabled_css__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_both_page_async_disabled_css__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _both_page_async_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(10); +/* harmony import */ var _both_page_async_css__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_both_page_async_css__WEBPACK_IMPORTED_MODULE_5__); + + + + + + + + +// console.log('async.js'); + + +/***/ }), +/* 6 */ +/***/ (function(module, exports) { + +// console.log('in-async.js'); + + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + +// extracted by mini-css-extract-plugin + +/***/ }), +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { + +// Imports +var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(14); +var ___CSS_LOADER_AT_RULE_IMPORT_0___ = __webpack_require__(15); +exports = ___CSS_LOADER_API_IMPORT___(false); +exports.i(___CSS_LOADER_AT_RULE_IMPORT_0___); +// Module +exports.push([module.i, ".in-async {\n background: green;\n}\n", ""]); +// Exports +module.exports = exports; + + +/***/ }), +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { + +// Imports +var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(14); +exports = ___CSS_LOADER_API_IMPORT___(false); +// Module +exports.push([module.i, ".both-page-async-disabled {\n color: yellow;\n}\n", ""]); +// Exports +module.exports = exports; + + +/***/ }), +/* 10 */ +/***/ (function(module, exports, __webpack_require__) { + +// extracted by mini-css-extract-plugin + +/***/ }), +/* 11 */, +/* 12 */, +/* 13 */, +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +// css base code, injected by the css-loader +// eslint-disable-next-line func-names +module.exports = function (useSourceMap) { + var list = []; // return the list of modules as css string + + list.toString = function toString() { + return this.map(function (item) { + var content = cssWithMappingToString(item, useSourceMap); + + if (item[2]) { + return "@media ".concat(item[2], " {").concat(content, "}"); + } + + return content; + }).join(''); + }; // import a list of modules into the list + // eslint-disable-next-line func-names + + + list.i = function (modules, mediaQuery, dedupe) { + if (typeof modules === 'string') { + // eslint-disable-next-line no-param-reassign + modules = [[null, modules, '']]; + } + + var alreadyImportedModules = {}; + + if (dedupe) { + for (var i = 0; i < this.length; i++) { + // eslint-disable-next-line prefer-destructuring + var id = this[i][0]; + + if (id != null) { + alreadyImportedModules[id] = true; + } + } + } + + for (var _i = 0; _i < modules.length; _i++) { + var item = [].concat(modules[_i]); + + if (dedupe && alreadyImportedModules[item[0]]) { + // eslint-disable-next-line no-continue + continue; + } + + if (mediaQuery) { + if (!item[2]) { + item[2] = mediaQuery; + } else { + item[2] = "".concat(mediaQuery, " and ").concat(item[2]); + } + } + + list.push(item); + } + }; + + return list; +}; + +function cssWithMappingToString(item, useSourceMap) { + var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring + + var cssMapping = item[3]; + + if (!cssMapping) { + return content; + } + + if (useSourceMap && typeof btoa === 'function') { + var sourceMapping = toComment(cssMapping); + var sourceURLs = cssMapping.sources.map(function (source) { + return "/*# sourceURL=".concat(cssMapping.sourceRoot || '').concat(source, " */"); + }); + return [content].concat(sourceURLs).concat([sourceMapping]).join('\n'); + } + + return [content].join('\n'); +} // Adapted from convert-source-map (MIT) + + +function toComment(sourceMap) { + // eslint-disable-next-line no-undef + var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))); + var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64); + return "/*# ".concat(data, " */"); +} + +/***/ }), +/* 15 */ +/***/ (function(module, exports, __webpack_require__) { + +// Imports +var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(14); +exports = ___CSS_LOADER_API_IMPORT___(false); +// Module +exports.push([module.i, ".async-import {\n background: black;\n}\n", ""]); +// Exports +module.exports = exports; + + +/***/ }) +]]); \ No newline at end of file diff --git a/test/cases/disable-extract-func/expected/3.css b/test/cases/disable-extract-func/expected/3.css new file mode 100644 index 00000000..38c3dcad --- /dev/null +++ b/test/cases/disable-extract-func/expected/3.css @@ -0,0 +1,4 @@ +.both-page-async { + color: cyan; +} + diff --git a/test/cases/disable-extract-func/expected/3.js b/test/cases/disable-extract-func/expected/3.js new file mode 100644 index 00000000..ffcd0cd4 --- /dev/null +++ b/test/cases/disable-extract-func/expected/3.js @@ -0,0 +1,163 @@ +(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[3],[ +/* 0 */, +/* 1 */, +/* 2 */, +/* 3 */, +/* 4 */, +/* 5 */, +/* 6 */, +/* 7 */, +/* 8 */, +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { + +// Imports +var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(14); +exports = ___CSS_LOADER_API_IMPORT___(false); +// Module +exports.push([module.i, ".both-page-async-disabled {\n color: yellow;\n}\n", ""]); +// Exports +module.exports = exports; + + +/***/ }), +/* 10 */ +/***/ (function(module, exports, __webpack_require__) { + +// extracted by mini-css-extract-plugin + +/***/ }), +/* 11 */, +/* 12 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _both_page_async_disabled_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); +/* harmony import */ var _both_page_async_disabled_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_both_page_async_disabled_css__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _both_page_async_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10); +/* harmony import */ var _both_page_async_css__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_both_page_async_css__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _is_async1_css__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13); +/* harmony import */ var _is_async1_css__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_is_async1_css__WEBPACK_IMPORTED_MODULE_2__); + + + + +// console.log('async2.js'); + + +/***/ }), +/* 13 */ +/***/ (function(module, exports, __webpack_require__) { + +// Imports +var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(14); +exports = ___CSS_LOADER_API_IMPORT___(false); +// Module +exports.push([module.i, ".is-async-1 {\n background: magenta;\n}\n", ""]); +// Exports +module.exports = exports; + + +/***/ }), +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +// css base code, injected by the css-loader +// eslint-disable-next-line func-names +module.exports = function (useSourceMap) { + var list = []; // return the list of modules as css string + + list.toString = function toString() { + return this.map(function (item) { + var content = cssWithMappingToString(item, useSourceMap); + + if (item[2]) { + return "@media ".concat(item[2], " {").concat(content, "}"); + } + + return content; + }).join(''); + }; // import a list of modules into the list + // eslint-disable-next-line func-names + + + list.i = function (modules, mediaQuery, dedupe) { + if (typeof modules === 'string') { + // eslint-disable-next-line no-param-reassign + modules = [[null, modules, '']]; + } + + var alreadyImportedModules = {}; + + if (dedupe) { + for (var i = 0; i < this.length; i++) { + // eslint-disable-next-line prefer-destructuring + var id = this[i][0]; + + if (id != null) { + alreadyImportedModules[id] = true; + } + } + } + + for (var _i = 0; _i < modules.length; _i++) { + var item = [].concat(modules[_i]); + + if (dedupe && alreadyImportedModules[item[0]]) { + // eslint-disable-next-line no-continue + continue; + } + + if (mediaQuery) { + if (!item[2]) { + item[2] = mediaQuery; + } else { + item[2] = "".concat(mediaQuery, " and ").concat(item[2]); + } + } + + list.push(item); + } + }; + + return list; +}; + +function cssWithMappingToString(item, useSourceMap) { + var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring + + var cssMapping = item[3]; + + if (!cssMapping) { + return content; + } + + if (useSourceMap && typeof btoa === 'function') { + var sourceMapping = toComment(cssMapping); + var sourceURLs = cssMapping.sources.map(function (source) { + return "/*# sourceURL=".concat(cssMapping.sourceRoot || '').concat(source, " */"); + }); + return [content].concat(sourceURLs).concat([sourceMapping]).join('\n'); + } + + return [content].join('\n'); +} // Adapted from convert-source-map (MIT) + + +function toComment(sourceMap) { + // eslint-disable-next-line no-undef + var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))); + var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64); + return "/*# ".concat(data, " */"); +} + +/***/ }) +]]); \ No newline at end of file diff --git a/test/cases/disable-extract-func/expected/4.css b/test/cases/disable-extract-func/expected/4.css new file mode 100644 index 00000000..67332816 --- /dev/null +++ b/test/cases/disable-extract-func/expected/4.css @@ -0,0 +1,4 @@ +.async { + background: blue; +} + diff --git a/test/cases/disable-extract-func/expected/4.js b/test/cases/disable-extract-func/expected/4.js new file mode 100644 index 00000000..0391d394 --- /dev/null +++ b/test/cases/disable-extract-func/expected/4.js @@ -0,0 +1,10 @@ +(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[4],{ + +/***/ 11: +/***/ (function(module, exports, __webpack_require__) { + +// extracted by mini-css-extract-plugin + +/***/ }) + +}]); \ No newline at end of file diff --git a/test/cases/disable-extract-func/expected/index1.css b/test/cases/disable-extract-func/expected/index1.css new file mode 100644 index 00000000..c7bfe98b --- /dev/null +++ b/test/cases/disable-extract-func/expected/index1.css @@ -0,0 +1,12 @@ +.shared { + background: pink; +} + +body { + background: red; +} + +.both-async { + color: red; +} + diff --git a/test/cases/disable-extract-func/expected/index1.js b/test/cases/disable-extract-func/expected/index1.js new file mode 100644 index 00000000..2af7eb38 --- /dev/null +++ b/test/cases/disable-extract-func/expected/index1.js @@ -0,0 +1,281 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // install a JSONP callback for chunk loading +/******/ function webpackJsonpCallback(data) { +/******/ var chunkIds = data[0]; +/******/ var moreModules = data[1]; +/******/ +/******/ +/******/ // add "moreModules" to the modules object, +/******/ // then flag all "chunkIds" as loaded and fire callback +/******/ var moduleId, chunkId, i = 0, resolves = []; +/******/ for(;i < chunkIds.length; i++) { +/******/ chunkId = chunkIds[i]; +/******/ if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) { +/******/ resolves.push(installedChunks[chunkId][0]); +/******/ } +/******/ installedChunks[chunkId] = 0; +/******/ } +/******/ for(moduleId in moreModules) { +/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { +/******/ modules[moduleId] = moreModules[moduleId]; +/******/ } +/******/ } +/******/ if(parentJsonpFunction) parentJsonpFunction(data); +/******/ +/******/ while(resolves.length) { +/******/ resolves.shift()(); +/******/ } +/******/ +/******/ }; +/******/ +/******/ +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // object to store loaded CSS chunks +/******/ var installedCssChunks = { +/******/ 0: 0 +/******/ } +/******/ +/******/ // object to store loaded and loading chunks +/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched +/******/ // Promise = chunk loading, 0 = chunk loaded +/******/ var installedChunks = { +/******/ 0: 0 +/******/ }; +/******/ +/******/ +/******/ +/******/ // script path function +/******/ function jsonpScriptSrc(chunkId) { +/******/ return __webpack_require__.p + "" + ({}[chunkId]||chunkId) + ".js" +/******/ } +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ // This file contains only the entry chunk. +/******/ // The chunk loading function for additional chunks +/******/ __webpack_require__.e = function requireEnsure(chunkId) { +/******/ var promises = []; +/******/ +/******/ +/******/ // mini-css-extract-plugin CSS loading +/******/ var cssChunks = {"1":1,"4":1}; +/******/ if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]); +/******/ else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) { +/******/ promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) { +/******/ var href = "" + ({}[chunkId]||chunkId) + ".css"; +/******/ var fullhref = __webpack_require__.p + href; +/******/ var existingLinkTags = document.getElementsByTagName("link"); +/******/ for(var i = 0; i < existingLinkTags.length; i++) { +/******/ var tag = existingLinkTags[i]; +/******/ var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href"); +/******/ if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return resolve(); +/******/ } +/******/ var existingStyleTags = document.getElementsByTagName("style"); +/******/ for(var i = 0; i < existingStyleTags.length; i++) { +/******/ var tag = existingStyleTags[i]; +/******/ var dataHref = tag.getAttribute("data-href"); +/******/ if(dataHref === href || dataHref === fullhref) return resolve(); +/******/ } +/******/ var linkTag = document.createElement("link"); +/******/ linkTag.rel = "stylesheet"; +/******/ linkTag.type = "text/css"; +/******/ linkTag.onload = resolve; +/******/ linkTag.onerror = function(event) { +/******/ var request = event && event.target && event.target.src || fullhref; +/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")"); +/******/ err.code = "CSS_CHUNK_LOAD_FAILED"; +/******/ err.request = request; +/******/ delete installedCssChunks[chunkId] +/******/ linkTag.parentNode.removeChild(linkTag) +/******/ reject(err); +/******/ }; +/******/ linkTag.href = fullhref; +/******/ +/******/ var head = document.getElementsByTagName("head")[0]; +/******/ head.appendChild(linkTag); +/******/ }).then(function() { +/******/ installedCssChunks[chunkId] = 0; +/******/ })); +/******/ } +/******/ +/******/ // JSONP chunk loading for javascript +/******/ +/******/ var installedChunkData = installedChunks[chunkId]; +/******/ if(installedChunkData !== 0) { // 0 means "already installed". +/******/ +/******/ // a Promise means "currently loading". +/******/ if(installedChunkData) { +/******/ promises.push(installedChunkData[2]); +/******/ } else { +/******/ // setup Promise in chunk cache +/******/ var promise = new Promise(function(resolve, reject) { +/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject]; +/******/ }); +/******/ promises.push(installedChunkData[2] = promise); +/******/ +/******/ // start chunk loading +/******/ var script = document.createElement('script'); +/******/ var onScriptComplete; +/******/ +/******/ script.charset = 'utf-8'; +/******/ script.timeout = 120; +/******/ if (__webpack_require__.nc) { +/******/ script.setAttribute("nonce", __webpack_require__.nc); +/******/ } +/******/ script.src = jsonpScriptSrc(chunkId); +/******/ +/******/ // create error before stack unwound to get useful stacktrace later +/******/ var error = new Error(); +/******/ onScriptComplete = function (event) { +/******/ // avoid mem leaks in IE. +/******/ script.onerror = script.onload = null; +/******/ clearTimeout(timeout); +/******/ var chunk = installedChunks[chunkId]; +/******/ if(chunk !== 0) { +/******/ if(chunk) { +/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type); +/******/ var realSrc = event && event.target && event.target.src; +/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')'; +/******/ error.name = 'ChunkLoadError'; +/******/ error.type = errorType; +/******/ error.request = realSrc; +/******/ chunk[1](error); +/******/ } +/******/ installedChunks[chunkId] = undefined; +/******/ } +/******/ }; +/******/ var timeout = setTimeout(function(){ +/******/ onScriptComplete({ type: 'timeout', target: script }); +/******/ }, 120000); +/******/ script.onerror = script.onload = onScriptComplete; +/******/ document.head.appendChild(script); +/******/ } +/******/ } +/******/ return Promise.all(promises); +/******/ }; +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // on error function for async loading +/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; }; +/******/ +/******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; +/******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); +/******/ jsonpArray.push = webpackJsonpCallback; +/******/ jsonpArray = jsonpArray.slice(); +/******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); +/******/ var parentJsonpFunction = oldJsonpFunction; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _main_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); +/* harmony import */ var _main_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_main_css__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _both_async_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); +/* harmony import */ var _both_async_css__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_both_async_css__WEBPACK_IMPORTED_MODULE_1__); + + + +__webpack_require__.e(/* import() */ 1).then(__webpack_require__.bind(null, 5)); + +__webpack_require__.e(/* import() */ 4).then(__webpack_require__.t.bind(null, 11, 7)); + +// console.log('index.js'); + + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +// extracted by mini-css-extract-plugin + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +// extracted by mini-css-extract-plugin + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/cases/disable-extract-func/expected/index2.css b/test/cases/disable-extract-func/expected/index2.css new file mode 100644 index 00000000..566323a7 --- /dev/null +++ b/test/cases/disable-extract-func/expected/index2.css @@ -0,0 +1,4 @@ +.is-async-2 { + background: brown; +} + diff --git a/test/cases/disable-extract-func/expected/index2.js b/test/cases/disable-extract-func/expected/index2.js new file mode 100644 index 00000000..18873b2b --- /dev/null +++ b/test/cases/disable-extract-func/expected/index2.js @@ -0,0 +1,273 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // install a JSONP callback for chunk loading +/******/ function webpackJsonpCallback(data) { +/******/ var chunkIds = data[0]; +/******/ var moreModules = data[1]; +/******/ +/******/ +/******/ // add "moreModules" to the modules object, +/******/ // then flag all "chunkIds" as loaded and fire callback +/******/ var moduleId, chunkId, i = 0, resolves = []; +/******/ for(;i < chunkIds.length; i++) { +/******/ chunkId = chunkIds[i]; +/******/ if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) { +/******/ resolves.push(installedChunks[chunkId][0]); +/******/ } +/******/ installedChunks[chunkId] = 0; +/******/ } +/******/ for(moduleId in moreModules) { +/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { +/******/ modules[moduleId] = moreModules[moduleId]; +/******/ } +/******/ } +/******/ if(parentJsonpFunction) parentJsonpFunction(data); +/******/ +/******/ while(resolves.length) { +/******/ resolves.shift()(); +/******/ } +/******/ +/******/ }; +/******/ +/******/ +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // object to store loaded CSS chunks +/******/ var installedCssChunks = { +/******/ 2: 0 +/******/ } +/******/ +/******/ // object to store loaded and loading chunks +/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched +/******/ // Promise = chunk loading, 0 = chunk loaded +/******/ var installedChunks = { +/******/ 2: 0 +/******/ }; +/******/ +/******/ +/******/ +/******/ // script path function +/******/ function jsonpScriptSrc(chunkId) { +/******/ return __webpack_require__.p + "" + ({}[chunkId]||chunkId) + ".js" +/******/ } +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ // This file contains only the entry chunk. +/******/ // The chunk loading function for additional chunks +/******/ __webpack_require__.e = function requireEnsure(chunkId) { +/******/ var promises = []; +/******/ +/******/ +/******/ // mini-css-extract-plugin CSS loading +/******/ var cssChunks = {"3":1}; +/******/ if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]); +/******/ else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) { +/******/ promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) { +/******/ var href = "" + ({}[chunkId]||chunkId) + ".css"; +/******/ var fullhref = __webpack_require__.p + href; +/******/ var existingLinkTags = document.getElementsByTagName("link"); +/******/ for(var i = 0; i < existingLinkTags.length; i++) { +/******/ var tag = existingLinkTags[i]; +/******/ var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href"); +/******/ if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return resolve(); +/******/ } +/******/ var existingStyleTags = document.getElementsByTagName("style"); +/******/ for(var i = 0; i < existingStyleTags.length; i++) { +/******/ var tag = existingStyleTags[i]; +/******/ var dataHref = tag.getAttribute("data-href"); +/******/ if(dataHref === href || dataHref === fullhref) return resolve(); +/******/ } +/******/ var linkTag = document.createElement("link"); +/******/ linkTag.rel = "stylesheet"; +/******/ linkTag.type = "text/css"; +/******/ linkTag.onload = resolve; +/******/ linkTag.onerror = function(event) { +/******/ var request = event && event.target && event.target.src || fullhref; +/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")"); +/******/ err.code = "CSS_CHUNK_LOAD_FAILED"; +/******/ err.request = request; +/******/ delete installedCssChunks[chunkId] +/******/ linkTag.parentNode.removeChild(linkTag) +/******/ reject(err); +/******/ }; +/******/ linkTag.href = fullhref; +/******/ +/******/ var head = document.getElementsByTagName("head")[0]; +/******/ head.appendChild(linkTag); +/******/ }).then(function() { +/******/ installedCssChunks[chunkId] = 0; +/******/ })); +/******/ } +/******/ +/******/ // JSONP chunk loading for javascript +/******/ +/******/ var installedChunkData = installedChunks[chunkId]; +/******/ if(installedChunkData !== 0) { // 0 means "already installed". +/******/ +/******/ // a Promise means "currently loading". +/******/ if(installedChunkData) { +/******/ promises.push(installedChunkData[2]); +/******/ } else { +/******/ // setup Promise in chunk cache +/******/ var promise = new Promise(function(resolve, reject) { +/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject]; +/******/ }); +/******/ promises.push(installedChunkData[2] = promise); +/******/ +/******/ // start chunk loading +/******/ var script = document.createElement('script'); +/******/ var onScriptComplete; +/******/ +/******/ script.charset = 'utf-8'; +/******/ script.timeout = 120; +/******/ if (__webpack_require__.nc) { +/******/ script.setAttribute("nonce", __webpack_require__.nc); +/******/ } +/******/ script.src = jsonpScriptSrc(chunkId); +/******/ +/******/ // create error before stack unwound to get useful stacktrace later +/******/ var error = new Error(); +/******/ onScriptComplete = function (event) { +/******/ // avoid mem leaks in IE. +/******/ script.onerror = script.onload = null; +/******/ clearTimeout(timeout); +/******/ var chunk = installedChunks[chunkId]; +/******/ if(chunk !== 0) { +/******/ if(chunk) { +/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type); +/******/ var realSrc = event && event.target && event.target.src; +/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')'; +/******/ error.name = 'ChunkLoadError'; +/******/ error.type = errorType; +/******/ error.request = realSrc; +/******/ chunk[1](error); +/******/ } +/******/ installedChunks[chunkId] = undefined; +/******/ } +/******/ }; +/******/ var timeout = setTimeout(function(){ +/******/ onScriptComplete({ type: 'timeout', target: script }); +/******/ }, 120000); +/******/ script.onerror = script.onload = onScriptComplete; +/******/ document.head.appendChild(script); +/******/ } +/******/ } +/******/ return Promise.all(promises); +/******/ }; +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // on error function for async loading +/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; }; +/******/ +/******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; +/******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); +/******/ jsonpArray.push = webpackJsonpCallback; +/******/ jsonpArray = jsonpArray.slice(); +/******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); +/******/ var parentJsonpFunction = oldJsonpFunction; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 3); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */, +/* 1 */, +/* 2 */, +/* 3 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _is_async2_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4); +/* harmony import */ var _is_async2_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_is_async2_css__WEBPACK_IMPORTED_MODULE_0__); + + +__webpack_require__.e(/* import() */ 3).then(__webpack_require__.bind(null, 12)); + +// console.log('index2'); + + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +// extracted by mini-css-extract-plugin + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/cases/disable-extract-func/in-async.css b/test/cases/disable-extract-func/in-async.css new file mode 100644 index 00000000..922b9d89 --- /dev/null +++ b/test/cases/disable-extract-func/in-async.css @@ -0,0 +1,5 @@ +@import './async-import.css'; + +.in-async { + background: green; +} diff --git a/test/cases/disable-extract-func/in-async.js b/test/cases/disable-extract-func/in-async.js new file mode 100644 index 00000000..33611214 --- /dev/null +++ b/test/cases/disable-extract-func/in-async.js @@ -0,0 +1 @@ +// console.log('in-async.js'); diff --git a/test/cases/disable-extract-func/in-async2.css b/test/cases/disable-extract-func/in-async2.css new file mode 100644 index 00000000..28781c21 --- /dev/null +++ b/test/cases/disable-extract-func/in-async2.css @@ -0,0 +1,5 @@ +@import './async-import.css'; + +.in-async-2 { + background: green; +} diff --git a/test/cases/disable-extract-func/index.js b/test/cases/disable-extract-func/index.js new file mode 100644 index 00000000..13a5bbe1 --- /dev/null +++ b/test/cases/disable-extract-func/index.js @@ -0,0 +1,8 @@ +import './main.css'; +import './both-async.css'; + +import('./async'); + +import('./async.css'); + +// console.log('index.js'); diff --git a/test/cases/disable-extract-func/index2.js b/test/cases/disable-extract-func/index2.js new file mode 100644 index 00000000..3a4cea27 --- /dev/null +++ b/test/cases/disable-extract-func/index2.js @@ -0,0 +1,5 @@ +import './is-async2.css'; + +import('./async2'); + +// console.log('index2'); diff --git a/test/cases/disable-extract-func/is-async1.css b/test/cases/disable-extract-func/is-async1.css new file mode 100644 index 00000000..ca7b2c9c --- /dev/null +++ b/test/cases/disable-extract-func/is-async1.css @@ -0,0 +1,3 @@ +.is-async-1 { + background: magenta; +} diff --git a/test/cases/disable-extract-func/is-async2.css b/test/cases/disable-extract-func/is-async2.css new file mode 100644 index 00000000..f815dcf1 --- /dev/null +++ b/test/cases/disable-extract-func/is-async2.css @@ -0,0 +1,3 @@ +.is-async-2 { + background: brown; +} diff --git a/test/cases/disable-extract-func/main.css b/test/cases/disable-extract-func/main.css new file mode 100644 index 00000000..584e42d4 --- /dev/null +++ b/test/cases/disable-extract-func/main.css @@ -0,0 +1,5 @@ +@import 'shared.css'; + +body { + background: red; +} diff --git a/test/cases/disable-extract-func/shared.css b/test/cases/disable-extract-func/shared.css new file mode 100644 index 00000000..0a1ca625 --- /dev/null +++ b/test/cases/disable-extract-func/shared.css @@ -0,0 +1,3 @@ +.shared { + background: pink; +} diff --git a/test/cases/disable-extract-func/webpack.config.js b/test/cases/disable-extract-func/webpack.config.js new file mode 100644 index 00000000..ade3522a --- /dev/null +++ b/test/cases/disable-extract-func/webpack.config.js @@ -0,0 +1,32 @@ +import Self from '../../../src'; + +module.exports = { + entry: { + index1: './index.js', + index2: './index2.js', + }, + module: { + rules: [ + { + test: /\.css$/, + use: [Self.loader, 'css-loader'], + }, + ], + }, + plugins: [ + new Self({ + filename: '[name].css', + disableExtract({ module, isAsync }) { + let ret = false; + if ( + module.content.indexOf('in-async ') > -1 || + module.content.indexOf('both-page-async-disabled') > -1 || + (module.content.indexOf('is-async') > -1 && isAsync) + ) { + ret = true; + } + return ret; + }, + }), + ], +}; diff --git a/test/manual/index.html b/test/manual/index.html index c95108db..bdbc9ec8 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -45,6 +45,7 @@

Lazy CSS: Must be red, but turn green when .

But turn orange, when . Additional clicks have no effect.

Refresh and press buttons in reverse order: This should turn green instead.

+

This should turn yellow after pressing "lazy-button" without loading extra css file containing "async-disabled.css".

Lazy CSS: Turn off the network and .

diff --git a/test/manual/src/async-disabled.css b/test/manual/src/async-disabled.css new file mode 100644 index 00000000..25eeb6ce --- /dev/null +++ b/test/manual/src/async-disabled.css @@ -0,0 +1,3 @@ +.async-disabled { + background: yellow; +} diff --git a/test/manual/src/lazy.js b/test/manual/src/lazy.js index faacb3a2..23bc08cb 100644 --- a/test/manual/src/lazy.js +++ b/test/manual/src/lazy.js @@ -1,3 +1,4 @@ /* eslint-env browser */ import './lazy.css'; +import './async-disabled.css'; diff --git a/test/manual/webpack.config.js b/test/manual/webpack.config.js index 3d308a6c..0b0a2e29 100644 --- a/test/manual/webpack.config.js +++ b/test/manual/webpack.config.js @@ -12,6 +12,7 @@ const ENABLE_ES_MODULE = module.exports = { mode: 'development', + devtool: 'cheap-source-map', output: { chunkFilename: '[contenthash].js', publicPath: '/dist/', @@ -23,6 +24,9 @@ module.exports = { test: /\.css$/, exclude: [/\.module\.css$/i], use: [ + { + loader : 'style-loader', + }, { loader: Self.loader, options: { @@ -61,6 +65,13 @@ module.exports = { new Self({ filename: '[name].css', chunkFilename: '[contenthash].css', + disableExtract({ module }) { + let ret = false; + if (module.content.indexOf('async-disabled') > -1) { + ret = true; + } + return ret; + }, }), ], devServer: {