feat: additional base setup

This commit is contained in:
Igor Randjelovic
2020-11-14 16:16:49 +01:00
parent 2be179a8d0
commit b22e1c2361
6 changed files with 248 additions and 77 deletions

View File

@ -1,9 +1,52 @@
import Config from 'webpack-chain';
import { IWebpackEnv } from './index';
import { IWebpackEnv, WebpackPlatform } from './index';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import { getDistPath } from '../helpers/projectHelpers';
// todo: add base configuration that's shared across all flavors
export default function (env: IWebpackEnv): Config {
const config = new Config();
config.entry('');
const distPath = getDistPath(env);
// inspector_modules
config.when(shouldIncludeInspectorModules(env), (config) => {
config.entry('inspector_modules').add('tns_modules/@nativescript/core/inspector_modules').end();
});
config.entry('bundle').add('todo/main').end();
// base aliases
config.resolve.alias.set('~/package.json', 'package.json').set('~', '<TODO>appFullPath').set('@', '<TODO>appFullPath');
// resolve symlinks
config.resolve.symlinks(true);
// items to clean
config.plugin('clean').use(CleanWebpackPlugin, [
{
cleanOnceBeforeBuildPatterns: [`${distPath}/**/*`],
verbose: true,
},
]);
return config;
}
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;
}
function determinePlatformFromEnv(env: IWebpackEnv): WebpackPlatform {
if (env?.android) {
return WebpackPlatform.android;
}
if (env?.ios) {
return WebpackPlatform.ios;
}
throw new Error('You need to provide a target platform!');
}