Skip to content

Commit

Permalink
Merge pull request #34 from pauljmelia/dev-server
Browse files Browse the repository at this point in the history
Added support for ng serve
  • Loading branch information
joeldenning authored Mar 25, 2019
2 parents 5ca1a3e + 6a3a1d0 commit c7a4544
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ jspm_packages
.node_repl_history

lib
*.tgz
5 changes: 5 additions & 0 deletions builders.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"class": "./lib/builders/browser",
"schema": "./src/builders/browser/schema.json",
"description": "Build an Angular CLI application as a single module"
},
"dev-server" :{
"class": "./lib/builders/dev-server",
"schema": "./src/builders/dev-server/schema.json",
"description": "Serve an Angular ClI application as a single module"
}
}
}
446 changes: 223 additions & 223 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"@angular/compiler": ">=2",
"@angular/compiler-cli": ">=2",
"@angular/core": ">=2",
"rxjs": ">= 6.0.0"
"rxjs": ">= 6.0.0",
"webpack": ">=4.6.0"
},
"devDependencies": {
"@angular-devkit/architect": "^0.13.6",
Expand Down
2 changes: 1 addition & 1 deletion src/builders/browser/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { NormalizedBrowserBuilderSchema } from '@angular-devkit/build-angular';

export interface SingleSpaBuilderSchema extends NormalizedBrowserBuilderSchema {
libraryTarget: string;
libraryTarget: "var" | "assign" | "this" | "window" | "global" | "commonjs" | "commonjs2" | "amd" | "umd" | "jsonp" | undefined;
libraryName: string;
}

Expand Down
17 changes: 16 additions & 1 deletion src/builders/browser/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@
"description": "Library name (maps to WebpackConfig.output.library)"
},
"libraryTarget": {
"type": "string",
"enum": [
"var",
"assign",
"this",
"window",
"self",
"global",
"commonjs",
"commonjs2",
"commonjs-module",
"amd",
"amd-require",
"umd",
"umd2",
"jsonp"
],
"default": "umd",
"description": "How the library will be exposed (maps to WebpackConfig.output.targetLibrary)"
},
Expand Down
29 changes: 29 additions & 0 deletions src/builders/dev-server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DevServerBuilder } from '@angular-devkit/build-angular';
import { BuilderContext } from '@angular-devkit/architect';
import { virtualFs, Path, tags} from '@angular-devkit/core';
import { SingleSpaBuilderSchema } from '../browser/schema';
import { Configuration } from 'webpack';
import * as fs from 'fs';
import { SingleSpaBrowserBuilder } from '../browser';


export class SingleSpaDevServer extends DevServerBuilder {
constructor(context: BuilderContext) {
super(context);
}

buildWebpackConfig(
root: Path,
projectRoot: Path,
host: virtualFs.Host<fs.Stats>,
options: SingleSpaBuilderSchema
): Configuration {
const browserBuilder = new SingleSpaBrowserBuilder(this.context);
const webpackConfig = browserBuilder.buildWebpackConfig(root, projectRoot, host, options);
this.context.logger.info(tags.oneLine `
SINGLE-SPA-ANGULAR: Angular dev server is serving application as a single module`);
return webpackConfig;
}
}

