-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): add ability to build bundle for node and export l…
…azy route map
- Loading branch information
1 parent
7d8f54a
commit 6f23636
Showing
20 changed files
with
317 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { WebpackConfigOptions } from '../webpack-config'; | ||
|
||
/** | ||
* Returns a partial specific to creating a bundle for node | ||
* @param _wco Options which are include the build options and app config | ||
*/ | ||
export const getServerConfig = function (_wco: WebpackConfigOptions) { | ||
return { | ||
target: 'node', | ||
output: { | ||
libraryTarget: 'commonjs' | ||
}, | ||
externals: [ | ||
/^@angular/, | ||
function (_: any, request: any, callback: (error?: any, result?: any) => void) { | ||
// Absolute & Relative paths are not externals | ||
if (request.match(/^\.{0,2}\//)) { | ||
return callback(); | ||
} | ||
|
||
try { | ||
// Attempt to resolve the module via Node | ||
const e = require.resolve(request); | ||
if (/node_modules/.test(e)) { | ||
// It's a node_module | ||
callback(null, request); | ||
} else { | ||
// It's a system thing (.ie util, fs...) | ||
callback(); | ||
} | ||
} catch (e) { | ||
// Node couldn't find it, so it must be user-aliased | ||
callback(); | ||
} | ||
} | ||
] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { AppModule } from './app.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fs = require('fs'); | ||
const { AppModuleNgFactory } = require('./dist/app.main'); | ||
const { renderModuleFactory } = require('@angular/platform-server'); | ||
|
||
require('zone.js/dist/zone-node'); | ||
|
||
renderModuleFactory(AppModuleNgFactory, { | ||
url: '/', | ||
document: '<app-root></app-root>' | ||
}).then(html => { | ||
fs.writeFileSync('dist/index.html', html); | ||
}) |
Oops, something went wrong.