From f929baf77fa95fb3bcac8a21c8c606a62ba3b97e Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Mon, 20 Aug 2018 15:43:53 +0300 Subject: [PATCH 1/6] chore: target 'rc' of nativescript-dev-webpack We should update that to 0.16.0 when the plugin is released. --- package-lock.json | 28 ++++++++++++++++------ src/add-ns/index.ts | 2 +- src/ng-new/application/_files/package.json | 2 +- src/ng-new/shared/_files/package.json | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index c958d83..3aa7d38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -942,11 +942,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -959,15 +961,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -1070,7 +1075,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -1080,6 +1086,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1092,17 +1099,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -1119,6 +1129,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -1191,7 +1202,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -1201,6 +1213,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -1306,6 +1319,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/src/add-ns/index.ts b/src/add-ns/index.ts index 25d5d82..4c7c1d6 100644 --- a/src/add-ns/index.ts +++ b/src/add-ns/index.ts @@ -286,7 +286,7 @@ const installNpmModules = () => (_tree: Tree, context: SchematicContext) => { 'tns-core-modules': '~4.2.0' }, devDependencies: { - 'nativescript-dev-webpack': '^0.15.0' + 'nativescript-dev-webpack': 'rc' } } diff --git a/src/ng-new/application/_files/package.json b/src/ng-new/application/_files/package.json index 2151e53..44c75da 100644 --- a/src/ng-new/application/_files/package.json +++ b/src/ng-new/application/_files/package.json @@ -28,7 +28,7 @@ "@angular-devkit/core": "~0.7.0", "@nativescript/schematics": "~0.2.0", "nativescript-dev-typescript": "~0.7.0",<% if(webpack) {%> - "nativescript-dev-webpack": "^0.15.0", + "nativescript-dev-webpack": "rc", "@ngtools/webpack": "~6.1.0", <% } %>"typescript": "~2.7.2" } diff --git a/src/ng-new/shared/_files/package.json b/src/ng-new/shared/_files/package.json index 5144a96..18f79bf 100644 --- a/src/ng-new/shared/_files/package.json +++ b/src/ng-new/shared/_files/package.json @@ -50,7 +50,7 @@ "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "nativescript-dev-typescript": "~0.7.0", - "nativescript-dev-webpack": "^0.15.0", + "nativescript-dev-webpack": "rc", "protractor": "~5.3.0", "ts-node": "~5.0.1", "tslint": "~5.9.1", From fe889d8b4855a8412e09301e07b72236d69e4cb1 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Mon, 20 Aug 2018 18:24:05 +0300 Subject: [PATCH 2/6] chore: remove update-dev-webpack schematic --- package-lock.json | 28 ++++------------ src/add-ns/index.ts | 12 ------- src/add-web/index.ts | 22 ------------- src/collection.json | 5 --- src/update-dev-webpack/index.ts | 52 ------------------------------ src/update-dev-webpack/schema.d.ts | 6 ---- src/update-dev-webpack/schema.json | 15 --------- 7 files changed, 7 insertions(+), 133 deletions(-) delete mode 100644 src/update-dev-webpack/index.ts delete mode 100644 src/update-dev-webpack/schema.d.ts delete mode 100644 src/update-dev-webpack/schema.json diff --git a/package-lock.json b/package-lock.json index 3aa7d38..c958d83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -942,13 +942,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -961,18 +959,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -1075,8 +1070,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -1086,7 +1080,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1099,20 +1092,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.2.4", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -1129,7 +1119,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -1202,8 +1191,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -1213,7 +1201,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -1319,7 +1306,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/src/add-ns/index.ts b/src/add-ns/index.ts index 4c7c1d6..f74d464 100644 --- a/src/add-ns/index.ts +++ b/src/add-ns/index.ts @@ -317,15 +317,3 @@ const addWebpackConfig = () => (tree:Tree) => { } } -// const updateDevWebpack = () => (tree: Tree, context: SchematicContext) => { -// context.logger.info('Updating webpack.config.js'); -// const options: UpdateDevWebpackOptions = { -// nsext: extensions.ns -// } - -// if (projectSettings.ngCliSemVer.major === 1) { -// return schematic('update-dev-webpack', options)(tree, context); -// } else { -// context.addTask(new RunSchematicTask('@nativescript/schematics', 'update-dev-webpack', options), [npmInstallTaskId]); -// } -// } diff --git a/src/add-web/index.ts b/src/add-web/index.ts index 1b27cd7..1e79381 100644 --- a/src/add-web/index.ts +++ b/src/add-web/index.ts @@ -1,5 +1,4 @@ import { Schema as MigrationOptions } from './schema'; -import { Schema as UpdateDevWebpackOptions } from '../update-dev-webpack/schema'; import { getSourceFile, addExtension } from '../utils'; import { @@ -39,7 +38,6 @@ export default function (options: MigrationOptions): Rule { validatePrerequisits, getProjectSettings, applyNsExtensionToCoreFiles, - updateWebpackConfig(), updateMainTns, mergeNgProjectSettings, addWebFiles(), @@ -89,26 +87,6 @@ const applyNsExtensionToCoreFiles = (tree: Tree) => { renameFilesForce(paths)(tree); }; -/** -* update webpack.config referenes: -* - main.ts -> bundle: "./main.tns.ts", -* - tsconfig.json -> tsConfigPath: "tsconfig.tns.json" -* - app.module -> app.module.tns#AppModule -*/ -const updateWebpackConfig = () => (tree: Tree, context: SchematicContext) => { - //TODO: need to test this - const options: UpdateDevWebpackOptions = { - nsext: extensions.ns - } - - return schematic('update-dev-webpack', options)(tree, context); - // installDevWebpackIfRequired(tree); - // updateMainTsExtension(tree); - // updateTsConfigExtension(tree); - // updateEntryModuleExtension(tree); - // return tree; -}; - // function installDevWebpackIfRequired(tree: Tree) { // if (!tree.exists(webpackConfigPath)) { // // TODO: code to install nativescript-dev-webpack diff --git a/src/collection.json b/src/collection.json index c56afdd..32ad9ad 100644 --- a/src/collection.json +++ b/src/collection.json @@ -69,11 +69,6 @@ "factory": "./npm-install", "schema": "./npm-install/schema.json" }, - "update-dev-webpack": { - "description": "Updates webpack.config.js file, to work with a code sharing structure", - "factory": "./update-dev-webpack", - "schema": "./update-dev-webpack/schema.json" - }, "refactor-nsng-modules": { "factory": "./refactor-nsng-modules", "description": "Upgrades existing {N} Angular projects.", diff --git a/src/update-dev-webpack/index.ts b/src/update-dev-webpack/index.ts deleted file mode 100644 index e4aa3b3..0000000 --- a/src/update-dev-webpack/index.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - Rule, - Tree, - chain, - SchematicsException -} from '@angular-devkit/schematics'; - -import * as ts from 'typescript'; - -import { Schema as UpdateOptions } from './schema'; -import { getSourceFile } from '../utils'; -import { findNode, replaceTextInNode } from '../ast-utils'; -const webpackConfigPath = 'webpack.config.js'; - -// You don't have to export the function as default. You can also have more than one rule factory -// per file. -export default function(options: UpdateOptions): Rule { - return chain([ - validatePrerequisits, - validateOptions(options), - updateTsConfigExtension(options.nsext), - ]) -} - -const validatePrerequisits = (tree: Tree) => { - //make sure that nativescript-dev-webpack is installed - if (!tree.exists(webpackConfigPath)) { - throw new SchematicsException(`nativescript-dev-webpack is missing. Run: -npm nativescript-dev-webpack -and try again.`); - } -} - -const validateOptions = (options: UpdateOptions) => () => { - if (options.nsext.charAt(0) !== '.') { - throw new SchematicsException(`nsext [${options.nsext}] should start with a .`); - } -}; - -const updateTsConfigExtension = (nsext: string) => (tree: Tree) => { - const source = getSourceFile(tree, webpackConfigPath); - const propertyToUpdate = '"tsconfig.esm.json"'; - - const node = findNode(source, [ - { kind: ts.SyntaxKind.NewExpression, name: 'nsWebpack.NativeScriptAngularCompilerPlugin' }, - { kind: ts.SyntaxKind.PropertyAssignment, name: 'tsConfigPath' } - ]); - - // TODO: this specific config might change with the next update - const tsConfigPath = `aot ? "tsconfig.aot.json" : "tsconfig${nsext}.json"`; - replaceTextInNode(tree, node, propertyToUpdate, tsConfigPath); -} diff --git a/src/update-dev-webpack/schema.d.ts b/src/update-dev-webpack/schema.d.ts deleted file mode 100644 index eb78bdc..0000000 --- a/src/update-dev-webpack/schema.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Schema { - /** - * Extension used for NativeScript files. Default: .tns - */ - nsext: string; -} diff --git a/src/update-dev-webpack/schema.json b/src/update-dev-webpack/schema.json deleted file mode 100644 index 6ae6c0d..0000000 --- a/src/update-dev-webpack/schema.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "id": "SchematicsNativeScriptUpdateWebpack", - "title": "NativeScript Angular npm-install Options Schema", - "type": "object", - "properties": { - "nsext": { - "type": "string", - "description": "Extension used for NativeScript files", - "default": ".tns" - } - }, - "required": [ - ] -} From c77ed6d95e4708a894cc42b12845a86727163926 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Mon, 20 Aug 2018 18:27:04 +0300 Subject: [PATCH 3/6] refactor: remove custom webpack configs --- src/add-ns/_webpack-files/webpack.config.js | 266 ------------------ src/add-ns/index.ts | 21 -- .../_webpack_files/webpack.config.js | 266 ------------------ src/ng-new/application/index.ts | 14 - src/ng-new/shared/_files/webpack.config.js | 266 ------------------ 5 files changed, 833 deletions(-) delete mode 100644 src/add-ns/_webpack-files/webpack.config.js delete mode 100644 src/ng-new/application/_webpack_files/webpack.config.js delete mode 100644 src/ng-new/shared/_files/webpack.config.js diff --git a/src/add-ns/_webpack-files/webpack.config.js b/src/add-ns/_webpack-files/webpack.config.js deleted file mode 100644 index f0d620b..0000000 --- a/src/add-ns/_webpack-files/webpack.config.js +++ /dev/null @@ -1,266 +0,0 @@ -const { join, relative, resolve, sep } = require("path"); - -const webpack = require("webpack"); -const nsWebpack = require("nativescript-dev-webpack"); -const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -const CleanWebpackPlugin = require("clean-webpack-plugin"); -const CopyWebpackPlugin = require("copy-webpack-plugin"); -const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); -const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); -const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); -const { AngularCompilerPlugin } = require("@ngtools/webpack"); - -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", - ]; - - const platform = env && (env.android && "android" || env.ios && "ios"); - if (!platform) { - throw new Error("You need to provide a target platform!"); - } - - const projectRoot = __dirname; - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file - // when bundling with `tns run android|ios --bundle`. - appPath = "app", - appResourcesPath = "app/App_Resources", - - // You can provide the following flags when running 'tns run android|ios' - aot, // --env.aot - snapshot, // --env.snapshot - uglify, // --env.uglify - report, // --env.report - sourceMap, // --env.sourceMap - } = env; - - const appFullPath = resolve(projectRoot, appPath); - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - - const entryModule = aot ? - nsWebpack.getAotEntryModule(appFullPath) : - `${nsWebpack.getEntryModule(appFullPath)}.ts`; - const entryPath = `.${sep}${entryModule}`; - - const config = { - mode: uglify ? "production" : "development", - context: appFullPath, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - "**/.*", - ] - }, - target: nativescriptTarget, - entry: { - bundle: entryPath, - }, - output: { - pathinfo: false, - path: dist, - libraryTarget: "commonjs2", - filename: "[name].js", - globalObject: "global", - }, - resolve: { - 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"), - "node_modules/tns-core-modules", - "node_modules", - ], - alias: { - '~': appFullPath - }, - symlinks: true - }, - resolveLoader: { - symlinks: false - }, - node: { - // Disable node shims that conflict with NativeScript - "http": false, - "timers": false, - "setImmediate": false, - "fs": "empty", - "__dirname": false, - }, - devtool: sourceMap ? "inline-source-map" : "none", - optimization: { - splitChunks: { - cacheGroups: { - vendor: { - name: "vendor", - chunks: "all", - test: (module, chunks) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || - appComponents.some(comp => comp === moduleName); - }, - enforce: true, - }, - } - }, - minimize: !!uglify, - minimizer: [ - new UglifyJsPlugin({ - uglifyOptions: { - parallel: true, - cache: true, - output: { - comments: false, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - 'collapse_vars': platform !== "android", - sequences: platform !== "android", - } - } - }) - ], - }, - module: { - rules: [ - { - test: new RegExp(entryPath), - use: [ - // Require all Android app components - platform === "android" && { - loader: "nativescript-dev-webpack/android-app-components-loader", - options: { modules: appComponents } - }, - - { - loader: "nativescript-dev-webpack/bundle-config-loader", - options: { - angular: true, - loadCss: !snapshot, // load the application css if in debug mode - } - }, - ].filter(loader => !!loader) - }, - - { test: /\.html$|\.xml$/, use: "raw-loader" }, - - // tns-core-modules reads the app.css and its imports using css-loader - { - test: /[\/|\\]app\.css$/, - use: { - loader: "css-loader", - options: { minimize: false, url: false }, - } - }, - { - test: /[\/|\\]app\.scss$/, - use: [ - { loader: "css-loader", options: { minimize: false, url: false } }, - "sass-loader" - ] - }, - - // Angular components reference css files and their imports using raw-loader - { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" }, - { test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] }, - - // Compile TypeScript files with ahead-of-time compiler. - { - test: /.ts$/, use: [ - "nativescript-dev-webpack/moduleid-compat-loader", - "@ngtools/webpack", - ] - }, - - // Mark files inside `@angular/core` as using SystemJS style dynamic imports. - // Removing this will cause deprecation warnings to appear. - { - test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, - parser: { system: true }, - }, - ], - }, - plugins: [ - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - "global.TNS_WEBPACK": "true", - }), - // Remove all files from the out dir. - new CleanWebpackPlugin([ `${dist}/**/*` ]), - // Copy native app resources to out dir. - new CopyWebpackPlugin([ - { - from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, - to: `${dist}/App_Resources/${appResourcesPlatformDir}`, - context: projectRoot - }, - ]), - // Copy assets to out dir. Add your own globs as needed. - new CopyWebpackPlugin([ - { from: "fonts/**" }, - { from: "**/*.jpg" }, - { from: "**/*.png" }, - ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), - // Generate a bundle starter script and activate it in package.json - new nsWebpack.GenerateBundleStarterPlugin([ - "./vendor", - "./bundle", - ]), - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - - new AngularCompilerPlugin({ - hostReplacementPaths: nsWebpack.getResolver([platform, "<%= shortExt %>"]), - entryModule: resolve(appPath, "<%= entryModuleImportPath %>#<%= entryModuleClassName %>"), - tsConfigPath: join(__dirname, aot ? "tsconfig.aot.json" : "tsconfig<%= nsext %>.json"), - skipCodeGeneration: !aot, - sourceMap: !!sourceMap, - }), - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - ], - }; - - if (report) { - // Generate report files for bundles content - config.plugins.push(new BundleAnalyzerPlugin({ - analyzerMode: "static", - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, "report", `report.html`), - statsFilename: resolve(projectRoot, "report", `stats.json`), - })); - } - - if (snapshot) { - config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: "vendor", - angular: true, - requireModules: [ - "reflect-metadata", - "@angular/platform-browser", - "@angular/core", - "@angular/common", - "@angular/router", - "nativescript-angular/platform-static", - "nativescript-angular/router", - ], - projectRoot, - webpackConfig: config, - })); - } - - return config; -}; diff --git a/src/add-ns/index.ts b/src/add-ns/index.ts index f74d464..2266524 100644 --- a/src/add-ns/index.ts +++ b/src/add-ns/index.ts @@ -54,8 +54,6 @@ export default function (options: MigrationOptions): Rule { excludeNsFilesFromTsconfig, addHomeComponent(options.nsExtension, options.webExtension), - addWebpackConfig(), - installNpmModules() ]); } @@ -298,22 +296,3 @@ const installNpmModules = () => (_tree: Tree, context: SchematicContext) => { context.addTask(new RunSchematicTask('@nativescript/schematics', 'npm-install', options)); } -const addWebpackConfig = () => (tree:Tree) => { - const templateOptions = { - entryModuleClassName: projectSettings.entryModuleClassName, - entryModuleImportPath: projectSettings.entryModuleImportPath, - nsext: extensions.ns, - shortExt: extensions.ns.replace('.', '') - } - - // This is always going to be the case for ng cli before 6.0 - if (!tree.exists('webpack.config.js')) { - const templateSource = apply(url('./_webpack-files'), [ - template(templateOptions) - ]); - return mergeWith(templateSource); - } else { - throw new SchematicsException('Failed at addWebpackConfig step. webpack.config.js already exists.'); - } -} - diff --git a/src/ng-new/application/_webpack_files/webpack.config.js b/src/ng-new/application/_webpack_files/webpack.config.js deleted file mode 100644 index 895ce29..0000000 --- a/src/ng-new/application/_webpack_files/webpack.config.js +++ /dev/null @@ -1,266 +0,0 @@ -const { join, relative, resolve, sep } = require("path"); - -const webpack = require("webpack"); -const nsWebpack = require("nativescript-dev-webpack"); -const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -const CleanWebpackPlugin = require("clean-webpack-plugin"); -const CopyWebpackPlugin = require("copy-webpack-plugin"); -const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); -const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); -const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); -const { AngularCompilerPlugin } = require("@ngtools/webpack"); - -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", - ]; - - const platform = env && (env.android && "android" || env.ios && "ios"); - if (!platform) { - throw new Error("You need to provide a target platform!"); - } - - const projectRoot = __dirname; - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file - // when bundling with `tns run android|ios --bundle`. - appPath = "app", - appResourcesPath = "app/App_Resources", - - // You can provide the following flags when running 'tns run android|ios' - aot, // --env.aot - snapshot, // --env.snapshot - uglify, // --env.uglify - report, // --env.report - sourceMap, // --env.sourceMap - } = env; - - const appFullPath = resolve(projectRoot, appPath); - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - - const entryModule = aot ? - nsWebpack.getAotEntryModule(appFullPath) : - `${nsWebpack.getEntryModule(appFullPath)}.ts`; - const entryPath = `.${sep}${entryModule}`; - - const config = { - mode: uglify ? "production" : "development", - context: appFullPath, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - "**/.*", - ] - }, - target: nativescriptTarget, - entry: { - bundle: entryPath, - }, - output: { - pathinfo: false, - path: dist, - libraryTarget: "commonjs2", - filename: "[name].js", - globalObject: "global", - }, - resolve: { - 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"), - "node_modules/tns-core-modules", - "node_modules", - ], - alias: { - '~': appFullPath - }, - symlinks: true - }, - resolveLoader: { - symlinks: false - }, - node: { - // Disable node shims that conflict with NativeScript - "http": false, - "timers": false, - "setImmediate": false, - "fs": "empty", - "__dirname": false, - }, - devtool: sourceMap ? "inline-source-map" : "none", - optimization: { - splitChunks: { - cacheGroups: { - vendor: { - name: "vendor", - chunks: "all", - test: (module, chunks) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || - appComponents.some(comp => comp === moduleName); - }, - enforce: true, - }, - } - }, - minimize: !!uglify, - minimizer: [ - new UglifyJsPlugin({ - uglifyOptions: { - parallel: true, - cache: true, - output: { - comments: false, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - 'collapse_vars': platform !== "android", - sequences: platform !== "android", - } - } - }) - ], - }, - module: { - rules: [ - { - test: new RegExp(entryPath), - use: [ - // Require all Android app components - platform === "android" && { - loader: "nativescript-dev-webpack/android-app-components-loader", - options: { modules: appComponents } - }, - - { - loader: "nativescript-dev-webpack/bundle-config-loader", - options: { - angular: true, - loadCss: !snapshot, // load the application css if in debug mode - } - }, - ].filter(loader => !!loader) - }, - - { test: /\.html$|\.xml$/, use: "raw-loader" }, - - // tns-core-modules reads the app.css and its imports using css-loader - { - test: /[\/|\\]app\.css$/, - use: { - loader: "css-loader", - options: { minimize: false, url: false }, - } - }, - { - test: /[\/|\\]app\.scss$/, - use: [ - { loader: "css-loader", options: { minimize: false, url: false } }, - "sass-loader" - ] - }, - - // Angular components reference css files and their imports using raw-loader - { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" }, - { test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] }, - - // Compile TypeScript files with ahead-of-time compiler. - { - test: /.ts$/, use: [ - "nativescript-dev-webpack/moduleid-compat-loader", - "@ngtools/webpack", - ] - }, - - // Mark files inside `@angular/core` as using SystemJS style dynamic imports. - // Removing this will cause deprecation warnings to appear. - { - test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, - parser: { system: true }, - }, - ], - }, - plugins: [ - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - "global.TNS_WEBPACK": "true", - }), - // Remove all files from the out dir. - new CleanWebpackPlugin([ `${dist}/**/*` ]), - // Copy native app resources to out dir. - new CopyWebpackPlugin([ - { - from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, - to: `${dist}/App_Resources/${appResourcesPlatformDir}`, - context: projectRoot - }, - ]), - // Copy assets to out dir. Add your own globs as needed. - new CopyWebpackPlugin([ - { from: "fonts/**" }, - { from: "**/*.jpg" }, - { from: "**/*.png" }, - ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), - // Generate a bundle starter script and activate it in package.json - new nsWebpack.GenerateBundleStarterPlugin([ - "./vendor", - "./bundle", - ]), - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - - new AngularCompilerPlugin({ - hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]), - entryModule: resolve(appPath, "app.module#AppModule"), - tsConfigPath: join(__dirname, "tsconfig.esm.json"), - skipCodeGeneration: !aot, - sourceMap: !!sourceMap, - }), - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - ], - }; - - if (report) { - // Generate report files for bundles content - config.plugins.push(new BundleAnalyzerPlugin({ - analyzerMode: "static", - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, "report", `report.html`), - statsFilename: resolve(projectRoot, "report", `stats.json`), - })); - } - - if (snapshot) { - config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: "vendor", - angular: true, - requireModules: [ - "reflect-metadata", - "@angular/platform-browser", - "@angular/core", - "@angular/common", - "@angular/router", - "nativescript-angular/platform-static", - "nativescript-angular/router", - ], - projectRoot, - webpackConfig: config, - })); - } - - return config; -}; diff --git a/src/ng-new/application/index.ts b/src/ng-new/application/index.ts index 969187f..b2001c2 100644 --- a/src/ng-new/application/index.ts +++ b/src/ng-new/application/index.ts @@ -36,20 +36,6 @@ export default function (options: ApplicationOptions) { ]), ), - options.webpack ? - mergeWith( - apply(url('./_webpack_files'), [ - template({ - ...options as any, - utils: stringUtils, - sourcedir, - dot: '.', - }), - move(appPath), - ]), - ) : - noop(), - runAngularJsonSchematic({ path: options.name, name: options.name, diff --git a/src/ng-new/shared/_files/webpack.config.js b/src/ng-new/shared/_files/webpack.config.js deleted file mode 100644 index 837faee..0000000 --- a/src/ng-new/shared/_files/webpack.config.js +++ /dev/null @@ -1,266 +0,0 @@ -const { join, relative, resolve, sep } = require("path"); - -const webpack = require("webpack"); -const nsWebpack = require("nativescript-dev-webpack"); -const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -const CleanWebpackPlugin = require("clean-webpack-plugin"); -const CopyWebpackPlugin = require("copy-webpack-plugin"); -const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); -const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); -const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); -const { AngularCompilerPlugin } = require("@ngtools/webpack"); - -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", - ]; - - const platform = env && (env.android && "android" || env.ios && "ios"); - if (!platform) { - throw new Error("You need to provide a target platform!"); - } - - const projectRoot = __dirname; - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file - // when bundling with `tns run android|ios --bundle`. - appPath = "app", - appResourcesPath = "app/App_Resources", - - // You can provide the following flags when running 'tns run android|ios' - aot, // --env.aot - snapshot, // --env.snapshot - uglify, // --env.uglify - report, // --env.report - sourceMap, // --env.sourceMap - } = env; - - const appFullPath = resolve(projectRoot, appPath); - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - - const entryModule = aot ? - nsWebpack.getAotEntryModule(appFullPath) : - `${nsWebpack.getEntryModule(appFullPath)}.ts`; - const entryPath = `.${sep}${entryModule}`; - - const config = { - mode: uglify ? "production" : "development", - context: appFullPath, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - "**/.*", - ] - }, - target: nativescriptTarget, - entry: { - bundle: entryPath, - }, - output: { - pathinfo: false, - path: dist, - libraryTarget: "commonjs2", - filename: "[name].js", - globalObject: "global", - }, - resolve: { - 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"), - "node_modules/tns-core-modules", - "node_modules", - ], - alias: { - '~': appFullPath - }, - symlinks: true - }, - resolveLoader: { - symlinks: false - }, - node: { - // Disable node shims that conflict with NativeScript - "http": false, - "timers": false, - "setImmediate": false, - "fs": "empty", - "__dirname": false, - }, - devtool: sourceMap ? "inline-source-map" : "none", - optimization: { - splitChunks: { - cacheGroups: { - vendor: { - name: "vendor", - chunks: "all", - test: (module, chunks) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || - appComponents.some(comp => comp === moduleName); - }, - enforce: true, - }, - } - }, - minimize: !!uglify, - minimizer: [ - new UglifyJsPlugin({ - uglifyOptions: { - parallel: true, - cache: true, - output: { - comments: false, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - 'collapse_vars': platform !== "android", - sequences: platform !== "android", - } - } - }) - ], - }, - module: { - rules: [ - { - test: new RegExp(entryPath), - use: [ - // Require all Android app components - platform === "android" && { - loader: "nativescript-dev-webpack/android-app-components-loader", - options: { modules: appComponents } - }, - - { - loader: "nativescript-dev-webpack/bundle-config-loader", - options: { - angular: true, - loadCss: !snapshot, // load the application css if in debug mode - } - }, - ].filter(loader => !!loader) - }, - - { test: /\.html$|\.xml$/, use: "raw-loader" }, - - // tns-core-modules reads the app.css and its imports using css-loader - { - test: /[\/|\\]app\.css$/, - use: { - loader: "css-loader", - options: { minimize: false, url: false }, - } - }, - { - test: /[\/|\\]app\.scss$/, - use: [ - { loader: "css-loader", options: { minimize: false, url: false } }, - "sass-loader" - ] - }, - - // Angular components reference css files and their imports using raw-loader - { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" }, - { test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] }, - - // Compile TypeScript files with ahead-of-time compiler. - { - test: /.ts$/, use: [ - "nativescript-dev-webpack/moduleid-compat-loader", - "@ngtools/webpack", - ] - }, - - // Mark files inside `@angular/core` as using SystemJS style dynamic imports. - // Removing this will cause deprecation warnings to appear. - { - test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, - parser: { system: true }, - }, - ], - }, - plugins: [ - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - "global.TNS_WEBPACK": "true", - }), - // Remove all files from the out dir. - new CleanWebpackPlugin([ `${dist}/**/*` ]), - // Copy native app resources to out dir. - new CopyWebpackPlugin([ - { - from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, - to: `${dist}/App_Resources/${appResourcesPlatformDir}`, - context: projectRoot - }, - ]), - // Copy assets to out dir. Add your own globs as needed. - new CopyWebpackPlugin([ - { from: "fonts/**" }, - { from: "**/*.jpg" }, - { from: "**/*.png" }, - ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), - // Generate a bundle starter script and activate it in package.json - new nsWebpack.GenerateBundleStarterPlugin([ - "./vendor", - "./bundle", - ]), - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - - new AngularCompilerPlugin({ - hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]), - entryModule: resolve(appPath, "./app/app.module#AppModule"), - tsConfigPath: join(__dirname, aot ? "tsconfig.aot.json" : "tsconfig.tns.json"), - skipCodeGeneration: !aot, - sourceMap: !!sourceMap, - }), - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - ], - }; - - if (report) { - // Generate report files for bundles content - config.plugins.push(new BundleAnalyzerPlugin({ - analyzerMode: "static", - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, "report", `report.html`), - statsFilename: resolve(projectRoot, "report", `stats.json`), - })); - } - - if (snapshot) { - config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: "vendor", - angular: true, - requireModules: [ - "reflect-metadata", - "@angular/platform-browser", - "@angular/core", - "@angular/common", - "@angular/router", - "nativescript-angular/platform-static", - "nativescript-angular/router", - ], - projectRoot, - webpackConfig: config, - })); - } - - return config; -}; From 4de8182513c4a76aab04f2f9dbf296e4fce427ed Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Mon, 20 Aug 2018 18:27:39 +0300 Subject: [PATCH 4/6] refactor: remove AoT helper files --- .../_ns-files/__sourceDir__/app/app.module.ngfactory.d.ts | 4 ---- src/add-ns/_ns-files/__sourceDir__/main.ns.aot.ts | 7 ------- .../_files/__sourcedir__/app.module.ngfactory.d.ts | 4 ---- src/ng-new/application/_files/__sourcedir__/main.aot.ts | 4 ---- .../_files/__sourcedir__/app/app.module.ngfactory.d.ts | 4 ---- src/ng-new/shared/_files/__sourcedir__/main.ns.aot.ts | 7 ------- 6 files changed, 30 deletions(-) delete mode 100644 src/add-ns/_ns-files/__sourceDir__/app/app.module.ngfactory.d.ts delete mode 100644 src/add-ns/_ns-files/__sourceDir__/main.ns.aot.ts delete mode 100644 src/ng-new/application/_files/__sourcedir__/app.module.ngfactory.d.ts delete mode 100644 src/ng-new/application/_files/__sourcedir__/main.aot.ts delete mode 100644 src/ng-new/shared/_files/__sourcedir__/app/app.module.ngfactory.d.ts delete mode 100644 src/ng-new/shared/_files/__sourcedir__/main.ns.aot.ts diff --git a/src/add-ns/_ns-files/__sourceDir__/app/app.module.ngfactory.d.ts b/src/add-ns/_ns-files/__sourceDir__/app/app.module.ngfactory.d.ts deleted file mode 100644 index 793157d..0000000 --- a/src/add-ns/_ns-files/__sourceDir__/app/app.module.ngfactory.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * A dynamically generated module when compiled with AoT. - */ -export const AppModuleNgFactory: any; \ No newline at end of file diff --git a/src/add-ns/_ns-files/__sourceDir__/main.ns.aot.ts b/src/add-ns/_ns-files/__sourceDir__/main.ns.aot.ts deleted file mode 100644 index 410be6e..0000000 --- a/src/add-ns/_ns-files/__sourceDir__/main.ns.aot.ts +++ /dev/null @@ -1,7 +0,0 @@ -// this import should be first in order to load some required settings (like globals and reflect-metadata) -import { platformNativeScript } from 'nativescript-angular/platform-static'; - -// './app.module.ngfactory' is a dynamically generated module when compiled with AoT. -import { AppModuleNgFactory } from './app/app.module.ngfactory'; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/src/ng-new/application/_files/__sourcedir__/app.module.ngfactory.d.ts b/src/ng-new/application/_files/__sourcedir__/app.module.ngfactory.d.ts deleted file mode 100644 index 793157d..0000000 --- a/src/ng-new/application/_files/__sourcedir__/app.module.ngfactory.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * A dynamically generated module when compiled with AoT. - */ -export const AppModuleNgFactory: any; \ No newline at end of file diff --git a/src/ng-new/application/_files/__sourcedir__/main.aot.ts b/src/ng-new/application/_files/__sourcedir__/main.aot.ts deleted file mode 100644 index ffd369c..0000000 --- a/src/ng-new/application/_files/__sourcedir__/main.aot.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { platformNativeScript } from 'nativescript-angular/platform-static'; -import { AppModuleNgFactory } from './app.module.ngfactory'; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/src/ng-new/shared/_files/__sourcedir__/app/app.module.ngfactory.d.ts b/src/ng-new/shared/_files/__sourcedir__/app/app.module.ngfactory.d.ts deleted file mode 100644 index 793157d..0000000 --- a/src/ng-new/shared/_files/__sourcedir__/app/app.module.ngfactory.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * A dynamically generated module when compiled with AoT. - */ -export const AppModuleNgFactory: any; \ No newline at end of file diff --git a/src/ng-new/shared/_files/__sourcedir__/main.ns.aot.ts b/src/ng-new/shared/_files/__sourcedir__/main.ns.aot.ts deleted file mode 100644 index 410be6e..0000000 --- a/src/ng-new/shared/_files/__sourcedir__/main.ns.aot.ts +++ /dev/null @@ -1,7 +0,0 @@ -// this import should be first in order to load some required settings (like globals and reflect-metadata) -import { platformNativeScript } from 'nativescript-angular/platform-static'; - -// './app.module.ngfactory' is a dynamically generated module when compiled with AoT. -import { AppModuleNgFactory } from './app/app.module.ngfactory'; - -platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory); From 35ac56ed078ebf740a20a84eaf5a90312964fcbc Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Tue, 21 Aug 2018 13:20:15 +0300 Subject: [PATCH 5/6] refactor: clean up shared project source files --- src/add-ns/_ns-files/__sourceDir__/main.ns.ts | 2 +- src/ng-new/application/index_spec.ts | 3 -- .../_files/__sourcedir__/tsconfig.app.json | 15 ++----- src/ng-new/shared/_files/package.json | 2 +- src/ng-new/shared/_files/tsconfig.aot.json | 21 ---------- src/ng-new/shared/_files/tsconfig.esm.json | 7 ---- src/ng-new/shared/_files/tsconfig.json | 41 +++++++++++-------- src/ng-new/shared/_files/tsconfig.tns.json | 17 ++++---- src/ng-new/shared/index_spec.ts | 4 -- 9 files changed, 36 insertions(+), 76 deletions(-) delete mode 100644 src/ng-new/shared/_files/tsconfig.aot.json delete mode 100644 src/ng-new/shared/_files/tsconfig.esm.json diff --git a/src/add-ns/_ns-files/__sourceDir__/main.ns.ts b/src/add-ns/_ns-files/__sourceDir__/main.ns.ts index 5f3edc2..5090102 100644 --- a/src/add-ns/_ns-files/__sourceDir__/main.ns.ts +++ b/src/add-ns/_ns-files/__sourceDir__/main.ns.ts @@ -1,7 +1,7 @@ // this import should be first in order to load some required settings (like globals and reflect-metadata) import { platformNativeScriptDynamic } from 'nativescript-angular/platform'; -import { <%= entryModuleClassName %> } from '<%= entryModuleImportPath %><%= nsext %>'; +import { <%= entryModuleClassName %> } from '<%= entryModuleImportPath %>'; // A traditional NativeScript application starts by initializing global objects, setting up global CSS rules, creating, and navigating to the main page. // Angular applications need to take care of their own initialization: modules, components, directives, routes, DI providers. diff --git a/src/ng-new/application/index_spec.ts b/src/ng-new/application/index_spec.ts index 3f58d9f..0c7accc 100644 --- a/src/ng-new/application/index_spec.ts +++ b/src/ng-new/application/index_spec.ts @@ -28,14 +28,11 @@ describe('Application Schematic', () => { expect(files.indexOf('/foo/.gitignore')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/package.json')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/tsconfig.json')).toBeGreaterThanOrEqual(0); - expect(files.indexOf('/foo/webpack.config.js')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/app/app.css')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/app/package.json')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/app/main.ts')).toBeGreaterThanOrEqual(0); - expect(files.indexOf('/foo/app/main.aot.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/app/app.module.ts')).toBeGreaterThanOrEqual(0); - expect(files.indexOf('/foo/app/app.module.ngfactory.d.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/app/app.component.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/app/home/home.component.ts')).toBeGreaterThanOrEqual(0); diff --git a/src/ng-new/shared/_files/__sourcedir__/tsconfig.app.json b/src/ng-new/shared/_files/__sourcedir__/tsconfig.app.json index cb79b92..4424d16 100644 --- a/src/ng-new/shared/_files/__sourcedir__/tsconfig.app.json +++ b/src/ng-new/shared/_files/__sourcedir__/tsconfig.app.json @@ -1,18 +1,9 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "outDir": "../out-tsc/app", + "outDir": "./out-tsc/app", + "baseUrl": "./", "module": "es2015", "types": [] - }, - "exclude": [ - "<%= sourcedir %>/test.ts", - "**/*.spec.ts", - "**/*.tns.ts", - "**/*.android.ts", - "**/*.ios.ts", - "./main.ns.aot.ts", - "./main.ns.ts", - "./vendor.ts" - ] + } } diff --git a/src/ng-new/shared/_files/package.json b/src/ng-new/shared/_files/package.json index 18f79bf..4949f15 100644 --- a/src/ng-new/shared/_files/package.json +++ b/src/ng-new/shared/_files/package.json @@ -54,6 +54,6 @@ "protractor": "~5.3.0", "ts-node": "~5.0.1", "tslint": "~5.9.1", - "typescript": "2.7.2" + "typescript": "~2.7.2" } } diff --git a/src/ng-new/shared/_files/tsconfig.aot.json b/src/ng-new/shared/_files/tsconfig.aot.json deleted file mode 100644 index 2a7a58f..0000000 --- a/src/ng-new/shared/_files/tsconfig.aot.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "es2015", - "moduleResolution": "node", - "baseUrl": "./", - "paths": { - "*": [ - "./node_modules/tns-core-modules/*", - "./node_modules/*" - ] - } - }, - "exclude": [ - "**/*.ns.ts", - "**/*.tns.ts", - "**/*.android.ts", - "**/*.ios.ts", - "**/*.spec.ts" - ] -} diff --git a/src/ng-new/shared/_files/tsconfig.esm.json b/src/ng-new/shared/_files/tsconfig.esm.json deleted file mode 100644 index 95f2ece..0000000 --- a/src/ng-new/shared/_files/tsconfig.esm.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "es2015", - "moduleResolution": "node" - } -} diff --git a/src/ng-new/shared/_files/tsconfig.json b/src/ng-new/shared/_files/tsconfig.json index 2c4ea5b..b948741 100644 --- a/src/ng-new/shared/_files/tsconfig.json +++ b/src/ng-new/shared/_files/tsconfig.json @@ -1,18 +1,25 @@ { - "compileOnSave": false, - "compilerOptions": { - "outDir": "./dist/out-tsc", - "declaration": false, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "target": "es5", - "typeRoots": [ - "node_modules/@types" - ], - "lib": [ - "es2017", - "dom" - ] - } -} \ No newline at end of file + "compileOnSave": false, + "compilerOptions": { + "outDir": "./dist/out-tsc", + "sourceMap": true, + "declaration": false, + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es5", + "typeRoots": [ + "node_modules/@types" + ], + "lib": [ + "es2017", + "dom" + ] + }, + "exclude": [ + "**/*.tns.ts", + "**/*.android.ts", + "**/*.ios.ts", + "**/*.spec.ts" + ] +} diff --git a/src/ng-new/shared/_files/tsconfig.tns.json b/src/ng-new/shared/_files/tsconfig.tns.json index 1d964a9..b7c67e7 100644 --- a/src/ng-new/shared/_files/tsconfig.tns.json +++ b/src/ng-new/shared/_files/tsconfig.tns.json @@ -5,16 +5,13 @@ "moduleResolution": "node", "baseUrl": "./", "paths": { + "~/*": [ + "src/*" + ], "*": [ - "./node_modules/tns-core-modules/*", - "./node_modules/*" + "./node_modules/tns-core-modules/*", + "./node_modules/*" ] } - }, - "exclude": [ - "**/*.tns.ts", - "**/*.android.ts", - "**/*.ios.ts", - "app/main.aot.ts" - ] -} \ No newline at end of file + } +} diff --git a/src/ng-new/shared/index_spec.ts b/src/ng-new/shared/index_spec.ts index 63d13bd..38d1388 100644 --- a/src/ng-new/shared/index_spec.ts +++ b/src/ng-new/shared/index_spec.ts @@ -26,14 +26,10 @@ describe('Shared Application Schematic', () => { expect(files.indexOf('/foo/.gitignore')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/package.json')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/tsconfig.tns.json')).toBeGreaterThanOrEqual(0); - expect(files.indexOf('/foo/tsconfig.aot.json')).toBeGreaterThanOrEqual(0); - expect(files.indexOf('/foo/webpack.config.js')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/src/package.json')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/src/main.ns.ts')).toBeGreaterThanOrEqual(0); - expect(files.indexOf('/foo/src/main.ns.aot.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/src/app/app.module.ts')).toBeGreaterThanOrEqual(0); - expect(files.indexOf('/foo/src/app/app.module.ngfactory.d.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/src/app/app.component.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/foo/src/app/app.component.html')).toBeGreaterThanOrEqual(0); From 08303e7d978e4dd2941cd5273b7f50e6671c24b4 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Tue, 21 Aug 2018 13:50:41 +0300 Subject: [PATCH 6/6] refactor: update `ng-add` schematic --- src/add-ns/_ns-files/tsconfig.aot.json | 21 --------------------- src/add-ns/_ns-files/tsconfig__nsext__.json | 8 +++++--- src/add-ns/index.ts | 15 ++++++--------- 3 files changed, 11 insertions(+), 33 deletions(-) delete mode 100644 src/add-ns/_ns-files/tsconfig.aot.json diff --git a/src/add-ns/_ns-files/tsconfig.aot.json b/src/add-ns/_ns-files/tsconfig.aot.json deleted file mode 100644 index 546e477..0000000 --- a/src/add-ns/_ns-files/tsconfig.aot.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "es2015", - "moduleResolution": "node", - "baseUrl": "./", - "paths": { - "*": [ - "./node_modules/tns-core-modules/*", - "./node_modules/*" - ] - } - }, - "exclude": [ - "**/*.ns.ts", - "**/*<%= nsext %>.ts", - "**/*.android.ts", - "**/*.ios.ts", - "**/*.spec.ts" - ] -} diff --git a/src/add-ns/_ns-files/tsconfig__nsext__.json b/src/add-ns/_ns-files/tsconfig__nsext__.json index 1e87b3e..dab8ffc 100644 --- a/src/add-ns/_ns-files/tsconfig__nsext__.json +++ b/src/add-ns/_ns-files/tsconfig__nsext__.json @@ -5,6 +5,9 @@ "moduleResolution": "node", "baseUrl": "./", "paths": { + "~/*": [ + "src/*" + ], "*": [ "./node_modules/tns-core-modules/*", "./node_modules/*" @@ -14,7 +17,6 @@ "exclude": [ "**/*<%= nsext %>.ts", "**/*.android.ts", - "**/*.ios.ts", - "app/main.aot.ts" + "**/*.ios.ts" ] -} \ No newline at end of file +} diff --git a/src/add-ns/index.ts b/src/add-ns/index.ts index 2266524..998bfca 100644 --- a/src/add-ns/index.ts +++ b/src/add-ns/index.ts @@ -100,9 +100,7 @@ ${JSON.stringify(angularJson.cli, null, 2)} ${JSON.stringify(angularJson.cli, null, 2)}`); } - angularJson.cli = { - 'defaultCollection' : defaultCollection - } + angularJson.cli = { 'defaultCollection': defaultCollection }; tree.overwrite('angular.json', JSON.stringify(angularJson, null, 2)); } @@ -254,18 +252,17 @@ const addNativeScriptProjectId = (tree: Tree, context: SchematicContext) => { */ const excludeNsFilesFromTsconfig = (tree: Tree, context: SchematicContext) => { context.logger.info('Excluding NativeScript files from web tsconfig'); - const tsConfigPath = projectSettings.tsConfig; - const tsConfig: any = getJsonFile(tree, tsConfigPath); - tsConfig.exclude = tsConfig.exclude || []; const nsExtensions = [ - '**/*.tns.ts', + `**/*${extensions.ns}.ts`, '**/*.android.ts', '**/*.ios.ts', - './main.ns.aot.ts', - './main.ns.ts', ]; + const tsConfigPath = projectSettings.tsConfig; + const tsConfig: any = getJsonFile(tree, tsConfigPath); + + tsConfig.exclude = tsConfig.exclude || []; tsConfig.exclude = [...tsConfig.exclude, ...nsExtensions]; tree.overwrite(tsConfigPath, JSON.stringify(tsConfig, null, 2));