mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refactor(webpack): use real modules and deprecate virtual modules
This commit is contained in:
committed by
Nathan Walker
parent
2fbc1898db
commit
0556cf9b20
@@ -1,26 +1,18 @@
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
import { getEntryPath, getEntryDirPath } from '../helpers/platform';
|
||||
import { addVirtualEntry } from '../helpers/virtualModules';
|
||||
import { chainedSetAddAfter } from '../helpers/chain';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import { ContextExclusionPlugin } from 'webpack';
|
||||
import base from './base';
|
||||
import path from 'path';
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
base(config, env);
|
||||
const entryPath = getEntryPath();
|
||||
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
|
||||
`
|
||||
const virtualEntryPath = path.resolve(
|
||||
__dirname,
|
||||
'../stubs/virtual-entry-javascript'
|
||||
);
|
||||
|
||||
// exclude files starting with _ from require.context
|
||||
|
||||
@@ -1,26 +1,18 @@
|
||||
import Config from 'webpack-chain';
|
||||
|
||||
import { getEntryDirPath, getEntryPath } from '../helpers/platform';
|
||||
import { addVirtualEntry } from '../helpers/virtualModules';
|
||||
import { chainedSetAddAfter } from '../helpers/chain';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import { ContextExclusionPlugin } from 'webpack';
|
||||
import base from './base';
|
||||
import path from 'path';
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
base(config, env);
|
||||
const entryPath = getEntryPath();
|
||||
const filterRE = '/\\.(xml|js|(?<!\\.d\\.)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
|
||||
`
|
||||
const virtualEntryPath = path.resolve(
|
||||
__dirname,
|
||||
'../stubs/virtual-entry-typescript.js'
|
||||
);
|
||||
|
||||
// exclude files starting with _ from require.context
|
||||
|
||||
@@ -8,6 +8,9 @@ import { getEntryDirPath } from './platform';
|
||||
import dedent from 'ts-dedent';
|
||||
import { getProjectFilePath } from './project';
|
||||
|
||||
/**
|
||||
* @deprecated Virtual entries are not recommended by the webpack team, use real files instead. For example, resolve a path in node_modules if necessary.
|
||||
*/
|
||||
export function addVirtualEntry(
|
||||
config: Config,
|
||||
name: string,
|
||||
@@ -20,6 +23,9 @@ export function addVirtualEntry(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Virtual modules are not recommended by the webpack team, use real files instead. For example, resolve a path in node_modules if necessary.
|
||||
*/
|
||||
export function addVirtualModule(
|
||||
config: Config,
|
||||
name: string,
|
||||
|
||||
5
packages/webpack5/src/stubs/virtual-entry-javascript.js
Normal file
5
packages/webpack5/src/stubs/virtual-entry-javascript.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// VIRTUAL ENTRY START
|
||||
require('@nativescript/core/bundle-entry-points')
|
||||
const context = require.context("~/", /* deep: */ true, /* filter: */ /.(xml|js|s?css)$/);
|
||||
global.registerWebpackModules(context);
|
||||
// VIRTUAL ENTRY END
|
||||
5
packages/webpack5/src/stubs/virtual-entry-typescript.js
Normal file
5
packages/webpack5/src/stubs/virtual-entry-typescript.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// VIRTUAL ENTRY START
|
||||
require('@nativescript/core/bundle-entry-points')
|
||||
const context = require.context("~/", /* deep: */ true, /* filter: */ /\.(xml|js|(?<!\.d\.)ts|s?css)$/);
|
||||
global.registerWebpackModules(context);
|
||||
// VIRTUAL ENTRY END
|
||||
Reference in New Issue
Block a user