-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove extraneous barrel at the app root #3369
Comments
yeh you are just going to confuse the daylights out of some N00bz using typescript barrels with reckless abandon, like u decided to do here. |
I am totally confused whether to use barrels or not with angular2 ? I am trying to use barrels the imports does seem to reference properly but when I run the application it doesn't seem to work as intended unless I import them without using any barrels. Can you please confirm going forward we shouldn't be using any barrels concept? Since even in angular docs I don't see any references to barrels in examples. As per https://github.com/angular/angular-cli/issues/3231 it says Barrels are no longer part of the style guide and was removed. Thanks, |
Barrels have essentially been superseded by |
@bhaskerchari Hi. Barrels help reduce the number of import statements, and can reduce the length of your imports. They do this by consolidating imports into a file (often called a barrel) and then re-exporting them. Thus our code can just import from the barrel, which repoints to the others. Angular does this itself with things like With the advent of An example of this can be found in my event-view repo on github https://github.com/johnpapa/event-view I hope this helps clarify a little |
Just to add: There shouldn't be any functional difference between importing directly or through a barrel. It is purely a stylistic matter where you want to stack your imports. There is nothing wrong in using them, and they should work. |
Hi @johnpapa , Thanks for clarifying that up and it does really makes sense now with the advent of NgModules we have less need for these barrels. While I do see the advantages with the barrels but there seems to be design problems too with usage of it in a way it creates cyclic dependencies between the different exports in a barrel where one has a dependency on another and makes the exports order non trivial otherwise there is more likely chance of breaking the app with an unintended behaviour. Maintaining the correct order in barrels can be tricky sometimes especially when you do have lot of exports and can become a painpoint which is what had troubled me. @wulfsberg Please refer to the below link which I am referring to: Having said all that I am getting rid of barrels from the project that I am going to work on. Thanks, |
BREAKING CHANGES: The app root module and component must now be imported directly. (e.g., use `import { AppModule } from './app/app.module';` instead of `import { AppModule } from './app/';`) Fixes #3369
BREAKING CHANGES: The app root module and component must now be imported directly. (e.g., use `import { AppModule } from './app/app.module';` instead of `import { AppModule } from './app/';`) Fixes angular#3369
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. |
OS?
Mac OSX Sierra
Versions.
angular-cli: 1.0.0-beta.21
node: 6.9.1
os: darwin x64
Repro steps
ng new foo
Details
src/app/foo/index.ts
is created and represents a barrel forapp.module.ts
andapp.component.ts
This is referenced from
src/app/main.ts
Removing the
index.ts
file would only require one change in the app:Before
After
Reason:
The text was updated successfully, but these errors were encountered: