mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
feat: ips helper, ts config, cleanups
This commit is contained in:
@ -2,9 +2,9 @@ import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
import { getAllDependencies, getDependencyPath } from './dependencies';
|
||||
import { clearCurrentPlugin, setCurrentPlugin } from '../index';
|
||||
import { info, warn } from './log';
|
||||
import * as lib from '../index';
|
||||
import { clearCurrentPlugin, setCurrentPlugin } from '../index';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
19
packages/webpack5/src/helpers/host.ts
Normal file
19
packages/webpack5/src/helpers/host.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import os from 'os';
|
||||
|
||||
export function getIPS() {
|
||||
// todo: perhaps mock networkInterfaces instead?
|
||||
if (__TEST__) {
|
||||
// in tests we don't need the real ips
|
||||
return ['127.0.0.1', '192.168.0.10'];
|
||||
}
|
||||
|
||||
const interfaces = os.networkInterfaces();
|
||||
return Object.keys(interfaces)
|
||||
.map((name) => {
|
||||
return interfaces[name].filter(
|
||||
(binding: any) => binding.family === 'IPv4'
|
||||
)[0];
|
||||
})
|
||||
.filter(Boolean)
|
||||
.map((binding) => binding.address);
|
||||
}
|
46
packages/webpack5/src/helpers/virtualModules.ts
Normal file
46
packages/webpack5/src/helpers/virtualModules.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { ContextExclusionPlugin } from 'webpack';
|
||||
import Config from 'webpack-chain';
|
||||
import { join } from 'path';
|
||||
|
||||
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
||||
import { getEntryDirPath } from './platform';
|
||||
import dedent from 'ts-dedent';
|
||||
|
||||
export function addVirtualEntry(
|
||||
config: Config,
|
||||
name: string,
|
||||
contents: string
|
||||
): string {
|
||||
return addVirtualModule(
|
||||
config,
|
||||
`__@nativescript_webpack_virtual_entry_${name}__`,
|
||||
contents
|
||||
);
|
||||
}
|
||||
|
||||
export function addVirtualModule(
|
||||
config: Config,
|
||||
name: string,
|
||||
contents: string
|
||||
): string {
|
||||
const virtualEntryPath = join(getEntryDirPath(), `${name}`);
|
||||
|
||||
config
|
||||
.plugin('ContextExclusionPluginPlugin')
|
||||
.use(ContextExclusionPlugin, [new RegExp(`${name}\.js$`)]);
|
||||
|
||||
const options = {
|
||||
[virtualEntryPath]: dedent(contents),
|
||||
};
|
||||
|
||||
if (config.plugins.has('VirtualModulesPlugin')) {
|
||||
config.plugin('VirtualModulesPlugin').tap((args) => {
|
||||
Object.assign(args[0], options);
|
||||
return args;
|
||||
});
|
||||
} else {
|
||||
config.plugin('VirtualModulesPlugin').use(VirtualModulesPlugin, [options]);
|
||||
}
|
||||
|
||||
return virtualEntryPath;
|
||||
}
|
Reference in New Issue
Block a user