|
1 |
| -import path from "path"; |
| 1 | +const path = require("path"); |
2 | 2 |
|
3 |
| -import { |
| 3 | +const { |
4 | 4 | findModuleById,
|
5 | 5 | evalModuleCode,
|
6 | 6 | AUTO_PUBLIC_PATH,
|
7 | 7 | ABSOLUTE_PUBLIC_PATH,
|
8 | 8 | SINGLE_DOT_PATH_SEGMENT,
|
9 | 9 | stringifyRequest,
|
10 |
| -} from "./utils"; |
11 |
| -import schema from "./loader-options.json"; |
| 10 | +} = require("./utils"); |
| 11 | +const schema = require("./loader-options.json"); |
12 | 12 |
|
13 |
| -import MiniCssExtractPlugin, { pluginName, pluginSymbol } from "./index"; |
| 13 | +const MiniCssExtractPlugin = require("./index"); |
14 | 14 |
|
15 | 15 | /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
|
16 | 16 | /** @typedef {import("webpack").Compiler} Compiler */
|
@@ -65,11 +65,13 @@ function hotLoader(content, context) {
|
65 | 65 | * @this {import("webpack").LoaderContext<LoaderOptions>}
|
66 | 66 | * @param {string} request
|
67 | 67 | */
|
68 |
| -export function pitch(request) { |
| 68 | +function pitch(request) { |
69 | 69 | // @ts-ignore
|
70 | 70 | const options = this.getOptions(/** @type {Schema} */ (schema));
|
71 | 71 | const callback = this.async();
|
72 |
| - const optionsFromPlugin = /** @type {TODO} */ (this)[pluginSymbol]; |
| 72 | + const optionsFromPlugin = /** @type {TODO} */ (this)[ |
| 73 | + MiniCssExtractPlugin.pluginSymbol |
| 74 | + ]; |
73 | 75 |
|
74 | 76 | if (!optionsFromPlugin) {
|
75 | 77 | callback(
|
@@ -240,7 +242,7 @@ export function pitch(request) {
|
240 | 242 | ? `\nexport {};`
|
241 | 243 | : "";
|
242 | 244 |
|
243 |
| - let resultSource = `// extracted by ${pluginName}`; |
| 245 | + let resultSource = `// extracted by ${MiniCssExtractPlugin.pluginName}`; |
244 | 246 |
|
245 | 247 | resultSource += this.hot
|
246 | 248 | ? hotLoader(result, { context: this.context, options, locals })
|
@@ -332,7 +334,7 @@ export function pitch(request) {
|
332 | 334 | const childCompiler =
|
333 | 335 | /** @type {Compilation} */
|
334 | 336 | (this._compilation).createChildCompiler(
|
335 |
| - `${pluginName} ${request}`, |
| 337 | + `${MiniCssExtractPlugin.pluginName} ${request}`, |
336 | 338 | outputOptions
|
337 | 339 | );
|
338 | 340 |
|
@@ -377,52 +379,58 @@ export function pitch(request) {
|
377 | 379 | const { NormalModule } = webpack;
|
378 | 380 |
|
379 | 381 | childCompiler.hooks.thisCompilation.tap(
|
380 |
| - `${pluginName} loader`, |
| 382 | + `${MiniCssExtractPlugin.pluginName} loader`, |
381 | 383 | /**
|
382 | 384 | * @param {Compilation} compilation
|
383 | 385 | */
|
384 | 386 | (compilation) => {
|
385 | 387 | const normalModuleHook =
|
386 | 388 | NormalModule.getCompilationHooks(compilation).loader;
|
387 | 389 |
|
388 |
| - normalModuleHook.tap(`${pluginName} loader`, (loaderContext, module) => { |
389 |
| - if (module.request === request) { |
390 |
| - // eslint-disable-next-line no-param-reassign |
391 |
| - module.loaders = loaders.map((loader) => { |
392 |
| - return { |
393 |
| - type: null, |
394 |
| - // @ts-ignore |
395 |
| - loader: loader.path, |
396 |
| - options: loader.options, |
397 |
| - ident: loader.ident, |
398 |
| - }; |
399 |
| - }); |
| 390 | + normalModuleHook.tap( |
| 391 | + `${MiniCssExtractPlugin.pluginName} loader`, |
| 392 | + (loaderContext, module) => { |
| 393 | + if (module.request === request) { |
| 394 | + // eslint-disable-next-line no-param-reassign |
| 395 | + module.loaders = loaders.map((loader) => { |
| 396 | + return { |
| 397 | + type: null, |
| 398 | + // @ts-ignore |
| 399 | + loader: loader.path, |
| 400 | + options: loader.options, |
| 401 | + ident: loader.ident, |
| 402 | + }; |
| 403 | + }); |
| 404 | + } |
400 | 405 | }
|
401 |
| - }); |
| 406 | + ); |
402 | 407 | }
|
403 | 408 | );
|
404 | 409 |
|
405 | 410 | /** @type {string | Buffer} */
|
406 | 411 | let source;
|
407 | 412 |
|
408 | 413 | childCompiler.hooks.compilation.tap(
|
409 |
| - pluginName, |
| 414 | + MiniCssExtractPlugin.pluginName, |
410 | 415 | /**
|
411 | 416 | * @param {Compilation} compilation
|
412 | 417 | */
|
413 | 418 | (compilation) => {
|
414 |
| - compilation.hooks.processAssets.tap(pluginName, () => { |
415 |
| - source = |
416 |
| - compilation.assets[childFilename] && |
417 |
| - compilation.assets[childFilename].source(); |
418 |
| - |
419 |
| - // Remove all chunk assets |
420 |
| - compilation.chunks.forEach((chunk) => { |
421 |
| - chunk.files.forEach((file) => { |
422 |
| - compilation.deleteAsset(file); |
| 419 | + compilation.hooks.processAssets.tap( |
| 420 | + MiniCssExtractPlugin.pluginName, |
| 421 | + () => { |
| 422 | + source = |
| 423 | + compilation.assets[childFilename] && |
| 424 | + compilation.assets[childFilename].source(); |
| 425 | + |
| 426 | + // Remove all chunk assets |
| 427 | + compilation.chunks.forEach((chunk) => { |
| 428 | + chunk.files.forEach((file) => { |
| 429 | + compilation.deleteAsset(file); |
| 430 | + }); |
423 | 431 | });
|
424 |
| - }); |
425 |
| - }); |
| 432 | + } |
| 433 | + ); |
426 | 434 | }
|
427 | 435 | );
|
428 | 436 |
|
@@ -478,5 +486,4 @@ export function pitch(request) {
|
478 | 486 | });
|
479 | 487 | }
|
480 | 488 |
|
481 |
| -// eslint-disable-next-line func-names |
482 |
| -export default function () {} |
| 489 | +module.exports = { default: function loader() {}, pitch }; |
0 commit comments