diff --git a/package-lock.json b/package-lock.json index ab6e66921..0eb3a567a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12924,6 +12924,15 @@ "inherits": "^2.0.1" } }, + "rollup": { + "version": "2.18.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.18.2.tgz", + "integrity": "sha512-+mzyZhL9ZyLB3eHBISxRNTep9Z2qCuwXzAYkUbFyz7yNKaKH03MFKeiGOS1nv2uvPgDb4ASKv+FiS5mC4h5IFQ==", + "dev": true, + "requires": { + "fsevents": "~2.1.2" + } + }, "rsvp": { "version": "4.8.5", "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz", diff --git a/package.json b/package.json index 3bf3adb51..2cb9479d8 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "natives": "^1.1.6", "prettier": "^2.2.1", "rimraf": "^3.0.2", + "rollup": "^2.18.2", "rxjs": "~6.6.0", "ts-jest": "^26.4.4", "ts-node": "~8.3.0", diff --git a/scripts/build/ngx.ts b/scripts/build/ngx.ts index 8f26ae780..5d7cad7b7 100644 --- a/scripts/build/ngx.ts +++ b/scripts/build/ngx.ts @@ -2,6 +2,7 @@ import * as ts from 'typescript'; import * as fs from 'fs-extra'; import * as path from 'path'; import * as rimraf from 'rimraf'; +import * as rollup from 'rollup'; import { generateDeclarations } from './transpile'; import { clone } from 'lodash'; import { EmitFlags, createCompilerHost, CompilerOptions, CompilerHost, createProgram } from '@angular/compiler-cli'; @@ -54,6 +55,31 @@ export function generateDeclarationFiles() { generateDeclarations(PLUGIN_PATHS.map(p => p.replace('index.ts', 'ngx/index.ts'))); } +export function generateLegacyBundles() { + [ + path.resolve(ROOT, 'dist/@ionic-native/core/index.js'), + ...PLUGIN_PATHS.map(p => + p.replace(path.join(ROOT, 'src'), path.join(ROOT, 'dist')).replace('index.ts', 'ngx/index.js') + ), + ].forEach(p => + rollup + .rollup({ + input: p, + onwarn(warning, warn) { + if (warning.code === 'UNUSED_EXTERNAL_IMPORT') return; + warn(warning); + }, + external: ['@angular/core', '@ionic-native/core', 'rxjs', 'tslib'], + }) + .then(bundle => + bundle.write({ + file: path.join(path.dirname(p), 'bundle.js'), + format: 'cjs', + }) + ) + ); +} + // remove reference to @ionic-native/core decorators export function modifyMetadata() { debugger; diff --git a/scripts/tasks/build-ngx.ts b/scripts/tasks/build-ngx.ts index 9d0b14f74..e5dfb3d3c 100644 --- a/scripts/tasks/build-ngx.ts +++ b/scripts/tasks/build-ngx.ts @@ -1,7 +1,15 @@ -import { cleanupNgx, generateDeclarationFiles, modifyMetadata, transpileNgx, transpileNgxCore } from '../build/ngx'; +import { + cleanupNgx, + generateLegacyBundles, + generateDeclarationFiles, + modifyMetadata, + transpileNgx, + transpileNgxCore, +} from '../build/ngx'; transpileNgxCore(); transpileNgx(); +generateLegacyBundles(); generateDeclarationFiles(); modifyMetadata(); cleanupNgx(); diff --git a/scripts/tasks/publish.ts b/scripts/tasks/publish.ts index 2fee939f5..e2e585761 100644 --- a/scripts/tasks/publish.ts +++ b/scripts/tasks/publish.ts @@ -15,6 +15,7 @@ const FLAGS = '--access public'; const PACKAGE_JSON_BASE = { description: 'Ionic Native - Native plugins for ionic apps', + main: 'bundle.js', module: 'index.js', typings: 'index.d.ts', author: 'ionic',