12

Suppose I have two dart projects

Project A contains code that uses web component to create bunch of UI widget (similar to https://github.com/kevmoo/widget.dart)

Project B contains my front end code that would reuse the UI widget I created in project A.

If I dont want to publish my project A to pub, is there anyway to link project B to project A without manually copying files from project A into B?

Thanks

nobody
  • 2,709
  • 6
  • 35
  • 37

1 Answers1

14

Take a look at this section in the pub documentation: Path Dependencies:

http://pub.dartlang.org/doc/dependencies.html#path-packages

Suppose project_a had a library file called myprojecta.dart

dependencies:
  project_a:
    path: /Users/me/project_a   <-- root of project a

In your code, you would import project_a using

import 'package:project_a/myprojecta.dart'

Note - if you don't want to publish your project to pub, you can always use git as a dependency rather than path dependency - this lets other people in your team use your projects without relying upon your filesystem layout.

Chris Buckett
  • 13,738
  • 5
  • 39
  • 46
  • 5
    You should also note that you never have to publish your application when you use Pub. Above all other things, Pub is for consuming packages from pub.dartlang.org, git, your filesystem, or even from somewhere else in your package. Check out http://pub.dartlang.org/doc/ for an idea of all the things Pub helps you do. – Juniper Belmont Apr 02 '13 at 21:27
  • 1
    Good clarification. Yes, publishing to pub.dartlang.org is only required if you want to actually make your package public. – Chris Buckett Apr 03 '13 at 07:16
  • You can find [git dependency examples here](https://stackoverflow.com/a/68023976/496176) – quantme Jun 29 '22 at 15:26