diff --git a/cli/help.md b/cli/help.md index b391ab154da..583de840666 100644 --- a/cli/help.md +++ b/cli/help.md @@ -26,7 +26,6 @@ Basic options: --chunkFileNames Name pattern for emitted secondary chunks --compact Minify wrapper code --context Specify top-level `this` value ---dynamicImportFunction Rename the dynamic `import()` function --entryFileNames Name pattern for emitted entry chunks --environment Settings passed to config file (see example) --no-esModule Do not add __esModule property diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index 831e982bb5f..101ac377a72 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -85,7 +85,6 @@ export default { // can be an array (for multiple inputs) // danger zone amd, - dynamicImportFunction, esModule, exports, externalLiveBindings, @@ -228,7 +227,6 @@ Many options have command line equivalents. In those cases, any arguments passed --chunkFileNames Name pattern for emitted secondary chunks --compact Minify wrapper code --context Specify top-level `this` value ---dynamicImportFunction Rename the dynamic `import()` function --entryFileNames Name pattern for emitted entry chunks --environment Settings passed to config file (see example) --no-esModule Do not add __esModule property diff --git a/docs/02-javascript-api.md b/docs/02-javascript-api.md index 4a4d8390f81..8f7fdaec8f7 100755 --- a/docs/02-javascript-api.md +++ b/docs/02-javascript-api.md @@ -136,7 +136,6 @@ const outputOptions = { // danger zone amd, - dynamicImportFunction, esModule, exports, freeze, diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index ffd8edea80e..9aa19d489a1 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -848,13 +848,6 @@ Default: `true` Whether to include the 'use strict' pragma at the top of generated non-ES bundles. Strictly speaking, ES modules are *always* in strict mode, so you shouldn't disable this without good reason. -#### output.dynamicImportFunction -Type: `string`
-CLI: `--dynamicImportFunction `
-Default: `import` - -This will rename the dynamic import function to the chosen name when outputting ES bundles. This is useful for generating code that uses a dynamic import polyfill such as [this one](https://github.com/uupaa/dynamic-import-polyfill). - #### preserveSymlinks Type: `boolean`
CLI: `--preserveSymlinks`
@@ -1133,6 +1126,7 @@ export default { ☢️ These options have been deprecated and may be removed in a future Rollup version. #### treeshake.pureExternalModules +_Use [`treeshake.moduleSideEffects: 'no-external'`](guide/en/#treeshake) instead._
Type: `boolean | string[] | (id: string) => boolean | null`
CLI: `--treeshake.pureExternalModules`/`--no-treeshake.pureExternalModules`
Default: `false` @@ -1159,3 +1153,11 @@ console.log(42); ``` You can also supply a list of external ids to be considered pure or a function that is called whenever an external import could be removed. + +#### output.dynamicImportFunction +_Use the [`renderDynamicImport`](guide/en/#renderdynamicimport) plugin hook instead._
+Type: `string`
+CLI: `--dynamicImportFunction `
+Default: `import` + +This will rename the dynamic import function to the chosen name when outputting ES bundles. This is useful for generating code that uses a dynamic import polyfill such as [this one](https://github.com/uupaa/dynamic-import-polyfill). diff --git a/src/rollup/rollup.ts b/src/rollup/rollup.ts index 917a8f5d5dd..cb61b03d9b6 100644 --- a/src/rollup/rollup.ts +++ b/src/rollup/rollup.ts @@ -197,6 +197,12 @@ export async function rollupInternal( ): Promise { timeStart('GENERATE', 1); + if (outputOptions.dynamicImportFunction) { + graph.warnDeprecation( + `The "output.dynamicImportFunction" option is deprecated. Use the "renderDynamicImport" plugin hook instead.`, + false + ); + } const assetFileNames = outputOptions.assetFileNames || 'assets/[name]-[hash][extname]'; const inputBase = commondir(getAbsoluteEntryModulePaths(chunks)); const outputBundleWithPlaceholders: OutputBundleWithPlaceholders = Object.create(null); diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 5d74878b49e..80250fedd20 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -484,6 +484,7 @@ export interface OutputOptions { compact?: boolean; // only required for bundle.write dir?: string; + /** @deprecated Use the "renderDynamicImport" plugin hook instead. */ dynamicImportFunction?: string; entryFileNames?: string; esModule?: boolean; @@ -493,8 +494,6 @@ export interface OutputOptions { // only required for bundle.write file?: string; footer?: string | (() => string | Promise); - // this is optional at the base-level of RollupWatchOptions, - // which extends from this interface through config merge format?: ModuleFormat; freeze?: boolean; globals?: GlobalsOption; diff --git a/test/chunking-form/samples/deprecated/dynamic-import-comments/_config.js b/test/chunking-form/samples/deprecated/dynamic-import-comments/_config.js new file mode 100644 index 00000000000..2bc7c8df417 --- /dev/null +++ b/test/chunking-form/samples/deprecated/dynamic-import-comments/_config.js @@ -0,0 +1,16 @@ +module.exports = { + description: 'should not remove inline comments inside dynamic import', + options: { + strictDeprecations: false, + input: 'main.js', + onwarn() {}, + plugins: { + resolveDynamicImport() { + return false; + } + }, + output: { + dynamicImportFunction: 'foobar' + } + } +}; diff --git a/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/amd/main.js b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/amd/main.js new file mode 100644 index 00000000000..24110f00861 --- /dev/null +++ b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/amd/main.js @@ -0,0 +1,26 @@ +define(['require'], function (require) { 'use strict'; + + function _interopNamespace(e) { + if (e && e.__esModule) { return e; } else { + var n = {}; + if (e) { + Object.keys(e).forEach(function (k) { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { + return e[k]; + } + }); + }); + } + n['default'] = e; + return n; + } + } + + new Promise(function (resolve, reject) { require([ + /* webpackChunkName: "chunk-name" */ + './foo'/*suffix*/], function (m) { resolve(_interopNamespace(m)); }, reject) }); + +}); diff --git a/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/cjs/main.js b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/cjs/main.js new file mode 100644 index 00000000000..7e7e20c640d --- /dev/null +++ b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/cjs/main.js @@ -0,0 +1,24 @@ +'use strict'; + +function _interopNamespace(e) { + if (e && e.__esModule) { return e; } else { + var n = {}; + if (e) { + Object.keys(e).forEach(function (k) { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { + return e[k]; + } + }); + }); + } + n['default'] = e; + return n; + } +} + +new Promise(function (resolve) { resolve(_interopNamespace(require( +/* webpackChunkName: "chunk-name" */ +'./foo.js'/*suffix*/))); }); diff --git a/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/es/main.js b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/es/main.js new file mode 100644 index 00000000000..8f23863149d --- /dev/null +++ b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/es/main.js @@ -0,0 +1,3 @@ +foobar( +/* webpackChunkName: "chunk-name" */ +'./foo.js'/*suffix*/); diff --git a/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/system/main.js b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/system/main.js new file mode 100644 index 00000000000..5967f1516fb --- /dev/null +++ b/test/chunking-form/samples/deprecated/dynamic-import-comments/_expected/system/main.js @@ -0,0 +1,12 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + module.import( + /* webpackChunkName: "chunk-name" */ + './foo.js'/*suffix*/); + + } + }; +}); diff --git a/test/chunking-form/samples/deprecated/dynamic-import-comments/main.js b/test/chunking-form/samples/deprecated/dynamic-import-comments/main.js new file mode 100644 index 00000000000..9519c0a650f --- /dev/null +++ b/test/chunking-form/samples/deprecated/dynamic-import-comments/main.js @@ -0,0 +1,3 @@ +import /* () should not break */ ( +/* webpackChunkName: "chunk-name" */ +'./foo.js'/*suffix*/); diff --git a/test/chunking-form/samples/dynamic-import-name/_config.js b/test/chunking-form/samples/deprecated/dynamic-import-name/_config.js similarity index 89% rename from test/chunking-form/samples/dynamic-import-name/_config.js rename to test/chunking-form/samples/deprecated/dynamic-import-name/_config.js index 12af4716181..601e3b9d0d7 100644 --- a/test/chunking-form/samples/dynamic-import-name/_config.js +++ b/test/chunking-form/samples/deprecated/dynamic-import-name/_config.js @@ -1,6 +1,7 @@ module.exports = { description: 'allows specifying a custom importer function', options: { + strictDeprecations: false, input: 'main.js', onwarn() {}, plugins: { diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js b/test/chunking-form/samples/deprecated/dynamic-import-name/_expected/amd/main.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js rename to test/chunking-form/samples/deprecated/dynamic-import-name/_expected/amd/main.js diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/cjs/main.js b/test/chunking-form/samples/deprecated/dynamic-import-name/_expected/cjs/main.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-name/_expected/cjs/main.js rename to test/chunking-form/samples/deprecated/dynamic-import-name/_expected/cjs/main.js diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/es/main.js b/test/chunking-form/samples/deprecated/dynamic-import-name/_expected/es/main.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-name/_expected/es/main.js rename to test/chunking-form/samples/deprecated/dynamic-import-name/_expected/es/main.js diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/system/main.js b/test/chunking-form/samples/deprecated/dynamic-import-name/_expected/system/main.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-name/_expected/system/main.js rename to test/chunking-form/samples/deprecated/dynamic-import-name/_expected/system/main.js diff --git a/test/chunking-form/samples/dynamic-import-name/main.js b/test/chunking-form/samples/deprecated/dynamic-import-name/main.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-name/main.js rename to test/chunking-form/samples/deprecated/dynamic-import-name/main.js diff --git a/test/chunking-form/samples/dynamic-import-comments/_config.js b/test/chunking-form/samples/dynamic-import-comments/_config.js index d279ae3a1bf..9e74bcab779 100644 --- a/test/chunking-form/samples/dynamic-import-comments/_config.js +++ b/test/chunking-form/samples/dynamic-import-comments/_config.js @@ -1,15 +1,15 @@ module.exports = { - description: 'should not remove inline comments inside dynamic import', + description: 'does not remove inline comments inside dynamic imports', options: { input: 'main.js', onwarn() {}, plugins: { + renderDynamicImport() { + return { left: 'foobar(', right: ')' }; + }, resolveDynamicImport() { return false; } - }, - output: { - dynamicImportFunction: 'foobar' } } }; diff --git a/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js index 24110f00861..686837209f9 100644 --- a/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js @@ -19,8 +19,8 @@ define(['require'], function (require) { 'use strict'; } } - new Promise(function (resolve, reject) { require([ + foobar( /* webpackChunkName: "chunk-name" */ - './foo'/*suffix*/], function (m) { resolve(_interopNamespace(m)); }, reject) }); + './foo'/*suffix*/); }); diff --git a/test/chunking-form/samples/dynamic-import-comments/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import-comments/_expected/cjs/main.js index 7e7e20c640d..5949b7802b5 100644 --- a/test/chunking-form/samples/dynamic-import-comments/_expected/cjs/main.js +++ b/test/chunking-form/samples/dynamic-import-comments/_expected/cjs/main.js @@ -19,6 +19,6 @@ function _interopNamespace(e) { } } -new Promise(function (resolve) { resolve(_interopNamespace(require( +foobar( /* webpackChunkName: "chunk-name" */ -'./foo.js'/*suffix*/))); }); +'./foo.js'/*suffix*/); diff --git a/test/chunking-form/samples/dynamic-import-comments/_expected/system/main.js b/test/chunking-form/samples/dynamic-import-comments/_expected/system/main.js index 5967f1516fb..6a642eabfb8 100644 --- a/test/chunking-form/samples/dynamic-import-comments/_expected/system/main.js +++ b/test/chunking-form/samples/dynamic-import-comments/_expected/system/main.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import( + foobar( /* webpackChunkName: "chunk-name" */ './foo.js'/*suffix*/); diff --git a/test/function/samples/dynamic-import-name-warn/_config.js b/test/function/samples/deprecated/dynamic-import-name-warn/_config.js similarity index 95% rename from test/function/samples/dynamic-import-name-warn/_config.js rename to test/function/samples/deprecated/dynamic-import-name-warn/_config.js index 581dde7a8fa..12b146bac6e 100644 --- a/test/function/samples/dynamic-import-name-warn/_config.js +++ b/test/function/samples/deprecated/dynamic-import-name-warn/_config.js @@ -9,6 +9,7 @@ module.exports = { } }, options: { + strictDeprecations: false, input: 'main.js', plugins: { resolveDynamicImport() { diff --git a/test/function/samples/dynamic-import-name-warn/main.js b/test/function/samples/deprecated/dynamic-import-name-warn/main.js similarity index 100% rename from test/function/samples/dynamic-import-name-warn/main.js rename to test/function/samples/deprecated/dynamic-import-name-warn/main.js diff --git a/test/function/samples/dynamic-import-name/_config.js b/test/function/samples/deprecated/dynamic-import-name/_config.js similarity index 93% rename from test/function/samples/dynamic-import-name/_config.js rename to test/function/samples/deprecated/dynamic-import-name/_config.js index 917b20a396f..afb4f3ba114 100644 --- a/test/function/samples/dynamic-import-name/_config.js +++ b/test/function/samples/deprecated/dynamic-import-name/_config.js @@ -10,6 +10,7 @@ module.exports = { } }, options: { + strictDeprecations: false, input: 'main.js', plugins: { resolveDynamicImport() { diff --git a/test/function/samples/dynamic-import-name/main.js b/test/function/samples/deprecated/dynamic-import-name/main.js similarity index 100% rename from test/function/samples/dynamic-import-name/main.js rename to test/function/samples/deprecated/dynamic-import-name/main.js diff --git a/test/function/samples/deprecations/dynamicImportFunction/_config.js b/test/function/samples/deprecations/dynamicImportFunction/_config.js new file mode 100644 index 00000000000..10db1585d19 --- /dev/null +++ b/test/function/samples/deprecations/dynamicImportFunction/_config.js @@ -0,0 +1,13 @@ +module.exports = { + description: 'marks the "output.dynamicImportFunction" option as deprecated', + options: { + output: { + dynamicImportFunction: 'foo' + } + }, + generateError: { + code: 'DEPRECATED_FEATURE', + message: + 'The "output.dynamicImportFunction" option is deprecated. Use the "renderDynamicImport" plugin hook instead.' + } +}; diff --git a/test/function/samples/deprecations/dynamicImportFunction/main.js b/test/function/samples/deprecations/dynamicImportFunction/main.js new file mode 100644 index 00000000000..f8a2d88d245 --- /dev/null +++ b/test/function/samples/deprecations/dynamicImportFunction/main.js @@ -0,0 +1,11 @@ +const foo = {}; + +function doIt(x) { + if (foo[x]) { + return true; + } + foo[x] = true; +} + +doIt('x'); +assert.ok(doIt('x'), 'foo was not reassigned');