Skip to content

Commit 6967d54

Browse files
Merge pull request #5 from netlify/basic-support
feat: add basic support for angular universal
2 parents 1f3a720 + dbf8dad commit 6967d54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+40968
-102
lines changed

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ module.exports = {
1616
'node/global-require': 0,
1717
'node/prefer-global/process': 0,
1818
'no-magic-numbers': 0,
19+
'no-negated-condition': 0,
20+
'no-param-reassign': 0,
1921
'no-promise-executor-return': 0,
2022
'no-prototype-builtins': 0,
2123
'no-shadow': 0,
2224
'no-unused-vars': 0,
25+
'no-use-before-define': 0,
2326
'prefer-regex-literals': 0,
2427
'promise/prefer-await-to-callbacks': 0,
28+
'require-await': 0,
29+
'unicorn/consistent-destructuring': 0,
2530
'unicorn/filename-case': 0,
2631
'unicorn/no-array-push-push': 0,
2732
},

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
### Node ###
22

3+
# Demo
4+
/demo/netlify
5+
/demo/serverless.ts
6+
/demo/tsconfig.serverless.json
7+
/demo/_redirects
8+
/demo/node_modules
9+
310
# Logs
411
logs
512
*.log
@@ -141,4 +148,5 @@ Temporary Items
141148

142149
# End of https://www.toptal.com/developers/gitignore/api/osx,node
143150

144-
.netlify
151+
demo/.netlify/functions
152+
demo/.netlify/functions-serve

README.md

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,72 @@
11
![Netlify Build plugin Angular Serverless – Run Angular Universal seamlessly on Netlify](netlify-plugin-angular.png)
22

3-
# Essential Angular Serverless Plugin
3+
# Angular Universal Plugin
44

5-
This build plugin is a utility for supporting Angular Universal on Netlify. This plugin will be installed by running a Netlify-specific Angular schematic, but it can also be installed manually.
5+
This build plugin is a utility for supporting Angular Universal on Netlify.
66

77
## Table of Contents
88

