mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: ips helper, ts config, cleanups
This commit is contained in:
@@ -16,12 +16,14 @@ import { getProjectRootPath } from '../helpers/project';
|
||||
import { hasDependency } from '../helpers/dependencies';
|
||||
import { applyDotEnvPlugin } from '../helpers/dotEnv';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import { getIPS } from '../helpers/host';
|
||||
import {
|
||||
getPlatformName,
|
||||
getAbsoluteDistPath,
|
||||
getEntryDirPath,
|
||||
getEntryPath,
|
||||
} from '../helpers/platform';
|
||||
import os from 'os';
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
const entryPath = getEntryPath();
|
||||
@@ -267,6 +269,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
{
|
||||
__DEV__: mode === 'development',
|
||||
__NS_WEBPACK__: true,
|
||||
__NS_DEV_HOST_IPS__:
|
||||
mode === 'development' ? JSON.stringify(getIPS()) : `[]`,
|
||||
__CSS_PARSER__: JSON.stringify('css-tree'), // todo: replace from config value
|
||||
__ANDROID__: platform === 'android',
|
||||
__IOS__: platform === 'ios',
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
||||
import { ContextExclusionPlugin } from 'webpack';
|
||||
import Config from 'webpack-chain';
|
||||
import dedent from 'ts-dedent';
|
||||
import { join } from 'path';
|
||||
|
||||
import { getEntryDirPath } from '../helpers/platform';
|
||||
import { addVirtualEntry } from '../helpers/virtualModules';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import base from './base';
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
base(config, env);
|
||||
|
||||
const virtualEntryPath = join(getEntryDirPath(), '__virtual_entry__.js');
|
||||
const filterRE = '/.(xml|js|s?css)$/';
|
||||
const virtualEntryPath = addVirtualEntry(
|
||||
config,
|
||||
'javascript',
|
||||
`
|
||||
// VIRTUAL ENTRY START
|
||||
require('@nativescript/core/bundle-entry-points')
|
||||
const context = require.context("~/", /* deep: */ true, /* filter: */ ${filterRE});
|
||||
global.registerWebpackModules(context);
|
||||
// VIRTUAL ENTRY END
|
||||
`
|
||||
);
|
||||
|
||||
config.entry('bundle').add(virtualEntryPath);
|
||||
|
||||
config
|
||||
.plugin('ContextExclusionPluginPlugin')
|
||||
.use(ContextExclusionPlugin, [/__virtual_entry__\.js$/]);
|
||||
|
||||
// Add a virtual entry module that will register all modules into
|
||||
// the nativescript module loader/handler
|
||||
config.plugin('VirtualModulesPlugin').use(VirtualModulesPlugin, [
|
||||
{
|
||||
[virtualEntryPath]: dedent`
|
||||
require('@nativescript/core/bundle-entry-points')
|
||||
const context = require.context("~/", /* deep: */ true, /* filter: */ ${filterRE});
|
||||
global.registerWebpackModules(context);
|
||||
`,
|
||||
},
|
||||
]);
|
||||
|
||||
config.resolve.extensions.add('.xml');
|
||||
// config.resolve.extensions.add('.xml');
|
||||
|
||||
// set up xml
|
||||
config.module
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { merge } from 'webpack-merge';
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import { getPlatformName } from '../helpers/platform';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import base from './base';
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
import { IWebpackEnv } from '../index';
|
||||
import { addVirtualEntry } from '../helpers/virtualModules';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import base from './base';
|
||||
|
||||
// todo: add base configuration for core
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
base(config, env);
|
||||
|
||||
const filterRE = '/.(xml|js|ts|s?css)$/';
|
||||
const virtualEntryPath = addVirtualEntry(
|
||||
config,
|
||||
'typescript',
|
||||
`
|
||||
// VIRTUAL ENTRY START
|
||||
require('@nativescript/core/bundle-entry-points')
|
||||
const context = require.context("~/", /* deep: */ true, /* filter: */ ${filterRE});
|
||||
global.registerWebpackModules(context);
|
||||
// VIRTUAL ENTRY END
|
||||
`
|
||||
);
|
||||
|
||||
config.entry('bundle').add(virtualEntryPath);
|
||||
|
||||
// config.resolve.extensions.add('.xml');
|
||||
|
||||
// set up xml
|
||||
config.module
|
||||
.rule('xml')
|
||||
.test(/\.xml$/)
|
||||
.use('xml-namespace-loader')
|
||||
.loader('xml-namespace-loader');
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ import { VueLoaderPlugin } from 'vue-loader';
|
||||
import { merge } from 'webpack-merge';
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import { getPlatformName } from '../helpers/platform';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import base from './base';
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
|
||||
Reference in New Issue
Block a user