I am trying to install some js files via bower. My repo has a bower.json with a main property, however the whole repo gets installed to components/, not just the files in the dist/custom/ dir.
Here is what my bower.rc looks like
{
"name": "jquery-m",
"version": "2.0.2mup",
"description": "Meetup custom build of jQuery 2.0, used on mobile",
"main": [ "./dist/custom/" ],
"license": "MIT"
}
Is this the way bower is supposed to work? I thought it was possible just to specify certain files with your main property.
Yes, this is how Bower is meant to work. Bower-installer looks like a more lightweight solution than Grunt to solve the exact requirement you're describing and get just the files you need to be deployed to production.
Yes, that's how Bower works.
It always look for the matching tag on the repo; if cannot find one, it goes with the default branch, and download it.
The unique usage I've seen so far for the main property of a bower.json file is for integration, for example with build tools, like Grunt (there are lots of other bower related tasks, just Google around) and others.
This is a common misconception.
As stated in Bower documentation, the main property is a string/array listing the primary endpoints of your package.
Bower package maintainers (and maybe users, using the overrides property) can use the ignore property, which is an array of paths not needed in production that you want Bower to ignore when installing your package.
Example:
{
"name": "stackoverflow",
"version": "1.0.0",
"ignore": [
"test/**",
".jshintrc"
],
"dependencies": {
"foo": "~1.1"
}
}
Related
I've got two "identical" (same OS, Visual Studio, etc.) machines. One has vcpkg with a number of installed packages ('older' versions), and I'd like an identical copy on the new machine that is integrated with Visual Studio. There seem to be a number of relatively complicated methods of accomplishing this: export/import, manifest versioning and binary caching. But what I'd really like to do is run a command on the new machine like "vcpkg installfrompath " or copy the vcpkg folder to the new machine and run "vcpkg restore". I really feel like this must exist and I'm just not seeing it.
Got answer from MS :) https://github.com/microsoft/vcpkg/issues/23464
Simply copy the vcpkg folder and run "vcpkg integrate install"
I verified that this works. Interestingly, this is the command you use when initially setting up vcpkg, but it didn't click for me, not did I see this answer in any of the similar questions I saw posted.
Use manifest mode. It's really easy and gives you exact control over different versions. Just add a file called "vcpkg.json" to the root folder of your project, activate "manifest" in the vcpkg entry of your Visual Studio project and you are almost done.
This is what a manifest file looks like:
{
"name": "myapp",
"version": "1.66.0",
"dependencies": [
{ "name": "pybind11" },
{ "name": "boost-format" },
{ "name": "boost-preprocessor" },
{ "name": "boost-uuid" },
{
"name": "python3",
"version>=": "3.7.4"
}
],
"builtin-baseline": "03ca9b59af1506a86840e3a3a01a092f3333a29b",
"homepage": "https://some.server.loc",
"supports": "windows"
}
Then simply build with Visual Studio. This will invoke vcpkg and build the exact versions you want.
We have a custom ExtJS CMD package created and used for main application. CMD package uses external js that is already minified/compressed. However on production build for app ExtJS again compresses already compressed file, leading to errors in app wherever those external resources are referenced.
Do we have any flag that turns of compression in package.json for externally included resources?
Well, one answer would be to simply not package the external JS with your app, but to serve it separately. Guessing that's not what you want to do, though...
So, to package the file and not have it be compressed, you edit the app.json. In particular, the production block, where there should be a js entry. Make it look something like this:
"production": {
"js": [
{"path": "app.js", "bundle": true},
{"path": "external_file_that_should_not_be_compressed.js", "compress": false }
],
...
},
I want to use bower add manage my library, my question is along with the js files, it always comes with some extra json or git related files. I don't want to push those files to the client, is there a recommended way rather than extract js filed manually?
Bower allows you define in your bower.json file a list of files it will ignore when installing your package:
ignore
Recommended Type: Array of String
A list of files for Bower to ignore when installing your package.
Note: README (all variants of case, .md, .text) and bower.json will
never be ignored.
The ignore rules follow the same rules specified in the gitignore pattern spec.
For example:
{
"name": "my-project",
"version": "1.0.0",
"main": "path/to/main.css",
"ignore": [
".jshintrc",
"**/*.txt"
],
...
}
Another option is keeping only the files you want to distribute in the Git tags which represents you package versions.
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.
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.
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).
Given that bower support installing items that do not technically exist in the global bower namespace the following problem can arise.
Bower install https://github.com/bitovi/canjs.com/archive/v1.1.6.zip
results in
Components
|- v1.1.6
|--bower.json
|-- (complete installation of all required pieces here).
This can lead to potential confusion and maintenance problems down the road as it is now on the developer to recall that "can.js" lives in v1.1.6. Clearly there are fixes that one can implement (i.e. pointing all items using can.js to this directory) but this doesn't solve the core problem.
bower.json looks like this:
{
"name": "v1.1.6",
"main" : "",
"version": "0.0.0",
"repository": {
"type": "asset",
"url": "https://github.com/bitovi/canjs.com/archive/v1.1.6.zip"
}
}
Is renaming the directory and updating the bower.json enough or is there another resource that needs to be updated as well?
Yes updating bower.json is enough. In the next bower major release (1.0.0), you can name a package when installing. In your case you would so something like this:
bower install canjs=git://github.com/bitovi/canjs.com.git#~1.1.6
You can try out this new feature by installing bower-canary: npm install -g -f bower-canary