99
- [Installation and Configuration](#installation-and-configuration)
10+
- [CLI Usage](#cli-usage)
11+
- [Caveats](#caveats)
1012

1113
## Installation and Configuration
1214

13-
### Angular Schematic
14-
- TBD
15-
1615
### Manual Installation
1716

18-
1. Create a `netlify.toml` in the root of your project. Your file should include
19-
the plugins section below:
17+
Create a `netlify.toml` in the root of your project. Your file should include the plugins section below:
2018

2119
```toml
22-
TBD
20+
[build]
21+
command = "ng build --configuration production && ng run {projectName}:serverless:production"
22+
publish = "dist/{projectName}/browser"
23+
24+
[[plugins]]
25+
package = "@netlify/plugin-angular-serverless"
2326
```
2427

25-
2. From your project's base directory, add this plugin to `dependencies` in
26-
`package.json`.
28+
If you'd like to install this plugin at a fixed version, install it via your package manager:
2729

2830
```bash
29-
# yarn add --save @netlify/plugin-angular-serverless
30-
npm install --save @netlify/plugin-angular-serverless
31+
npm install @netlify/plugin-angular-universal
32+
# or
33+
yarn add @netlify/plugin-angular-universal
3134
```
3235

33-
Read more about
34-
[file-based plugin installation](https://docs.netlify.com/configure-builds/build-plugins/#file-based-installation)
36+
Read more about [file-based plugin installation](https://docs.netlify.com/configure-builds/build-plugins/#file-based-installation)
3537
in our docs.
38+
39+
## CLI Usage
40+
41+
### Plugin Side Effects
42+
43+
This plugin will make direct changes to your project source when run via the CLI:
44+
45+
1. It will modify your angular.json to add a `serverless` project configuration.
46+
2. It will add `serverless.ts` and `tsconfig.serverless.json` files.
47+
48+
It is up to you whether to commit these changes to your project. If the plugin makes updates to these files or configurations, it will overwrite what you'd previously committed, and you can commit the new updates. Otherwise, you can stash and ignore them.
49+
50+
### Workflow
51+
52+
If you'd like to build and deploy your project using the
53+
[Netlify CLI](https://docs.netlify.com/cli/get-started/), we recommend this
54+
workflow to manage git tracking plugin-generated files:
55+
56+
1. Make sure all your project's files are committed before running a build with
57+
the CLI
58+
2. Run any number of builds and deploys freely (i.e. `netlify build`,
59+
`netlify deploy --build`, `netlify deploy --prod`)
60+
3. Run `git stash --include-unstaged` to easily ignore plugin-generated files
61+
62+
It's important to note that the CLI may mix your project's source code and
63+
plugin-generated files; this is why we recommend committing all project source
64+
files before running CLI builds.
65+
66+
## Caveats
67+
68+
This plugin is currently in beta.
69+
70+
Right now:
71+
- it does not include out of the box monorepo support
72+
- it does not support Angular Universal prerendering

demo/.browserslistrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2+
# For additional information regarding the format and rule options, please see:
3+
# https://github.com/browserslist/browserslist#queries
4+
5+
# For the full list of supported browsers by the Angular framework, please see:
6+
# https://angular.io/guide/browser-support
7+
8+
# You can see what browsers were selected by your queries by running:
9+
# npx browserslist
10+
11+
last 1 Chrome version
12+
last 1 Firefox version
13+
last 2 Edge major versions
14+
last 2 Safari major versions
15+
last 2 iOS major versions
16+
Firefox ESR
17+
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

demo/.netlify/state.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"siteId": "0dae6390-88f8-402c-b054-3cf77541cacf"
3+
}

demo/angular.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$schema":"./node_modules/@angular/cli/lib/config/schema.json","cli":{"analytics":false},"version":1,"newProjectRoot":"projects","projects":{"angular-bfdx":{"projectType":"application","schematics":{},"root":"","sourceRoot":"src","prefix":"app","architect":{"build":{"builder":"@angular-devkit/build-angular:browser","options":{"outputPath":"dist/angular-bfdx/browser","index":"src/index.html","main":"src/main.ts","polyfills":"src/polyfills.ts","tsConfig":"tsconfig.app.json","aot":true,"assets":["src/favicon.ico","src/assets"],"styles":["src/styles.css"],"scripts":[]},"configurations":{"production":{"fileReplacements":[{"replace":"src/environments/environment.ts","with":"src/environments/environment.prod.ts"}],"optimization":true,"outputHashing":"none","sourceMap":false,"namedChunks":false,"extractLicenses":true,"vendorChunk":false,"buildOptimizer":true,"budgets":[{"type":"initial","maximumWarning":"2mb","maximumError":"5mb"},{"type":"anyComponentStyle","maximumWarning":"6kb","maximumError":"10kb"}]}}},"serve":{"builder":"@angular-devkit/build-angular:dev-server","options":{"browserTarget":"angular-bfdx:build"},"configurations":{"production":{"browserTarget":"angular-bfdx:build:production"}}},"extract-i18n":{"builder":"@angular-devkit/build-angular:extract-i18n","options":{"browserTarget":"angular-bfdx:build"}},"test":{"builder":"@angular-devkit/build-angular:karma","options":{"main":"src/test.ts","polyfills":"src/polyfills.ts","tsConfig":"tsconfig.spec.json","karmaConfig":"karma.conf.js","assets":["src/favicon.ico","src/assets"],"styles":["src/styles.css"],"scripts":[]}},"lint":{"builder":"@angular-devkit/build-angular:tslint","options":{"tsConfig":["tsconfig.app.json","tsconfig.spec.json","e2e/tsconfig.json","tsconfig.server.json"],"exclude":["**/node_modules/**"]}},"e2e":{"builder":"@angular-devkit/build-angular:protractor","options":{"protractorConfig":"e2e/protractor.conf.js","devServerTarget":"angular-bfdx:serve"},"configurations":{"production":{"devServerTarget":"angular-bfdx:serve:production"}}},"server":{"builder":"@angular-devkit/build-angular:server","options":{"outputPath":"dist/angular-bfdx/server","main":"server.ts","tsConfig":"tsconfig.server.json"},"configurations":{"production":{"outputHashing":"media","fileReplacements":[{"replace":"src/environments/environment.ts","with":"src/environments/environment.prod.ts"}],"sourceMap":false,"optimization":true}}},"serve-ssr":{"builder":"@nguniversal/builders:ssr-dev-server","options":{"browserTarget":"angular-bfdx:build","serverTarget":"angular-bfdx:server"},"configurations":{"production":{"browserTarget":"angular-bfdx:build:production","serverTarget":"angular-bfdx:server:production"}}},"prerender":{"builder":"@nguniversal/builders:prerender","options":{"browserTarget":"angular-bfdx:build:production","serverTarget":"angular-bfdx:server:production","routes":["/"]},"configurations":{"production":{}}},"serverless":{"builder":"@angular-devkit/build-angular:server","options":{"outputPath":"dist/angular-bfdx/serverless","main":"serverless.ts","tsConfig":"tsconfig.serverless.json"},"configurations":{"production":{"outputHashing":"media","fileReplacements":[{"replace":"src/environments/environment.ts","with":"src/environments/environment.prod.ts"}],"sourceMap":false,"optimization":true}}}}}},"defaultProject":"angular-bfdx"}

demo/karma.conf.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
jasmine: {
17+
// you can add configuration options for Jasmine here
18+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19+
// for example, you can disable the random execution with `random: false`
20+
// or set a specific seed with `seed: 4321`
21+
},
22+
clearContext: false // leave Jasmine Spec Runner output visible in browser
23+
},
24+
jasmineHtmlReporter: {
25+
suppressAll: true // removes the duplicated traces
26+
},
27+
coverageReporter: {
28+
dir: require('path').join(__dirname, './coverage/angular-bfdx'),
29+
subdir: '.',
30+
reporters: [
31+
{ type: 'html' },
32+
{ type: 'text-summary' }
33+
]
34+
},
35+
reporters: ['progress', 'kjhtml'],
36+
port: 9876,
37+
colors: true,
38+
logLevel: config.LOG_INFO,
39+
autoWatch: true,
40+
browsers: ['Chrome'],
41+
singleRun: false,
42+
restartOnFileChange: true
43+
});
44+
};

demo/netlify.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build]
2+
command = "npm run build:sls"
3+
publish = "dist/angular-bfdx/browser"
4+
5+
# TO-DO: remove after cli redirect fix is out https://github.com/netlify/cli/pull/2920
6+
# any additional redirects for the site should come *before* this one
7+
[[redirects]]
8+
from = "/*"
9+
to = "/.netlify/functions/angular-builder"
10+
status = 200
11+
12+
# TO-DO: remove when config-mutating bug is diagnosed by workflow
13+
[functions]
14+
included_files=["dist/angular-bfdx/browser/index.html"]
15+
node_bundler="esbuild"
16+
17+
[[plugins]]
18+
package = "../"

0 commit comments

Comments
 (0)