export default SingleSpaDevServer;
189 changes: 189 additions & 0 deletions src/builders/dev-server/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"title": "Dev Server schema for single-spa-angular.",
"description": "Dev Server target options for single-spa-angular.",
"type": "object",
"properties": {
"browserTarget": {
"type": "string",
"description": "Target to serve."
},
"port": {
"type": "number",
"description": "Port to listen on.",
"default": 4200
},
"host": {
"type": "string",
"description": "Host to listen on.",
"default": "localhost"
},
"proxyConfig": {
"type": "string",
"description": "Proxy configuration file."
},
"ssl": {
"type": "boolean",
"description": "Serve using HTTPS.",
"default": false
},
"sslKey": {
"type": "string",
"description": "SSL key to use for serving HTTPS."
},
"sslCert": {
"type": "string",
"description": "SSL certificate to use for serving HTTPS."
},
"open": {
"type": "boolean",
"description": "Opens the url in default browser.",
"default": false,
"alias": "o"
},
"verbose": {
"type": "boolean",
"description": "Adds more details to output logging.",
"default": false
},
"liveReload": {
"type": "boolean",
"description": "Whether to reload the page on change, using live-reload.",
"default": true
},
"publicHost": {
"type": "string",
"description": "Specify the URL that the browser client will use."
},
"servePath": {
"type": "string",
"description": "The pathname where the app will be served."
},
"disableHostCheck": {
"type": "boolean",
"description": "Don't verify connected clients are part of allowed hosts.",
"default": false
},
"hmr": {
"type": "boolean",
"description": "Enable hot module replacement.",
"default": false
},
"watch": {
"type": "boolean",
"description": "Rebuild on change.",
"default": true
},
"hmrWarning": {
"type": "boolean",
"description": "Show a warning when the --hmr option is enabled.",
"default": true
},
"servePathDefaultWarning": {
"type": "boolean",
"description": "Show a warning when deploy-url/base-href use unsupported serve path values.",
"default": true
},
"optimization": {
"description": "Enables optimization of the build output.",
"oneOf": [
{
"type": "object",
"properties": {
"scripts": {
"type": "boolean",
"description": "Enables optimization of the scripts output.",
"default": true
},
"styles": {
"type": "boolean",
"description": "Enables optimization of the styles output.",
"default": true
}
},
"additionalProperties": false
},
{
"type": "boolean"
}
]
},
"aot": {
"type": "boolean",
"description": "Build using Ahead of Time compilation."
},
"sourceMap": {
"description": "Output sourcemaps.",
"default": true,
"oneOf": [
{
"type": "object",
"properties": {
"scripts": {
"type": "boolean",
"description": "Output sourcemaps for all scripts.",
"default": true
},
"styles": {
"type": "boolean",
"description": "Output sourcemaps for all styles.",
"default": true
},
"hidden": {
"type": "boolean",
"description": "Output sourcemaps used for error reporting tools.",
"default": false
},
"vendor": {
"type": "boolean",
"description": "Resolve vendor packages sourcemaps.",
"default": false
}
},
"additionalProperties": false
},
{
"type": "boolean"
}
]
},
"vendorSourceMap": {
"type": "boolean",
"description": "Resolve vendor packages sourcemaps.",
"x-deprecated": true,
"default": false
},
"evalSourceMap": {
"type": "boolean",
"description": "Output in-file eval sourcemaps.",
"x-deprecated": true
},
"vendorChunk": {
"type": "boolean",
"description": "Use a separate bundle containing only vendor libraries."
},
"commonChunk": {
"type": "boolean",
"description": "Use a separate bundle containing code used across multiple bundles."
},
"baseHref": {
"type": "string",
"description": "Base url for the application being built."
},
"deployUrl": {
"type": "string",
"description": "URL where files will be deployed."
},
"progress": {
"type": "boolean",
"description": "Log progress to the console while building."
},
"poll": {
"type": "number",
"description": "Enable and define the file watching poll time period in milliseconds."
}
},
"additionalProperties": false,
"required": [
"browserTarget"
]
}
7 changes: 6 additions & 1 deletion src/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ describe('ng-add', () => {
const angularJSON = JSON.parse(getFileContent(tree, '/angular.json'));
const ssApp = angularJSON.projects['ss-angular-cli-app'];
expect(ssApp.architect['single-spa']).toBeDefined();
expect(ssApp.architect['single-spa'].builder).toBe('single-spa-angular:build');
expect(ssApp.architect['single-spa'].builder).toBe('single-spa-angular:build');
expect(ssApp.architect['single-spa'].options.main).toBe('src/main.single-spa.ts');
expect(ssApp.architect['single-spa-serve']).toBeDefined();
expect(ssApp.architect['single-spa-serve'].builder).toBe('single-spa-angular:dev-server');
expect(ssApp.architect['single-spa-serve'].options.browserTarget).toBe('ss-angular-cli-app:single-spa');

});

test('should add build:single-spa npm script', () => {
const tree = testRunner.runSchematic<NgAddOptions>('ng-add', { routing: true }, defaultAppTree);
const packageJSON = JSON.parse(getFileContent(tree, '/package.json'));
expect(packageJSON.scripts['build:single-spa']).toBeDefined();
expect(packageJSON.scripts['serve:single-spa']).toBeDefined();
});
});
6 changes: 6 additions & 0 deletions src/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export function updateConfiguration(options: NgAddOptions) {
clientProject.architect['single-spa'].builder = 'single-spa-angular:build';
clientProject.architect['single-spa'].options.main = 'src/main.single-spa.ts';

// Copy configuration from the serve architect
clientProject.architect['single-spa-serve'] = clientProject.architect.serve;
clientProject.architect['single-spa-serve'].builder = 'single-spa-angular:dev-server';
clientProject.architect['single-spa-serve'].options.browserTarget = `${project.name}:single-spa`;

host.overwrite(workspacePath, JSON.stringify(workspace, null, 2));

Expand All @@ -93,6 +97,8 @@ export function addNPMScripts(options: NgAddOptions) {

pkg.scripts['build:single-spa'] = `ng run ${options.project}:single-spa`;

pkg.scripts['serve:single-spa'] = `ng run ${options.project}:single-spa-serve`

host.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
};
}
Expand Down

0 comments on commit c7a4544

Please sign in to comment.