Skip to content

Commit

Permalink
feat(vite-plugin-angular): add include configuration for analog file …
Browse files Browse the repository at this point in the history
…globs (#882)
  • Loading branch information
joshuamorony authored Feb 9, 2024
1 parent 68283f8 commit 00baaf4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
29 changes: 25 additions & 4 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export interface PluginOptions {
/**
* Enable experimental support for Analog file extension
*/
supportAnalogFormat?: boolean;
supportAnalogFormat?:
| boolean
| {
include: string[];
};
};
supportedBrowsers?: string[];
transformFilter?: (code: string, id: string) => boolean;
Expand Down Expand Up @@ -424,17 +428,34 @@ export function angular(options?: PluginOptions): Plugin[] {
].filter(Boolean) as Plugin[];

function findAnalogFiles(config: UserConfig) {
if (!pluginOptions.supportAnalogFormat) {
const analogConfig = pluginOptions.supportAnalogFormat;
if (!analogConfig) {
return [];
}

let extraGlobs: string[] = [];

if (typeof analogConfig === 'object') {
if (analogConfig.include) {
extraGlobs = analogConfig.include;
}
}

const fg = require('fast-glob');
const root = normalizePath(
const appRoot = normalizePath(
path.resolve(pluginOptions.workspaceRoot, config.root || '.')
);
const workspaceRoot = normalizePath(
path.resolve(pluginOptions.workspaceRoot)
);

const globs = [
`${appRoot}/**/*.{analog,agx}`,
...extraGlobs.map((glob) => `${workspaceRoot}${glob}.{analog,agx}`),
];

return fg
.sync([`${root}/**/*.analog`, `${root}/**/*.agx`], {
.sync(globs, {
dot: true,
})
.map((file: string) => `${file}.ts`);
Expand Down
7 changes: 6 additions & 1 deletion packages/vite-plugin-angular/src/lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export function augmentHostWithResources(
) => ReturnType<any> | null,
options: {
inlineStylesExtension?: string;
supportAnalogFormat?: boolean;
supportAnalogFormat?:
| boolean
| {
include: string[];
};

isProd?: boolean;
} = {}
) {
Expand Down

0 comments on commit 00baaf4

Please sign in to comment.