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 ca58448 commit ec0d240
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"dev": "npm run start",
"build": "modern build",
"start": "modern build -w",
"test": "vitest run"
"test": "vitest run -u"
},
"dependencies": {
"@rsdoctor/graph": "workspace:*",
Expand Down
26 changes: 21 additions & 5 deletions packages/core/src/build-utils/build/utils/loader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getOptions } from 'loader-utils';
import path from 'path';
import fse from 'fs-extra';
import { omit, findIndex } from 'lodash';
import { cloneDeep, omit } from 'lodash';
import { Loader } from '@rsdoctor/utils/common';
import type { Common, Plugin } from '@rsdoctor/types';
import { Rule, SourceMapInput as WebpackSourceMapInput } from '../../../types';
Expand Down Expand Up @@ -236,6 +236,7 @@ export function addProbeLoader2Rules<T extends Plugin.BuildRuleSetRule>(
{
loader: rule.loader,
options: rule.options,
ident: ('ident' in rule && rule.ident) || undefined,
},
],
loader: undefined,
Expand All @@ -246,11 +247,26 @@ export function addProbeLoader2Rules<T extends Plugin.BuildRuleSetRule>(

if (rule.use) {
if (Array.isArray(rule.use)) {
const _index = findIndex(rule.use, (_r) => fn(_r as T));
if (_index > -1) {
return appendRules(rule, _index);
const indexList = rule.use.map((_r, index) => {
if (fn(_r as T)) {
return index;
}
});

let _rule2 = cloneDeep(rule);

if (indexList.length) {
indexList.forEach((i, _index) => {
if (i !== undefined) {
_rule2 = appendRules(_rule2, i + _index * 2);
}
});
}
} else if (

return _rule2;
}

if (
typeof rule.use === 'object' &&
!Array.isArray(rule.use) &&
typeof rule.use !== 'function'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports[`test src/build/utils/loader.ts addProbeLoader2Rules > addProbeLoader2Ru
{
"loader": "probe",
"options": {
"ident": undefined,
"loader": "builtin:swc-loader",
"options": {
"jsc": {
Expand All @@ -40,6 +41,7 @@ exports[`test src/build/utils/loader.ts addProbeLoader2Rules > addProbeLoader2Ru
},
},
{
"ident": undefined,
"loader": "builtin:swc-loader",
"options": {
"jsc": {
Expand All @@ -54,6 +56,7 @@ exports[`test src/build/utils/loader.ts addProbeLoader2Rules > addProbeLoader2Ru
{
"loader": "probe",
"options": {
"ident": undefined,
"loader": "builtin:swc-loader",
"options": {
"jsc": {
Expand Down Expand Up @@ -82,6 +85,7 @@ exports[`test src/build/utils/loader.ts addProbeLoader2Rules > addProbeLoader2Ru
{
"loader": "probe",
"options": {
"ident": undefined,
"loader": "builtin:swc-loader",
"options": {
"jsc": {
Expand All @@ -96,6 +100,7 @@ exports[`test src/build/utils/loader.ts addProbeLoader2Rules > addProbeLoader2Ru
},
},
{
"ident": undefined,
"loader": "builtin:swc-loader",
"options": {
"jsc": {
Expand All @@ -110,6 +115,7 @@ exports[`test src/build/utils/loader.ts addProbeLoader2Rules > addProbeLoader2Ru
{
"loader": "probe",
"options": {
"ident": undefined,
"loader": "builtin:swc-loader",
"options": {
"jsc": {
Expand Down
11 changes: 9 additions & 2 deletions packages/webpack-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
} from '@rsdoctor/core/types';
import { ChunkGraph, ModuleGraph } from '@rsdoctor/graph';
import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
import { Constants, Linter } from '@rsdoctor/types';
import { Constants, Linter, Manifest } from '@rsdoctor/types';
import { Process } from '@rsdoctor/utils/build';
import { debug } from '@rsdoctor/utils/logger';
import { cloneDeep } from 'lodash';
Expand Down Expand Up @@ -99,7 +99,14 @@ export class RsdoctorWebpackPlugin<Rules extends Linter.ExtendRuleData[]>
}

if (this.options.features.plugins) {
new InternalPluginsPlugin<Compiler>(this).apply(compiler);
if (Loader.isVue(compiler)) {
this.sdk.addClientRoutes([
Manifest.RsdoctorManifestClientRoutes.WebpackLoaders,
]);
new InternalLoaderPlugin(this).apply(compiler);
} else {
new InternalPluginsPlugin<Compiler>(this).apply(compiler);
}
}

if (this.options.features.bundle) {
Expand Down

0 comments on commit ec0d240

Please sign in to comment.