107

What is the use of property main file when you run bower init? I have been looking and many people says that it currently has no purpose.

Is that true? Bower's documentation doesn't explain it either.

Darryl Hein
  • 134,677
  • 87
  • 206
  • 257
raulricardo21
  • 2,489
  • 4
  • 19
  • 27
  • 3
    There seems to be others also confused by this. For example the writer of this bower tutorial: http://net.tutsplus.com/tutorials/tools-and-tips/meet-bower-a-package-manager-for-the-web/ – Simon Bengtsson Dec 18 '13 at 15:03
  • It appears that the definition of the `main` property is currently in question and being debated in an open issue on the bower github repo. Look here for the current proposed definitions and the discussion: https://github.com/bower/bower/issues/935 – BenjaminGolder Jun 05 '14 at 19:35

2 Answers2

60

According to the Bower.io documentation

main

Recommended Type: String or Array of String

The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list --json andbower list --paths, so they can be used by build tools.

Preprocessor files like CoffeeScript should be compiled.Do not include minified files.Filenames should not be versioned (Bad: package.1.1.0.js; Good: package.js).

I think it's more for the package management, and build tools like Grunt and Brunch. For example, Bootstrap's bower.json looks like :

{
  "name": "bootstrap",
  "version": "3.0.3",
  "main": [
    "./dist/css/bootstrap.css",
    "./dist/js/bootstrap.js",
    "./dist/fonts/glyphicons-halflings-regular.eot",
    "./dist/fonts/glyphicons-halflings-regular.svg",
    "./dist/fonts/glyphicons-halflings-regular.ttf",
    "./dist/fonts/glyphicons-halflings-regular.woff"
  ],
  "ignore": [
    "**/.*",
    "_config.yml",
    "CNAME",
    "composer.json",
    "CONTRIBUTING.md",
    "docs",
    "js/tests"
  ],
  "dependencies": {
    "jquery": ">= 1.9.0"
  }
}

When I build in Brunch, it pulls these files from my bower_components folder in my public folder.

Bruno A.
  • 1,380
  • 14
  • 13
Kelly J Andrews
  • 5,007
  • 1
  • 17
  • 32
  • What "documentation"? – 0xcaff Apr 10 '14 at 15:37
  • 5
    This doesn't really answer the question. The documentation doesn't clarify the role of "The primary endpoints of your package." You've stated the relevance of main to Brunch, but not how it relates to Bower. – BenjaminGolder Jun 05 '14 at 19:32
  • I think the point I was trying to make, is that the main files are utilized in several build tools in regards to "these are the files my bower package intends to distribute." It's still a tad ambiguous to it's true intent. – Kelly J Andrews Jul 14 '14 at 11:53
  • The anchor of the documentation link is dead. See @Vivian Spencer's answer for an update. – Timothy Gu Nov 16 '14 at 05:30
9

According to Bower's JSON Specification (https://github.com/bower/spec/blob/master/json.md#main), the "main" property is used to list the files primarily used in the project. The files listed are not actually used by Bower in any way, they are apparently there for the purpose of being used by other build tools.

Here is the official specification:

main

Recommended
Type: String or Array of String

The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list --json and bower list --paths, so they can be used by build tools.

  • Preprocessor files like CoffeeScript should be compiled.
  • Do not include minified files.
  • Filenames should not be versioned (Bad: package.1.1.0.js; Good: package.js).
Gianluca Casati
  • 1,935
  • 25
  • 20
Vivian Spencer
  • 117
  • 1
  • 6
  • 1
    Some libraries just won't work without main files listed, wiredep to be the perfect example. – kboom May 20 '15 at 11:44
  • @kboom i might have the issue connected to what you are saying: for example pdf.js-viewer's css file wont copy using main-bower-files, should i put it in main inside bower.json ? If yes, do I actually have to provide the whole path for each file? thanks! – trainoasis Oct 27 '17 at 10:17