mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
chore: workiing on base
This commit is contained in:
@ -1,7 +1,10 @@
|
|||||||
import { Configuration } from 'webpack';
|
import { Configuration } from 'webpack';
|
||||||
|
import Config from 'webpack-chain';
|
||||||
|
|
||||||
// todo: add base configuration that's shared across all flavors
|
// todo: add base configuration that's shared across all flavors
|
||||||
export default function (env): Configuration {
|
export default function (env): Configuration {
|
||||||
|
const config = new Config()
|
||||||
|
config.entry('')
|
||||||
return {
|
return {
|
||||||
entry: {
|
entry: {
|
||||||
'bundle.js': 'bundle.js',
|
'bundle.js': 'bundle.js',
|
||||||
|
27
packages/webpack5/src/helpers/projectHelpers.ts
Normal file
27
packages/webpack5/src/helpers/projectHelpers.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
import { resolve } from "path";
|
||||||
|
|
||||||
|
export function getPackageJson(projectDir: string) {
|
||||||
|
const packageJsonPath = getPackageJsonPath(projectDir);
|
||||||
|
const result = readJsonFile(packageJsonPath);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function readJsonFile(filePath:string) {
|
||||||
|
return require(filePath) as {
|
||||||
|
main:string
|
||||||
|
// to be extended?
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPackageJsonPath (projectDir: string) {
|
||||||
|
const packagePath = resolve(projectDir, "package.json");
|
||||||
|
if (existsSync(packagePath)) {
|
||||||
|
return packagePath;
|
||||||
|
} else {
|
||||||
|
return getPackageJsonPath(resolve(projectDir, '..'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +1,55 @@
|
|||||||
export * from './configuration';
|
export * from './configuration';
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
import { getPackageJson } from './helpers/projectHelpers';
|
||||||
|
import { resolve } from "path";
|
||||||
|
|
||||||
|
|
||||||
|
export type Platform = 'android' | 'ios';
|
||||||
|
/**
|
||||||
|
* Function to ensure the app directory exists
|
||||||
|
*
|
||||||
|
* @param appDirectory
|
||||||
|
*/
|
||||||
|
function verifyEntryModuleDirectory(appDirectory: string) {
|
||||||
|
if (!appDirectory) {
|
||||||
|
throw new Error("Path to app directory is not specified. Unable to find entry module.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!existsSync(appDirectory)) {
|
||||||
|
throw new Error(`The specified path to app directory ${appDirectory} does not exist. Unable to find entry module.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPackageJsonEntry(appDirectory) {
|
||||||
|
const packageJsonSource = getPackageJson(appDirectory);
|
||||||
|
const entry = packageJsonSource.main;
|
||||||
|
|
||||||
|
if (!entry) {
|
||||||
|
throw new Error(`${appDirectory}/package.json must contain a 'main' attribute!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry.replace(/\.js$/i, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getEntryModule (appDirectory: string, platform: 'android' | 'ios') {
|
||||||
|
verifyEntryModuleDirectory(appDirectory);
|
||||||
|
|
||||||
|
const entry = getPackageJsonEntry(appDirectory);
|
||||||
|
|
||||||
|
const tsEntryPath = resolve(appDirectory, `${entry}.ts`);
|
||||||
|
const jsEntryPath = resolve(appDirectory, `${entry}.js`);
|
||||||
|
let entryExists = existsSync(tsEntryPath) || existsSync(jsEntryPath);
|
||||||
|
if (!entryExists && platform) {
|
||||||
|
const platformTsEntryPath = resolve(appDirectory, `${entry}.${platform}.ts`);
|
||||||
|
const platformJsEntryPath = resolve(appDirectory, `${entry}.${platform}.js`);
|
||||||
|
entryExists = existsSync(platformTsEntryPath) || existsSync(platformJsEntryPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entryExists) {
|
||||||
|
throw new Error(`The entry module ${entry} specified in ` +
|
||||||
|
`${appDirectory}/package.json doesn't exist!`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
};
|
@ -7,21 +7,16 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"lib": [
|
"lib": ["es2017"],
|
||||||
"es2017"
|
|
||||||
],
|
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"skipDefaultLibCheck": true,
|
"skipDefaultLibCheck": true,
|
||||||
"diagnostics": true,
|
"diagnostics": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@nativescript/webpack": [
|
"@nativescript/webpack": ["src"]
|
||||||
"src"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true
|
||||||
},
|
},
|
||||||
"exclude": [
|
"include": ["src"],
|
||||||
"node_modules"
|
"exclude": ["node_modules"]
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user