mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
chore: base webpack with ability to switch between esm to commonjs as needed
This commit is contained in:
5676
packages/webpack5/package-lock.json
generated
5676
packages/webpack5/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ import {
|
|||||||
ContextExclusionPlugin,
|
ContextExclusionPlugin,
|
||||||
DefinePlugin,
|
DefinePlugin,
|
||||||
HotModuleReplacementPlugin,
|
HotModuleReplacementPlugin,
|
||||||
|
BannerPlugin,
|
||||||
} from 'webpack';
|
} from 'webpack';
|
||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
import { satisfies } from 'semver';
|
import { satisfies } from 'semver';
|
||||||
@ -98,6 +99,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
// appears to be working - but we still have to deal with HMR
|
// appears to be working - but we still have to deal with HMR
|
||||||
config.target('node');
|
config.target('node');
|
||||||
|
|
||||||
|
// config.entry('globals').add('@nativescript/core/globals/index').end();
|
||||||
|
|
||||||
config
|
config
|
||||||
.entry('bundle')
|
.entry('bundle')
|
||||||
// ensure we load nativescript globals first
|
// ensure we load nativescript globals first
|
||||||
@ -124,19 +127,20 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
.add('@nativescript/core/inspector_modules');
|
.add('@nativescript/core/inspector_modules');
|
||||||
});
|
});
|
||||||
|
|
||||||
config.merge({
|
// config.merge({
|
||||||
experiments: {
|
// experiments: {
|
||||||
// enable ES module syntax (import/exports)
|
// // enable ES module syntax (import/exports)
|
||||||
outputModule: true,
|
// outputModule: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
|
|
||||||
config.output
|
config.output
|
||||||
.path(outputPath)
|
.path(outputPath)
|
||||||
.pathinfo(false)
|
.pathinfo(false)
|
||||||
.publicPath('')
|
.publicPath('')
|
||||||
.set('module', true)
|
// .set('module', true)
|
||||||
.libraryTarget('module')
|
// .libraryTarget('module')
|
||||||
|
.libraryTarget('commonjs')
|
||||||
.globalObject('global')
|
.globalObject('global')
|
||||||
.set('clean', true);
|
.set('clean', true);
|
||||||
|
|
||||||
@ -184,11 +188,24 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
config.optimization.runtimeChunk('single');
|
config.optimization.runtimeChunk('single');
|
||||||
|
|
||||||
config.optimization.splitChunks({
|
config.optimization.splitChunks({
|
||||||
|
// chunks: 'all',
|
||||||
cacheGroups: {
|
cacheGroups: {
|
||||||
|
// globals: {
|
||||||
|
// test: (module) =>
|
||||||
|
// module.resource &&
|
||||||
|
// /[\\/]@nativescript[\\/]core[\\/]globals[\\/]index\.(mjs|js|ts)$/.test(
|
||||||
|
// module.resource,
|
||||||
|
// ),
|
||||||
|
// name: 'globals',
|
||||||
|
// enforce: true, // ignore size/min-chunk thresholds
|
||||||
|
// chunks: 'all',
|
||||||
|
// priority: 30,
|
||||||
|
// },
|
||||||
defaultVendor: {
|
defaultVendor: {
|
||||||
test: /[\\/]node_modules[\\/]/,
|
test: /[\\/]node_modules[\\/]/,
|
||||||
priority: -10,
|
priority: -10,
|
||||||
name: 'vendor',
|
name: 'vendor',
|
||||||
|
// enforce: true,
|
||||||
chunks: 'all',
|
chunks: 'all',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -427,6 +444,17 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
// }
|
// }
|
||||||
// ])
|
// ])
|
||||||
|
|
||||||
|
// config.plugin('globals-shim').use(BannerPlugin, [
|
||||||
|
// {
|
||||||
|
// // commonjs style
|
||||||
|
// banner: `require("./globals");`,
|
||||||
|
// // ESM style
|
||||||
|
// // banner: `import "./globals";`,
|
||||||
|
// raw: true,
|
||||||
|
// entryOnly: true,
|
||||||
|
// },
|
||||||
|
// ]);
|
||||||
|
|
||||||
config.plugin('PlatformSuffixPlugin').use(PlatformSuffixPlugin, [
|
config.plugin('PlatformSuffixPlugin').use(PlatformSuffixPlugin, [
|
||||||
{
|
{
|
||||||
extensions: platform === 'visionos' ? [platform, 'ios'] : [platform],
|
extensions: platform === 'visionos' ? [platform, 'ios'] : [platform],
|
||||||
|
Reference in New Issue
Block a user