mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -12,7 +12,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
const entryPath = getEntryPath();
|
||||
const virtualEntryPath = path.resolve(
|
||||
__dirname,
|
||||
'../stubs/virtual-entry-typescript.js'
|
||||
`../stubs/virtual-entry-typescript.${env.commonjs ? 'js' : 'mjs'}`,
|
||||
);
|
||||
|
||||
// exclude files starting with _ from require.context
|
||||
@@ -23,7 +23,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
chainedSetAddAfter(
|
||||
config.entry('bundle'),
|
||||
'@nativescript/core/globals/index',
|
||||
virtualEntryPath
|
||||
virtualEntryPath,
|
||||
);
|
||||
|
||||
config.when(env.hmr, (config) => {
|
||||
|
||||
@@ -1,5 +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);
|
||||
global.registerBundlerModules(context);
|
||||
// VIRTUAL ENTRY END
|
||||
@@ -1,5 +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);
|
||||
global.registerBundlerModules(context);
|
||||
// VIRTUAL ENTRY END
|
||||
78
packages/webpack5/src/stubs/virtual-entry-typescript.mjs
Normal file
78
packages/webpack5/src/stubs/virtual-entry-typescript.mjs
Normal file
@@ -0,0 +1,78 @@
|
||||
// VIRTUAL ENTRY START
|
||||
require('@nativescript/core/bundle-entry-points')
|
||||
|
||||
import { readdirSync } from 'fs';
|
||||
import { join, extname, relative } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { createRequire } from 'module';
|
||||
|
||||
console.log('__COMMONJS__:', __COMMONJS__);
|
||||
|
||||
// const context = require.context("~/", /* deep: */ true, /* filter: */ /\.(xml|js|(?<!\.d\.)ts|s?css)$/);
|
||||
|
||||
// const modules = import.meta.glob(
|
||||
// // adjust the pattern to your layout:
|
||||
// "/src/**/*.@(xml|js|ts|scss|css)"
|
||||
// // { eager: true } // uncomment to import immediately
|
||||
// );
|
||||
console.log('typeof import.meta.glob:', typeof import.meta.glob);
|
||||
if (typeof import.meta.glob !== 'undefined') {
|
||||
// Vite environment
|
||||
const modules = import.meta.glob(
|
||||
// adjust the pattern to your layout:
|
||||
'~/**/*.@(xml|js|ts|scss|css)',
|
||||
{ eager: true }, // uncomment to import immediately
|
||||
);
|
||||
global.registerBundlerModules(modules);
|
||||
} else {
|
||||
const require = createRequire(import.meta.url);
|
||||
const root = fileURLToPath(new URL('./src', import.meta.url));
|
||||
|
||||
/**
|
||||
* Recursively walk `dir`, collecting all files whose extension is in `exts`,
|
||||
* ignoring any `*.d.ts` files.
|
||||
*/
|
||||
function collectFilesSync(
|
||||
dir,
|
||||
exts = ['.xml', '.js', '.ts', '.css', '.scss'],
|
||||
) {
|
||||
let results = [];
|
||||
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = join(dir, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
results = results.concat(collectFilesSync(full, exts));
|
||||
} else {
|
||||
// skip declaration files
|
||||
if (entry.name.endsWith('.d.ts')) continue;
|
||||
// filter by extension
|
||||
if (exts.includes(extname(entry.name))) {
|
||||
results.push(full);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously load every matching module under `./src`,
|
||||
* keyed by its path relative to `root`.
|
||||
*/
|
||||
function loadContextSync() {
|
||||
const files = collectFilesSync(root);
|
||||
const context = {};
|
||||
|
||||
for (const fullPath of files) {
|
||||
// make the key look like fast‑glob’s relative paths
|
||||
const relPath = relative(root, fullPath).replace(/\\/g, '/');
|
||||
// require() each module
|
||||
context[relPath] = require(fullPath);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
const context = loadContextSync();
|
||||
|
||||
global.registerBundlerModules(context);
|
||||
}
|
||||
// VIRTUAL ENTRY END
|
||||
Reference in New Issue
Block a user