feat(@angular/cli): add ability to build bundle for node - #6913
Conversation
31c8e93 to
160ca2c
Compare
|
|
||
| @Injectable() | ||
| export class MyInjectable { | ||
| constructor(public viewContainer: ViewContainerRef, @Inject(DOCUMENT) public doc) {} |
There was a problem hiding this comment.
VCR is not an ordinary injectable
It can only be injected from a component and it's value is the VCR of the specific instance of the component.
A service/ injectable is not able to inject a VCR
There was a problem hiding this comment.
This is to test the downgrading of a non-annotated Angular class. I think the test needs to happen, I don't care much with which class. Does this test makes your code fail? How so?
There was a problem hiding this comment.
This test is done in the normal webpack tests.
This test makes my tests fail because I am actually executing the application and it fails to bootstrap because the service is not able to find the VCR.
Is it fine to remove it from this set of tests because the functionality is covered in the other webpack tests?
df8d278 to
2602917
Compare
| .then(() => expectFileToMatch('dist/app.main.js', | ||
| /renderModuleFactory \*\/\].*\/\* AppModuleNgFactory \*\/\]/)) | ||
| /renderModuleFactory \*\/\].*\/\* AppModuleNgFactory \*\/\]/)) | ||
| .then(() => exec(normalize('rm'), |
There was a problem hiding this comment.
Considering there's no path, normalize('rm') is a noop.
| "description": "Base url for the application being built." | ||
| }, | ||
| "platform": { | ||
| "type": "string", |
There was a problem hiding this comment.
This should be an enum, not a generic stsring.
eb675f2 to
04d605e
Compare
| if (project.root === path.resolve(outputPath)) { | ||
| throw new SilentError ('Output path MUST not be project root directory!'); | ||
| } | ||
| if (appConfig.platform && appConfig.platform === 'server') { |
There was a problem hiding this comment.
appConfig.platform is redundant here.
| .then(() => _removeDecorators(refactor)) | ||
| .then(() => _refactorBootstrap(plugin, refactor)); | ||
| .then(() => _refactorBootstrap(plugin, refactor)) | ||
| .then(() => _stuff(plugin, refactor)) |
There was a problem hiding this comment.
_stuff? I'm sure you can do better ;)
d6e695d to
ed7f5f0
Compare
| }); | ||
|
|
||
| const dirName = path.normalize(path.dirname(refactor.fileName)); | ||
| let exportStatement = `export const moduleMap = ${JSON.stringify(map)};`; |
There was a problem hiding this comment.
Change this to not use JSON.stringify and instead properly build up the export map without string replacement hacks.
There was a problem hiding this comment.
Also, let's rename the exported symbol to LAZY_MODULE_FACTORY_MAP.
| return { | ||
| loadChildrenString: routeKey, | ||
| path: plugin.lazyRoutes[lazyRouteKey], | ||
| name: routeKey.split('#')[1] |
There was a problem hiding this comment.
Add validation that the loadChildren format is correct.
e127c52 to
a2d4ddb
Compare
| refactor.prependBefore(node, `import * as __lazy_${index}__ from './${relativePath}'`); | ||
| return `"${routeKey}": __lazy_${index}__.${moduleName}`; | ||
| }) | ||
| .join(); |
There was a problem hiding this comment.
Wait, how are these separated. Shouldn't it be joined with a comma or something?
There was a problem hiding this comment.
Never mind, apparently comma is the default for join().
|
|
||
| const modulePath = plugin.lazyRoutes[lazyRouteKey]; | ||
| const relativePath = path.relative(dirName, modulePath).replace(/\\/g, '/'); | ||
| refactor.prependBefore(node, `import * as __lazy_${index}__ from './${relativePath}'`); |
There was a problem hiding this comment.
It's weird for .map to have side effects. Can we move this out to a separate .forEach iteration through the keys?
| refactor.prependBefore(node, `import * as __lazy_${index}__ from './${relativePath}'`); | ||
| return `"${routeKey}": __lazy_${index}__.${moduleName}`; | ||
| }) | ||
| .join(); |
There was a problem hiding this comment.
Never mind, apparently comma is the default for join().
eafa684 to
b6ae689
Compare
b6ae689 to
f089a33
Compare
|
Just confirmed locally that the e2e tests are flakes and everything is green. Cheers. |
|
Was just playing with this and found an issue with a particular export pattern in barrels that is broken: intellix/universal-cli@8ed967d#diff-a44e09a3c12667be300e8cb75d793c5dR1 Worked inside @app/user/index.ts: export * from './user.module';
export * from './user.service';Didn't work inside app/user/index.ts: export { UserModule } from './user.module';
export { UserService } from './user.service';Build error: |
|
@intellix Thank you for testing this feature and for the replication for the issue. I have prepared a fix for this issue but would you do the honors of logging it as an issue in this GitHub repo? Thank you |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This adds the ability to create a commonjs bundle which contains the application module/ngfactory which can be used in node environments
Here's an example of how a project using this feature would look https://github.com/FrozenPandaz/u-cli-app