feat(wepback): custom buildPathsupport (#10477)

Co-authored-by: farfromrefuge <dev@akylas.fr>
This commit is contained in:
Igor Randjelovic
2024-01-19 20:23:25 +01:00
committed by GitHub
parent ca886b9a1f
commit 429328495c
12 changed files with 26 additions and 19 deletions

View File

@ -13,6 +13,7 @@ import {
getPlatformName, getPlatformName,
} from '../helpers/platform'; } from '../helpers/platform';
import base from './base'; import base from './base';
// until we can switch to async/await on the webpack config, copy this from '@angular/compiler-cli' // until we can switch to async/await on the webpack config, copy this from '@angular/compiler-cli'
const GLOBAL_DEFS_FOR_TERSER = { const GLOBAL_DEFS_FOR_TERSER = {
ngDevMode: false, ngDevMode: false,

View File

@ -11,11 +11,11 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import TerserPlugin from 'terser-webpack-plugin'; import TerserPlugin from 'terser-webpack-plugin';
import { getProjectFilePath, getProjectTSConfigPath } from '../helpers/project';
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin'; import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
import { applyFileReplacements } from '../helpers/fileReplacements'; import { applyFileReplacements } from '../helpers/fileReplacements';
import { addCopyRule, applyCopyRules } from '../helpers/copyRules'; import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
import { WatchStatePlugin } from '../plugins/WatchStatePlugin'; import { WatchStatePlugin } from '../plugins/WatchStatePlugin';
import { getProjectFilePath, getProjectTSConfigPath } from '../helpers/project';
import { hasDependency } from '../helpers/dependencies'; import { hasDependency } from '../helpers/dependencies';
import { applyDotEnvPlugin } from '../helpers/dotEnv'; import { applyDotEnvPlugin } from '../helpers/dotEnv';
import { env as _env, IWebpackEnv } from '../index'; import { env as _env, IWebpackEnv } from '../index';
@ -84,7 +84,9 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
// when using hidden-source-map, output source maps to the `platforms/{platformName}-sourceMaps` folder // when using hidden-source-map, output source maps to the `platforms/{platformName}-sourceMaps` folder
if (env.sourceMap === 'hidden-source-map') { if (env.sourceMap === 'hidden-source-map') {
const sourceMapAbsolutePath = getProjectFilePath( const sourceMapAbsolutePath = getProjectFilePath(
`./platforms/${platform}-sourceMaps/[file].map[query]` `./${
env.buildPath ?? 'platforms'
}/${platform}-sourceMaps/[file].map[query]`
); );
const sourceMapRelativePath = relative(outputPath, sourceMapAbsolutePath); const sourceMapRelativePath = relative(outputPath, sourceMapAbsolutePath);
config.output.sourceMapFilename(sourceMapRelativePath); config.output.sourceMapFilename(sourceMapRelativePath);
@ -131,7 +133,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
config.watchOptions({ config.watchOptions({
ignored: [ ignored: [
`${getProjectFilePath('platforms')}/**`, `${getProjectFilePath(env.buildPath ?? 'platforms')}/**`,
`${getProjectFilePath(env.appResourcesPath ?? 'App_Resources')}/**`, `${getProjectFilePath(env.appResourcesPath ?? 'App_Resources')}/**`,
], ],
}); });

View File

@ -1,9 +1,7 @@
import CopyWebpackPlugin from 'copy-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin';
import { basename, relative, resolve } from 'path';
import Config from 'webpack-chain'; import Config from 'webpack-chain';
import { sync as globbySync } from 'globby'; import { basename } from 'path';
import { getProjectRootPath } from './project';
import { getEntryDirPath } from './platform'; import { getEntryDirPath } from './platform';
import { env } from '..'; import { env } from '..';

View File

@ -1,8 +1,8 @@
import { resolve } from 'path'; import { resolve } from 'path';
import { env as _env, IWebpackEnv } from '../index'; import { env as _env, IWebpackEnv } from '../index';
import { addCopyRule } from './copyRules';
import { getProjectRootPath } from './project'; import { getProjectRootPath } from './project';
import { addCopyRule } from './copyRules';
interface IReplacementMap { interface IReplacementMap {
[_replace: string]: /* _with */ string; [_replace: string]: /* _with */ string;

View File

@ -10,6 +10,7 @@ import { applyFileReplacements } from './fileReplacements';
import { addCopyRule, removeCopyRule } from './copyRules'; import { addCopyRule, removeCopyRule } from './copyRules';
import { error, info, warn, warnOnce } from './log'; import { error, info, warn, warnOnce } from './log';
import { determineProjectFlavor } from './flavor'; import { determineProjectFlavor } from './flavor';
import { readTsConfig } from './typescript';
import { getValue } from './config'; import { getValue } from './config';
import { getIPS } from './host'; import { getIPS } from './host';
import { import {
@ -26,7 +27,6 @@ import {
getPlatform, getPlatform,
getPlatformName, getPlatformName,
} from './platform'; } from './platform';
import { readTsConfig } from './typescript';
// intentionally populated manually // intentionally populated manually
// as this generates nicer typings // as this generates nicer typings

View File

@ -1,5 +1,5 @@
import dedent from 'ts-dedent';
import { env } from '@nativescript/webpack'; import { env } from '@nativescript/webpack';
import dedent from 'ts-dedent';
// de-indents strings so multi-line string literals can be used // de-indents strings so multi-line string literals can be used
function cleanup(data: any[]) { function cleanup(data: any[]) {

View File

@ -138,7 +138,7 @@ export function getDistPath() {
} }
// fallback to a generic platforms/<platform>/dist folder // fallback to a generic platforms/<platform>/dist folder
return `platforms/${getPlatformName()}/dist`; return `${env.buildPath ?? 'platforms'}/${getPlatformName()}/dist`;
} }
/** /**

View File

@ -1,11 +1,11 @@
import { ContextExclusionPlugin } from 'webpack';
import Config from 'webpack-chain';
import { dirname, join } from 'path';
import { writeFileSync, mkdirSync } from 'fs';
import VirtualModulesPlugin from 'webpack-virtual-modules'; import VirtualModulesPlugin from 'webpack-virtual-modules';
import { getEntryDirPath } from './platform'; import { ContextExclusionPlugin } from 'webpack';
import { mkdirSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
import Config from 'webpack-chain';
import dedent from 'ts-dedent'; import dedent from 'ts-dedent';
import { getEntryDirPath } from './platform';
import { getProjectFilePath } from './project'; import { getProjectFilePath } from './project';
/** /**

View File

@ -26,6 +26,7 @@ export interface IWebpackEnv {
appPath?: string; appPath?: string;
appResourcesPath?: string; appResourcesPath?: string;
buildPath?: string;
appComponents?: string[]; appComponents?: string[];
nativescriptLibPath?: string | boolean; nativescriptLibPath?: string | boolean;
@ -65,6 +66,7 @@ let webpackMerges: any[] = [];
let explicitUseConfig = false; let explicitUseConfig = false;
let hasInitialized = false; let hasInitialized = false;
let currentPlugin: string | undefined; let currentPlugin: string | undefined;
/** /**
* @internal * @internal
*/ */
@ -85,6 +87,7 @@ export function clearCurrentPlugin() {
} }
////// PUBLIC API ////// PUBLIC API
/** /**
* The default flavor specific configs * The default flavor specific configs
*/ */

View File

@ -1,7 +1,8 @@
import { INativeScriptPlatform } from "../helpers/platform"; import { INativeScriptPlatform } from "../helpers/platform";
import { env } from '../';
function getDistPath() { function getDistPath() {
return `platforms/android/app/src/main/assets/app`; return `${env.buildPath ?? "platforms"}/android/app/src/main/assets/app`;
} }
const AndroidPlatform: INativeScriptPlatform = { const AndroidPlatform: INativeScriptPlatform = {

View File

@ -2,6 +2,7 @@ import { basename } from "path";
import { INativeScriptPlatform } from "../helpers/platform"; import { INativeScriptPlatform } from "../helpers/platform";
import { getProjectRootPath } from "../helpers/project"; import { getProjectRootPath } from "../helpers/project";
import { env } from '../';
function sanitizeName(appName: string): string { function sanitizeName(appName: string): string {
return appName.split("").filter((c) => return appName.split("").filter((c) =>
@ -10,7 +11,7 @@ function sanitizeName(appName: string): string {
} }
function getDistPath() { function getDistPath() {
const appName = sanitizeName(basename(getProjectRootPath())); const appName = sanitizeName(basename(getProjectRootPath()));
return `platforms/ios/${appName}/app`; return `${env.buildPath ?? "platforms"}/ios/${appName}/app`;
} }
const iOSPlatform: INativeScriptPlatform = { const iOSPlatform: INativeScriptPlatform = {

View File

@ -2,6 +2,7 @@ import { basename } from "path";
import { INativeScriptPlatform } from "../helpers/platform"; import { INativeScriptPlatform } from "../helpers/platform";
import { getProjectRootPath } from "../helpers/project"; import { getProjectRootPath } from "../helpers/project";
import { env } from '../';
function sanitizeName(appName: string): string { function sanitizeName(appName: string): string {
return appName.split("").filter((c) => return appName.split("").filter((c) =>
@ -10,7 +11,7 @@ function sanitizeName(appName: string): string {
} }
function getDistPath() { function getDistPath() {
const appName = sanitizeName(basename(getProjectRootPath())); const appName = sanitizeName(basename(getProjectRootPath()));
return `platforms/visionos/${appName}/app`; return `${env.buildPath ?? "platforms"}/visionos/${appName}/app`;
} }
const visionOSPlatform: INativeScriptPlatform = { const visionOSPlatform: INativeScriptPlatform = {