Skip to content

Commit

Permalink
feat(vue): support for the loader analysis with vue-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 committed Aug 13, 2024
1 parent 18c95d0 commit 66e1a9e
Show file tree
Hide file tree
Showing 3 changed files with 11,947 additions and 9,053 deletions.
16 changes: 12 additions & 4 deletions packages/rspack-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
import {
Constants,
Linter,
Manifest,
Manifest as ManifestType,
Plugin,
} from '@rsdoctor/types';
Expand Down Expand Up @@ -110,11 +111,18 @@ export class RsdoctorRspackPlugin<Rules extends Linter.ExtendRuleData[]>
compiler,
);

if (this.options.features.loader && !Loader.isVue(compiler)) {
if (this.options.features.loader) {
new ProbeLoaderPlugin().apply(compiler);
new InternalLoaderPlugin<Plugin.BaseCompilerType<'rspack'>>(this).apply(
compiler,
);
// add loader page to client
this.sdk.addClientRoutes([
Manifest.RsdoctorManifestClientRoutes.WebpackLoaders,
]);

if (!Loader.isVue(compiler)) {
new InternalLoaderPlugin<Plugin.BaseCompilerType<'rspack'>>(this).apply(
compiler,
);
}
}

if (this.options.features.plugins) {
Expand Down
12 changes: 12 additions & 0 deletions packages/rspack-plugin/src/probeLoaderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import { Plugin } from '@rsdoctor/types';
import type { RuleSetRules } from '@rspack/core';
import { Build } from '@rsdoctor/core';
import { Loader } from '@rsdoctor/utils/common';

const BuiltinLoaderName = 'builtin:swc-loader';
const ESMLoaderFile = '.mjs';
Expand Down Expand Up @@ -40,6 +41,7 @@ export class ProbeLoaderPlugin {
loader: path.join(__dirname, './probeLoader.js'),
options: {
..._options,
ident: undefined,
type: 'end',
builderName: compiler.options.name,
},
Expand All @@ -49,6 +51,7 @@ export class ProbeLoaderPlugin {
loader: path.join(__dirname, './probeLoader.js'),
options: {
..._options,
ident: undefined,
type: 'start',
builderName: compiler.options.name,
},
Expand All @@ -57,6 +60,15 @@ export class ProbeLoaderPlugin {
return rule;
};

if (Loader.isVue(compiler)) {
compiler.options.module.rules = Utils.addProbeLoader2Rules(
rules,
appendRule,
(r: Plugin.BuildRuleSetRule) => !!r.loader,
) as RuleSetRules;
return;
}

compiler.options.module.rules = Utils.addProbeLoader2Rules(
rules,
appendRule,
Expand Down
Loading

0 comments on commit 66e1a9e

Please sign in to comment.