npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-resourcesbinder

v1.0.19

Published

Embed Bower dependencies to your source code.

Downloads

5

Readme

ResourcesBinder

Bind bower or local dependencies to your source code.It can manage binary resources and text attachments (css,javascript,...).It permits to extends bower json for handling submodules. Bottom you can see a example:

  "resources": {
  "mp3":"mp3/*",
  "font":"font/*"
  },
  "modules":{
   "linkPreviewInterceptor":{
   "main":["js/linkPreviewInterceptor.js"],
   "dependencies":{},
   "resources":{}
   }
   }

Getting Started

Install the module with npm:

$ npm install --save grunt-resourcesbinder

Install your bower dependencies (if you haven't already):

$ bower install --save jquery

Insert placeholders in your code where your dependencies will be injected:

<html>
<head>
  <!-- @bind:css linked separated uglified 
       jquery

  -->

</head>
<body>
  <!-- @bind:js linked separated uglified 
       jquery

  -->
</body>
</html>

The complete syntax is

@binder:[<filetype>] <linked|inline>  <aggregated|separated>  [minified|uglified]

The options mean: linked: it replace the link if the corrispondent dependency using the link replacement, inline: it replace directly the all sources mentioned using source replament, aggregated: it aggregate all dependencies, separated : it handles each dependency separately. In the following lines of this block you must insert all the top dependencies (one for every line) with this syntax:


<package_name><modules><search> <nodeps> <nounique>

where modules is optional and has this syntax :

<( <module1> , <module2> , ...)>

where search is optional and has this syntax :

<[<op> "<[filter]>" ]>

where op comparator is :

	== : equals
	!= : not equals
	=^ : starts with
	!^ : not starts with
	=$ : ends with
	!$ : not ends with
	=? : contains 
	!? : not contains
	=~ : match the filter
	!~ : not match the filter

where

  • nodeps is optional and force to not inject the dependencies
  • nounique is optional and permits to repeat the same package in the template.

The optional parameters search and nodeps might be used just if necessary , for example where a external bower package contains different versions in the same package or optional dependencies.

The sub dependencies of the package are automatically injected if 'nodeps' parameter is set. The filter is optional and permits to filter the resources of that package.

Set the the right options for your project :

development : it adds dev-dependencies , forces the setting of  every block as 'linked  separated'
localDependencies: you can add dependencies not deployed in bower system , but just locally in your project,
templates:{target:<path where to place the final html or frontend templates(like tpl,velocity,freemarker,...)>,sources:<array of html or frontend templates files>},

attachments:{
<file extension>: {replacement:{link:<text to replace with {{file}} injection> ,inline:<text to replace with {{source}} injection>},target:<final directory where to place the resources>},
.......
}.

The default setting is :

{
separator: grunt.util.linefeed,
development: false, 
localDependencies:{},
packageHandler:undefined,// handler for fix eventually errors in external bower packages.
minifyHandlers:// internal handlers can be overriden
js:minifyJS,
css:minifyCSS
},
development:false,// if true the block will be forced to bindind in mapped way , disabling also the minification.
exclude:[],  
templates:{target:'target/',sources:[]},
attachments:{
js: {replacement:{link:'<script src="/js/{{file}}"></script>',inline:'<script>{{source}}</script>'},target:'js/'},
css:{replacement:{link:'<link rel="stylesheet" href="/css/{{file}}" />',inline:'<style><{{source}}</style>'},target:'css/'}
},
resources:{

}


}

Let bind work its magic:

<html>
<head>
 <link href="/css/jquery.css">

</head>
<body>

  <script src="/js/jquery.js"></script>

</body>
</html>

Build Chain Integration

Grunt

See grunt-resourcesbinder.

Bower Overrides

To override a property, or lack of, in one of your dependency's bower.json file, you may specify an overrides object in your own bower.json.

Maven

You can integrate this plugin with maven using frontend-maven-plugin. A example of configuration is :

		<plugin>
						<groupId>com.github.eirslett</groupId>
						<artifactId>frontend-maven-plugin</artifactId>
						<version>0.0.23</version>
						<executions>
							<execution>
								<id>npm install</id>
								<goals>
									<goal>npm</goal>
								</goals>
								<configuration>
									<arguments>install</arguments>
								</configuration>
							</execution>
							<execution>
								<id>bower install</id>
								<goals>
									<goal>bower</goal>
								</goals>
								<configuration>
									<arguments>install</arguments>
								</configuration>
							</execution>
							<execution>
								<id>grunt build</id>
								<goals>
									<goal>grunt</goal>
								</goals>
								<configuration>
									<arguments>--no-color</arguments>
									<arguments>--project=${project.artifactId}</arguments>
									<arguments>--dev</arguments>
								</configuration>
							</execution>
						</executions>
					</plugin>

using this Gruntfile.js example:

module.exports = function(grunt) {
var project=(grunt.option( "project" )==undefined)?'':grunt.option( "project" );
grunt.initConfig({
// Before generating any new files, remove any previously-created files.

resourcesbinder: {
default_options: {
templates:{target:'target/'+project+'/WEB-INF/ftl/',sources:['src/main/ftl/**/*.ftl']},
development:grunt.option( "dev" )!==undefined,
attachments:{
js: {replacement:{link:'<script src="<@utils.url\'/js/{{file}}\'/>"></script>',inline:'<script>{{source}}</script>'},target:'target/'+project+'/WEB-INF/js/'},
css:{replacement:{link:'<link rel="stylesheet" href="<@utils.url\'/css/{{file}}\'/>" rel="stylesheet" media="screen" />',inline:'<style><{{source}}</style>'},target:'target/'+project+'/WEB-INF/css/'}
},
resources:{img:{target:"img/",global:false}
}



}
});
	grunt.loadNpmTasks('grunt-resourcesbinder');
	// Default task(s).
	grunt.registerTask('default', ['resourcesbinder' ]);

};

Contributing

This package is used personally, but it might be extended with new features.

License

Copyright (c) 2015 Lorenzetto Cristian. Licensed under the MIT license.

To do

There is no way for importing optional sub-module in a dependency. Unfortunatelly bower don't support extended syntax included in the round parenthesis like this plugin so for skipping the problem we can add a json new property like optionals:["<namedep/namesubmodule>",...]

Bitdeli Badge