mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: implement basic public api
This commit is contained in:
@@ -2,9 +2,8 @@ import base from './base';
|
||||
import { IWebpackEnv } from '@nativescript/webpack';
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
// todo: add base configuration for angular
|
||||
export default function (env: IWebpackEnv): Config {
|
||||
const config = base(env);
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
base(config, env);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import Config from 'webpack-chain';
|
||||
import { IWebpackEnv, WebpackPlatform } from './index';
|
||||
import { IWebpackEnv, Platform } from '../index';
|
||||
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
||||
import { getDistPath } from '../helpers/projectHelpers';
|
||||
import { DefinePlugin } from 'webpack';
|
||||
import { WatchStateLoggerPlugin } from '../plugins/WatchStateLoggerPlugin';
|
||||
|
||||
// todo: add base configuration that's shared across all flavors
|
||||
export default function (env: IWebpackEnv): Config {
|
||||
const config = new Config();
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
const distPath = getDistPath(env);
|
||||
const platform = determinePlatformFromEnv(env);
|
||||
const mode = env.production ? 'production' : 'development';
|
||||
@@ -21,7 +19,7 @@ export default function (env: IWebpackEnv): Config {
|
||||
// look for loaders in
|
||||
// - @nativescript/webpack/loaders
|
||||
// - node_modules
|
||||
config.resolveLoader.modules.add('@nativescript/webpack/loaders').add('node_modules');
|
||||
config.resolveLoader.modules.add('@nativescript/webpack/dist/loaders').add('node_modules');
|
||||
|
||||
// inspector_modules
|
||||
config.when(shouldIncludeInspectorModules(env), (config) => {
|
||||
@@ -95,8 +93,8 @@ export default function (env: IWebpackEnv): Config {
|
||||
config.plugin('DefinePlugin').use(DefinePlugin, [
|
||||
{
|
||||
'global.NS_WEBPACK': true,
|
||||
'global.isAndroid': platform === WebpackPlatform.android,
|
||||
'global.isIOS': platform === WebpackPlatform.ios,
|
||||
'global.isAndroid': platform === 'android',
|
||||
'global.isIOS': platform === 'ios',
|
||||
process: 'global.process',
|
||||
},
|
||||
]);
|
||||
@@ -120,16 +118,16 @@ function shouldIncludeInspectorModules(env: IWebpackEnv): boolean {
|
||||
const platform = determinePlatformFromEnv(env);
|
||||
// todo: check if core modules are external
|
||||
// todo: check if we are testing
|
||||
return platform === WebpackPlatform.ios;
|
||||
return platform === 'ios';
|
||||
}
|
||||
|
||||
function determinePlatformFromEnv(env: IWebpackEnv): WebpackPlatform {
|
||||
function determinePlatformFromEnv(env: IWebpackEnv): Platform {
|
||||
if (env?.android) {
|
||||
return WebpackPlatform.android;
|
||||
return 'android';
|
||||
}
|
||||
|
||||
if (env?.ios) {
|
||||
return WebpackPlatform.ios;
|
||||
return 'ios';
|
||||
}
|
||||
|
||||
throw new Error('You need to provide a target platform!');
|
||||
|
||||
@@ -7,36 +7,12 @@ import svelte from './svelte';
|
||||
import typescript from './typescript';
|
||||
import vue from './vue';
|
||||
|
||||
// export chain configs
|
||||
// todo: rename if needed
|
||||
export { base as __base, angular as __angular, javascript as __javascript, react as __react, svelte as __svelte, typescript as __typescript, vue as __vue };
|
||||
|
||||
// export final configs
|
||||
export const baseConfig = (env: IWebpackEnv) => base(env).toConfig();
|
||||
|
||||
export const angularConfig = (env: IWebpackEnv) => angular(env).toConfig();
|
||||
export const javascriptConfig = (env: IWebpackEnv) => javascript(env).toConfig();
|
||||
export const reactConfig = (env: IWebpackEnv) => react(env).toConfig();
|
||||
export const svelteConfig = (env: IWebpackEnv) => svelte(env).toConfig();
|
||||
export const typescriptConfig = (env: IWebpackEnv) => typescript(env).toConfig();
|
||||
export const vueConfig = (env: IWebpackEnv) => vue(env).toConfig();
|
||||
|
||||
export interface IWebpackEnv {
|
||||
[name: string]: any;
|
||||
|
||||
appPath?: string;
|
||||
appResourcesPath?: string;
|
||||
|
||||
android?: boolean;
|
||||
ios?: boolean;
|
||||
|
||||
production?: boolean;
|
||||
report?: boolean;
|
||||
hmr?: boolean;
|
||||
// todo: add others
|
||||
}
|
||||
|
||||
export enum WebpackPlatform {
|
||||
'ios',
|
||||
'android',
|
||||
}
|
||||
export const configs = {
|
||||
base,
|
||||
angular,
|
||||
javascript,
|
||||
react,
|
||||
svelte,
|
||||
typescript,
|
||||
vue,
|
||||
};
|
||||
|
||||
@@ -3,8 +3,8 @@ import { IWebpackEnv } from '@nativescript/webpack';
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
// todo: add base configuration for core with javascript
|
||||
export default function (env: IWebpackEnv): Config {
|
||||
const config = base(env);
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
base(config, env);
|
||||
|
||||
// set up xml
|
||||
config.module
|
||||
|
||||
@@ -3,9 +3,8 @@ import { IWebpackEnv } from '@nativescript/webpack';
|
||||
import Config from 'webpack-chain';
|
||||
import { merge } from 'webpack-merge';
|
||||
|
||||
// todo: add base configuration for react
|
||||
export default function (env: IWebpackEnv): Config {
|
||||
const config = base(env);
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
base(config, env);
|
||||
|
||||
// todo: use env
|
||||
let isAnySourceMapEnabled = true;
|
||||
|
||||
@@ -3,8 +3,8 @@ import { IWebpackEnv } from '@nativescript/webpack';
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
// todo: add base configuration for svelte
|
||||
export default function (env: IWebpackEnv): Config {
|
||||
const config = base(env);
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
base(config, env);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import { IWebpackEnv } from '@nativescript/webpack';
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
// todo: add base configuration for core
|
||||
export default function (env: IWebpackEnv): Config {
|
||||
const config = base(env);
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
base(config, env);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import base from './base';
|
||||
import Config from 'webpack-chain';
|
||||
import { VueLoaderPlugin } from 'vue-loader';
|
||||
import { IWebpackEnv } from './index';
|
||||
import { IWebpackEnv } from '../index';
|
||||
import { merge } from 'webpack-merge';
|
||||
// todo: add base configuration for vue
|
||||
export default function (env: IWebpackEnv): Config {
|
||||
const config = base(env);
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
base(config, env);
|
||||
|
||||
// resolve .vue files
|
||||
config.resolve.extensions.prepend('.vue');
|
||||
|
||||
Reference in New Issue
Block a user