ng -v
npm uninstall -g @angular/cli npm cache npm cache verify npm i -g @angular/cli@latest
ng -v
yarn
recommend ng set --global packageManager=yarn
ng
use yarn
to install all the necessary project dependencies. ng new my-project cd my-project
my-project
in the folder my-project
and go to this folder.node_modules
folder in the project folder, then my recommendations for installing yarn
staff package manager for ng
were ignored. Or something went wrong. npm install
npm run build
ng
> 1.6 ng g universal universal
universal
is not a slip of the pen. In this case, this is the name for the module. If you like copy-paste mode, then I suggest leaving everything as it is. Then you can always fix it. yarn add @angular/platform-server express @nguniversal/express-engine
npm i @angular/platform-server express @nguniversal/express-engine
server.js
file in the root of our little project. 'use strict'; /* Zone.js */ require('zone.js/dist/zone-node'); const express = require('express'); const ngUniversal = require('@nguniversal/express-engine'); const appServer = require('./dist-server/main.bundle'); /* */ function angularRouter(req, res) { res.render('index', { req, res }); } const app = express(); /* */ app.get('/', angularRouter); /* CLI (index.html, CSS? JS, assets...) */ app.use(express.static(`${__dirname}/dist`)); /* Angular Express */ app.engine('html', ngUniversal.ngExpressEngine({ bootstrap: appServer.AppServerModuleNgFactory })); app.set('view engine', 'html'); app.set('views', 'dist'); /* Direct all routes to index.html, where Angular will take care of routing */ app.get('*', angularRouter); app.post('*', angularRouter); app.listen(3000, () => { console.log(`Listening on http://localhost:3000`); });
package.json
file, add or replace the “build” script "sctipts": { // - . "build": "ng build --prod && ng build --prod --app universal --output-hashing=none" },
npm run build node server.js
Source: https://habr.com/ru/post/344832/
All Articles