From 0a3362d46cd741a154f944bcf1b2e446aaa1d6c2 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 24 Sep 2020 10:14:26 +0200 Subject: [PATCH 1/5] chore(webpack-5): update for webpack 5 update manual test cases update CssModule for webpack 5 (to avoid deprecation) clean up inconsistency in loader --- src/CssModule.js | 25 ++++++++++++++++++++++++- src/loader.js | 11 +++++++---- test/manual/index.html | 11 +++++++---- test/manual/src/index.js | 23 ++++++++++++++++++++++- test/manual/src/lazy.module.css | 3 +++ test/manual/webpack.config.js | 4 ++-- 6 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 test/manual/src/lazy.module.css diff --git a/src/CssModule.js b/src/CssModule.js index 80839d62..3bdac2d9 100644 --- a/src/CssModule.js +++ b/src/CssModule.js @@ -2,6 +2,12 @@ import webpack from 'webpack'; import { MODULE_TYPE } from './utils'; +const TYPES = new Set([MODULE_TYPE]); +const CODE_GENERATION_RESULT = { + sources: new Map(), + runtimeRequirements: new Set(), +}; + class CssModule extends webpack.Module { constructor({ context, @@ -20,9 +26,11 @@ class CssModule extends webpack.Module { this.content = content; this.media = media; this.sourceMap = sourceMap; + this.buildInfo = {}; + this.buildMeta = {}; } - // no source() so webpack doesn't do add stuff to the bundle + // no source() so webpack 4 doesn't do add stuff to the bundle size() { return this.content.length; @@ -38,6 +46,16 @@ class CssModule extends webpack.Module { }`; } + // eslint-disable-next-line class-methods-use-this + getSourceTypes() { + return TYPES; + } + + // eslint-disable-next-line class-methods-use-this + codeGeneration() { + return CODE_GENERATION_RESULT; + } + nameForCondition() { const resource = this._identifier.split('!').pop(); const idx = resource.indexOf('?'); @@ -60,6 +78,11 @@ class CssModule extends webpack.Module { return true; } + // eslint-disable-next-line class-methods-use-this + needBuild(context, callback) { + callback(null, false); + } + build(options, compilation, resolver, fileSystem, callback) { this.buildInfo = {}; this.buildMeta = {}; diff --git a/src/loader.js b/src/loader.js index ff9e7f84..d1a4c373 100644 --- a/src/loader.js +++ b/src/loader.js @@ -192,11 +192,10 @@ export function pitch(request) { : originalExports; if (namedExport) { - locals = ''; - Object.keys(originalExports).forEach((key) => { if (key !== 'default') { - locals += `\nexport const ${key} = "${originalExports[key]}";`; + if (!locals) locals = {}; + locals[key] = originalExports[key]; } }); } else { @@ -228,7 +227,11 @@ export function pitch(request) { const result = locals ? namedExport - ? locals + ? Object.keys(locals) + .map( + (key) => `\nexport const ${key} = ${JSON.stringify(locals[key])};` + ) + .join('') : `\n${ esModule ? 'export default' : 'module.exports =' } ${JSON.stringify(locals)};` diff --git a/test/manual/index.html b/test/manual/index.html index c95108db..26b9e7c9 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -5,7 +5,7 @@ mini-css-extract-plugin testcase - + -