feat: add entryDir helper + update aliases

This commit is contained in:
Igor Randjelovic
2020-11-29 17:44:36 +01:00
parent 6e0407e5e8
commit ca78bc5ae8
10 changed files with 529 additions and 36 deletions

View File

@@ -13,6 +13,7 @@ import { WatchStatePlugin } from '../plugins/WatchStatePlugin';
import { IWebpackEnv } from '../index';
import {
getAbsoluteDistPath,
getEntryDirPath,
getEntryPath,
getPlatform,
} from '../helpers/project';
@@ -106,9 +107,7 @@ export default function (config: Config, env: IWebpackEnv): Config {
.add('.json');
// base aliases
config.resolve.alias
.set('~', '<TODO>appFullPath')
.set('@', '<TODO>appFullPath');
config.resolve.alias.set('~', getEntryDirPath()).set('@', getEntryDirPath());
// resolve symlinks
config.resolve.symlinks(true);

View File

@@ -1,16 +1,17 @@
import VirtualModulesPlugin from 'webpack-virtual-modules';
import Config from 'webpack-chain';
import { getEntryPath } from '../helpers/project';
import { IWebpackEnv } from '../index';
import base from './base';
import dedent from 'ts-dedent';
import { join } from 'path';
// todo: add base configuration for core with javascript
export default function (config: Config, env: IWebpackEnv): Config {
import { env as _env, IWebpackEnv } from '../index';
import { getEntryDirPath } from '../helpers/project';
import base from './base';
export default function (config: Config, env: IWebpackEnv = _env): Config {
base(config, env);
const virtualEntryPath = getEntryPath() + '.virtual.js';
const virtualEntryPath = join(getEntryDirPath(), '__virtual_entry__.js');
const filterRE = '/.(xml|js|s?css)$/';
config.entry('bundle').add(virtualEntryPath);
@@ -18,11 +19,10 @@ export default function (config: Config, env: IWebpackEnv): Config {
config.plugin('VirtualModulesPlugin').use(VirtualModulesPlugin, [
{
[virtualEntryPath]: dedent`
require('@nativescript/core/bundle-entry-points')
const context = require.context("./", /* deep: */ true);
global.registerWebpackModules(context);
`,
require('@nativescript/core/bundle-entry-points')
const context = require.context("~/", /* deep: */ true, /* filter: */ ${filterRE});
global.registerWebpackModules(context);
`,
},
]);

View File

@@ -1,5 +1,5 @@
import { env, Platform } from '../index';
import { resolve, basename } from 'path';
import { resolve, basename, dirname } from 'path';
import { error } from './log';
export function getProjectRootPath(): string {
@@ -19,6 +19,10 @@ export function getEntryPath() {
return resolve(getProjectRootPath(), packageJson.main);
}
export function getEntryDirPath() {
return dirname(getEntryPath());
}
export function getDistPath() {
if (env.ios) {
const appName = basename(getProjectRootPath());