From fb715a92f97d5eaa1668671107b934a1b065bc21 Mon Sep 17 00:00:00 2001 From: Hanai Date: Thu, 18 Jun 2020 19:51:02 +0800 Subject: [PATCH 1/5] add support for amd options --- README.md | 2 ++ src/index.js | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 249a230d..7cf283c2 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,8 @@ Options --compress Compress output using Terser --strict Enforce undefined global context and add "use strict" --name Specify name exposed in UMD and IIFE builds + --amd.id ID for AMD module (default is anonymous) + --amd.define Function to use in place of `define` --cwd Use an alternative working directory (default .) --sourcemap Generate source map (default true) --raw Show raw byte size (default false) diff --git a/src/index.js b/src/index.js index a10ae135..51cf8966 100644 --- a/src/index.js +++ b/src/index.js @@ -457,6 +457,15 @@ function createConfig(options, entry, format, writeMeta) { outputAliases['.'] = './' + basename(options.output); } + let amd = {}; + if (options['amd.id']) { + amd.id = options['amd.id']; + } + + if (options['amd.define']) { + amd.define = options['amd.define']; + } + const moduleAliases = options.alias ? parseMappingArgumentAlias(options.alias) : []; @@ -707,6 +716,7 @@ function createConfig(options, entry, format, writeMeta) { outputOptions: { paths: outputAliases, globals, + amd, strict: options.strict === true, legacy: true, freeze: false, From b84e5956a6887afa32ffefd5180051b14460e7fa Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 19 Jun 2020 18:44:55 -0400 Subject: [PATCH 2/5] Add options to CLI args list --- src/prog.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/prog.js b/src/prog.js index 8386f9c5..ccea5431 100644 --- a/src/prog.js +++ b/src/prog.js @@ -44,6 +44,8 @@ export default handler => { .option('--compress', 'Compress output using Terser', null) .option('--strict', 'Enforce undefined global context and add "use strict"') .option('--name', 'Specify name exposed in UMD builds') + .option('--amd-name', '[amd] use named define("name", ...)') + .option('--amd-define', '[amd] function to use in place of define()') .option('--cwd', 'Use an alternative working directory', '.') .option('--sourcemap', 'Generate source map', true) .option( From da36404359d8bfc1938555ca994fd29a5b4529fe Mon Sep 17 00:00:00 2001 From: Hanai Date: Sat, 20 Jun 2020 12:21:18 +0800 Subject: [PATCH 3/5] Update README.md Co-authored-by: Jason Miller --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7cf283c2..d4cc405c 100644 --- a/README.md +++ b/README.md @@ -229,8 +229,8 @@ Options --compress Compress output using Terser --strict Enforce undefined global context and add "use strict" --name Specify name exposed in UMD and IIFE builds - --amd.id ID for AMD module (default is anonymous) - --amd.define Function to use in place of `define` + --amd-name [amd] use named define("name", ...) + --amd-define [amd] function to use in place of define() --cwd Use an alternative working directory (default .) --sourcemap Generate source map (default true) --raw Show raw byte size (default false) From cf7a2f3cd35fe22f739339721779a5a3fc485c9a Mon Sep 17 00:00:00 2001 From: Hanai Date: Sat, 20 Jun 2020 12:22:52 +0800 Subject: [PATCH 4/5] Update src/index.js Co-authored-by: Jason Miller --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 51cf8966..586d24f5 100644 --- a/src/index.js +++ b/src/index.js @@ -458,12 +458,12 @@ function createConfig(options, entry, format, writeMeta) { } let amd = {}; - if (options['amd.id']) { - amd.id = options['amd.id']; + if (options.amdName) { + amd.id = options.amdName; } - if (options['amd.define']) { - amd.define = options['amd.define']; + if (options.amdDefine) { + amd.define = options.amdDefine; } const moduleAliases = options.alias From 69628af62ec97f6b86e147d1e3a1ad87cb729b77 Mon Sep 17 00:00:00 2001 From: Hanai Date: Sat, 20 Jun 2020 13:44:45 +0800 Subject: [PATCH 5/5] fix read amd options --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 586d24f5..24dff453 100644 --- a/src/index.js +++ b/src/index.js @@ -458,12 +458,12 @@ function createConfig(options, entry, format, writeMeta) { } let amd = {}; - if (options.amdName) { - amd.id = options.amdName; + if (options['amd-name']) { + amd.id = options['amd-name']; } - if (options.amdDefine) { - amd.define = options.amdDefine; + if (options['amd-define']) { + amd.define = options['amd-define']; } const moduleAliases = options.alias