Skip to content

Commit

Permalink
fix(build): publish Node (server) friendly bundles (#3483)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sogl <mytechde@outlook.com>
  • Loading branch information
laurentgoudet and danielsogl authored Apr 5, 2021
1 parent 0932e11 commit b4227f2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions scripts/build/ngx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion scripts/tasks/build-ngx.ts
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions scripts/tasks/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b4227f2

Please sign in to comment.