mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
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';
|
|
|
|
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
|
|
`
|
|
);
|
|
|
|
// exclude files starting with _ from require.context
|
|
config
|
|
.plugin(`ContextExclusionPlugin|exclude_files`)
|
|
.use(ContextExclusionPlugin, [/\b_.+\./]);
|
|
|
|
chainedSetAddAfter(
|
|
config.entry('bundle'),
|
|
'@nativescript/core/globals/index',
|
|
virtualEntryPath
|
|
);
|
|
|
|
config.when(env.hmr, (config) => {
|
|
// set up core HMR
|
|
config.module
|
|
.rule('hmr-core')
|
|
.before('js')
|
|
.test(/\.js$/)
|
|
.exclude.add(/node_modules/)
|
|
.add(entryPath)
|
|
.end()
|
|
.use('nativescript-hot-loader')
|
|
.loader('nativescript-hot-loader')
|
|
.options({
|
|
appPath: getEntryDirPath(),
|
|
});
|
|
});
|
|
|
|
return config;
|
|
}
|