Skip to content

Commit

Permalink
fix(nativescript): app generator option without structure (#194)
Browse files Browse the repository at this point in the history
closes #192
  • Loading branch information
NathanWalker authored Apr 25, 2020
1 parent 1bd7cc4 commit 384713b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 31 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@angular/router": "^9.1.0",
"@angular/service-worker": "^9.1.0",
"@angular/upgrade": "^9.1.0",

"@cypress/webpack-preprocessor": "^4.1.0",
"@nrwl/angular": "~9.2.2",
"@nrwl/express": "~9.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
},
"description": "NativeScript Application",
"scripts": {
"postinstall": "node ./tools/xplat-postinstall.js"
"postinstall": "node ./tools/xplat-postinstall.js && npm run ngcc",
"ngcc": "ngcc --properties es2015 module main --first-only"
},
"dependencies": {
"@angular/animations": "<%= angularVersion %>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptModule } from '@nativescript/angular';
import { NativeScriptModule, NativeScriptHttpClientModule } from '@nativescript/angular';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"target": "es2015",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"lib": ["es6", "dom", "es2015.iterable"],
"removeComments": true,
"downlevelIteration": true,
"skipLibCheck": true,
"lib": ["es2017", "dom", "webworker", "es6"],
"typeRoots": ["./node_modules/@types"],
"baseUrl": ".",
"paths": {
Expand All @@ -17,7 +20,8 @@
],
"@<%= npmScope %>/nativescript/*": [
"<%= pathOffset %>xplat/<%= xplatFolderName %>/*"
]
],
"*": ["./node_modules/*"]
}
},
"exclude": ["node_modules", "platforms"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const hashSalt = Date.now().toString();
module.exports = env => {
// Add your custom Activities, Services and other Android app components here.
const appComponents = [
'tns-core-modules/ui/frame',
'tns-core-modules/ui/frame/activity'
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
];

const platform = env && ((env.android && 'android') || (env.ios && 'ios'));
Expand Down Expand Up @@ -65,9 +65,14 @@ module.exports = env => {
hiddenSourceMap, // --env.hiddenSourceMap
hmr, // --env.hmr,
unitTesting, // --env.unitTesting
verbose // --env.verbose
verbose, // --env.verbose
ci, // --env.ci
snapshotInDocker, // --env.snapshotInDocker
skipSnapshotTools, // --env.skipSnapshotTools
compileSnapshot // --env.compileSnapshot
} = env;

const useLibs = compileSnapshot;
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
const externals = nsWebpack.getConvertedExternals(env.externals);
const appFullPath = resolve(projectRoot, appPath);
Expand All @@ -78,9 +83,9 @@ module.exports = env => {
const entries = { bundle: entryPath };
const areCoreModulesExternal =
Array.isArray(env.externals) &&
env.externals.some(e => e.indexOf('tns-core-modules') > -1);
env.externals.some(e => e.indexOf('@nativescript') > -1);
if (platform === 'ios' && !areCoreModulesExternal) {
entries['tns_modules/tns-core-modules/inspector_modules'] =
entries['tns_modules/@nativescript/core/inspector_modules'] =
'inspector_modules';
}

Expand All @@ -90,8 +95,22 @@ module.exports = env => {
ngCompilerTransformers.push(nsReplaceBootstrap);
}

if (hmr) {
ngCompilerTransformers.push(nsSupportHmrNg);
const copyTargets = [
{ from: { glob: 'assets/**' } },
{ from: { glob: 'fonts/**' } }
// copy monorepo shared assests
// for example:
// { from: '../../../libs/assets/i18n', to: 'assets/i18n' }
];

if (!production) {
// copy monorepo shared assets which are for development purposes only
// for example: a mock data json folder
// copyTargets.push({ from: '../../../libs/assets/mockdata', to: 'assets/mockdata' });

if (hmr) {
ngCompilerTransformers.push(nsSupportHmrNg);
}
}

// when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
Expand Down Expand Up @@ -185,13 +204,15 @@ module.exports = env => {
extensions: ['.ts', '.js', '.scss', '.css'],
// Resolve {N} system modules from tns-core-modules
modules: [
resolve(__dirname, 'node_modules/tns-core-modules'),
resolve(__dirname, 'node_modules/@nativescript/core'),
resolve(__dirname, 'node_modules'),
'node_modules/tns-core-modules',
'node_modules/@nativescript/core',
'node_modules'
],
alias: {
'~': appFullPath
'~': appFullPath,
'tns-core-modules': '@nativescript/core',
'nativescript-angular': '@nativescript/angular'
},
symlinks: true
},
Expand Down Expand Up @@ -235,7 +256,7 @@ module.exports = env => {
minimizer: [
new TerserPlugin({
parallel: true,
cache: true,
cache: !ci,
sourceMap: isAnySourceMapEnabled,
terserOptions: {
output: {
Expand All @@ -246,16 +267,38 @@ module.exports = env => {
// The Android SBG has problems parsing the output
// when these options are enabled
collapse_vars: platform !== 'android',
sequences: platform !== 'android'
}
sequences: platform !== 'android',
// custom
drop_console: true,
drop_debugger: true,
ecma: 6,
keep_infinity: platform === 'android', // for Chrome/V8
reduce_funcs: platform !== 'android', // for Chrome/V8
pure_funcs: [
'this._log.debug',
'this._log.error',
'this._log.info',
'this._log.warn',
'this.log.debug',
'this.log.error',
'this.log.info',
'this.log.warn'
],
global_defs: {
__UGLIFIED__: true
}
},
// custom
ecma: 6,
safari10: platform !== 'android'
}
})
]
},
module: {
rules: [
{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
include: join(appFullPath, entryPath),
use: [
// Require all Android app components
platform === 'android' && {
Expand Down Expand Up @@ -330,14 +373,9 @@ module.exports = env => {
// Remove all files from the out dir.
new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }),
// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin(
[
{ from: { glob: 'fonts/**' } },
{ from: { glob: '**/*.jpg' } },
{ from: { glob: '**/*.png' } }
],
{ ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }
),
new CopyWebpackPlugin(copyTargets, {
ignore: [`${relative(appPath, appResourcesFullPath)}/**`]
}),
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
// For instructions on how to set up workers with webpack
// check out https://github.com/nativescript/worker-loader
Expand Down Expand Up @@ -376,12 +414,15 @@ module.exports = env => {
'nativescript-angular/router'
],
projectRoot,
webpackConfig: config
webpackConfig: config,
snapshotInDocker,
skipSnapshotTools,
useLibs
})
);
}

if (hmr) {
if (!production && hmr) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nativescript-angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const nodeSassVersion = '^4.12.0';
export const terserWebpackVersion = '~2.2.0';
export const tslibVersion = '~1.11.0';
export const nsThemeCoreVersion = '^1.0.4';
export const typescriptVersion = '~3.7.4';
export const typescriptVersion = '~3.8.3';

// in case workspace had not added angular yet
// TODO: move deps to nstudio/xplat to ref from everywhere for all supported framework versions
Expand Down

0 comments on commit 384713b

Please sign in to comment.