Pergunta

I have a web dir, which contains some css and js files:

├── bootstrap-wysiwyg
│   ├── index.html
│   ├── packages -> ../../packages
│   └── republish.sh
├── css
│   ├── bootstrap-combined.no-icons.min.css
│   ├── packages -> ../../packages
│   ├── prettify.css
│   └── screen.css
├── images
│   └── packages -> ../../packages
├── js
│   ├── bootstrap.min.js
│   ├── packages -> ../../packages
│   ├── prettify.js
│   └── prettify.js.1
├── lib
│   ├── font-awesome-3.2.1
│   └── packages -> ../../packages
└── packages -> ../packages

You can see there are one packages link in each subdir of the web dir. I deleted them once, but it will appear when I run pub install.

I can't understand why pub will create them for me, and is there any way to disable it? I don't want them because when I run build command in my IDEA Dart-plugin, it will reports errors since it can't handle them correctly.

Foi útil?

Solução

When Dart sees an import like:

import 'package:foo/foo.dart';

It translates it to:

import '<url of your entrypoint>/packages/foo/foo.dart';

So, say your app's entrypoint is in:

myapp/web/app/main.dart

If it has a "package:" import, like above, it will remap it to:

import 'myapp/web/app/packages/foo/foo.dart';

That means that for Dart to be able to find foo.dart, there needs to be a packages directory inside app that contains foo/foo.dart. Part of pub's job is to set that up for you.

This is definitely not the nicest part of working with Dart and pub. Spewing symlinks everywhere is gross, but it deals with the limitations that the language places on us. Over time, we're hoping to move away from having to create these symlinks.

More details on this here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top