fix(bundling): combine user-defined external esbuild options with ours (#14755)
This commit is contained in:
parent
2876996a39
commit
2f4f0f0ab2
@ -1,5 +1,6 @@
|
||||
import { buildEsbuildOptions } from './build-esbuild-options';
|
||||
import { ExecutorContext } from 'nx/src/config/misc-interfaces';
|
||||
import path = require('path');
|
||||
|
||||
describe('buildEsbuildOptions', () => {
|
||||
const context: ExecutorContext = {
|
||||
@ -14,8 +15,8 @@ describe('buildEsbuildOptions', () => {
|
||||
},
|
||||
nxJsonConfiguration: {},
|
||||
isVerbose: false,
|
||||
root: '/',
|
||||
cwd: '/',
|
||||
root: path.join(__dirname, 'fixtures'),
|
||||
cwd: path.join(__dirname, 'fixtures'),
|
||||
target: {
|
||||
executor: '@nrwl/esbuild:esbuild',
|
||||
options: {
|
||||
@ -276,4 +277,73 @@ describe('buildEsbuildOptions', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should respect user defined external', () => {
|
||||
expect(
|
||||
buildEsbuildOptions(
|
||||
'esm',
|
||||
{
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
main: 'apps/myapp/src/index.ts',
|
||||
outputPath: 'dist/apps/myapp',
|
||||
tsConfig: 'apps/myapp/tsconfig.app.json',
|
||||
project: 'apps/myapp/package.json',
|
||||
outputFileName: 'index.js',
|
||||
assets: [],
|
||||
singleEntry: true,
|
||||
external: ['foo'],
|
||||
esbuildOptions: {
|
||||
external: ['bar'],
|
||||
},
|
||||
},
|
||||
context
|
||||
)
|
||||
).toEqual({
|
||||
bundle: true,
|
||||
entryNames: '[dir]/[name]',
|
||||
entryPoints: ['apps/myapp/src/index.ts'],
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
outfile: 'dist/apps/myapp/index.js',
|
||||
tsconfig: 'apps/myapp/tsconfig.app.json',
|
||||
external: ['bar', 'foo'],
|
||||
outExtension: {
|
||||
'.js': '.js',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not set external if --bundle=false', () => {
|
||||
expect(
|
||||
buildEsbuildOptions(
|
||||
'esm',
|
||||
{
|
||||
bundle: false,
|
||||
platform: 'node',
|
||||
main: 'apps/myapp/src/index.ts',
|
||||
outputPath: 'dist/apps/myapp',
|
||||
tsConfig: 'apps/myapp/tsconfig.app.json',
|
||||
project: 'apps/myapp/package.json',
|
||||
outputFileName: 'index.js',
|
||||
assets: [],
|
||||
singleEntry: true,
|
||||
external: ['foo'],
|
||||
},
|
||||
context
|
||||
)
|
||||
).toEqual({
|
||||
bundle: false,
|
||||
entryNames: '[dir]/[name]',
|
||||
entryPoints: ['apps/myapp/src/index.ts'],
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
outdir: 'dist/apps/myapp',
|
||||
tsconfig: 'apps/myapp/tsconfig.app.json',
|
||||
external: undefined,
|
||||
outExtension: {
|
||||
'.js': '.js',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -24,7 +24,10 @@ export function buildEsbuildOptions(
|
||||
entryNames:
|
||||
options.outputHashing === 'all' ? '[dir]/[name].[hash]' : '[dir]/[name]',
|
||||
bundle: options.bundle,
|
||||
external: options.external,
|
||||
// Cannot use external with bundle option
|
||||
external: options.bundle
|
||||
? [...(options.esbuildOptions?.external ?? []), ...options.external]
|
||||
: undefined,
|
||||
minify: options.minify,
|
||||
platform: options.platform,
|
||||
target: options.target,
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"paths": {}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user