Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
feat: allow angular resolver configuration via webpack.config
Browse files Browse the repository at this point in the history
  • Loading branch information
ventsislav-georgiev committed Feb 15, 2019
1 parent e2714f2 commit 4f3e8a6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions host/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { parse, join } from "path";
import { statSync } from "fs";

export function getResolver(platforms: string[], explicitResolve: string[] = []) {
const platformSpecificExt = [".ts", ".js", ".scss", ".less", ".css", ".html", ".xml", ".vue", ".json"];
const nsPackageFilters = [
'nativescript',
'tns',
'ns'
];
export function getResolver(platforms: string[], options: { nsPackageFilters?: string[], explicitResolve?: string[], platformSpecificExt?: string[] } = {}) {
options.nsPackageFilters = options.nsPackageFilters || ['nativescript', 'tns', 'ns'];
options.explicitResolve = options.explicitResolve || [];
options.platformSpecificExt = options.platformSpecificExt || [".ts", ".js", ".scss", ".less", ".css", ".html", ".xml", ".vue", ".json"];

const { nsPackageFilters, explicitResolve, platformSpecificExt } = options;

return function (path: string) {
const nmIndex = path.lastIndexOf('node_modules');
Expand All @@ -16,7 +15,7 @@ export function getResolver(platforms: string[], explicitResolve: string[] = [])
const subPath = path.substr(nmIndex + 'node_modules'.length).replace(/\\/g, '/');
const shouldResolve = explicitResolve.length && explicitResolve.some(packageName => subPath.indexOf(packageName) !== -1);
const pathParts = subPath.split(/[/\-_]/);

if (!shouldResolve && pathParts.every(p => nsPackageFilters.every(f => f !== p))) {
return path;
}
Expand Down

0 comments on commit 4f3e8a6

Please sign in to comment.