
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
grunt-asset-packager
Advanced tools
Packages javascript and stylesheets similarly to the smart_asset gem.
Packages javascript and stylesheets similarly to the Rails asset pipeline.
This task makes it easy to compile local and production versions of a static site. Rather than putting stylesheet and javascript includes directly in the html file they are put into package files; it is the package files that are referenced from the html file.
For example, a package file named common.js
might contain the following lines:
src/js/ file1.js
src/js/ file2.js
index.html
would then have this tag referencing that package:
<script-package src="common.js" />
When the task is run in DEVELOPMENT mode, the javascript files will be copied to the build directory and the <script-package>
tag replaced by <script>
tags including each file.
When the task is run in PRODUCTION mode, the javascript files will be concatenated and uglified into a single file named common.js
and the <script-package>
tag replaced by a single <script>
tag including that file.
Unprocessed files can also be included at any point using <script-partial>
tags.
This plugin requires Grunt.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-asset-packager --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-asset-packager');
In your project's Gruntfile, add a section named asset_packager
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
asset_packager: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Type: String
For static site projects with a single html file defining all script and style includes. This sets the path to the index file containing package includes.
Type: String
Default value: '.'
For static site projects with a single html file defining all script and style includes. This sets the path to the folder that will contained the final compiled index file and assets.
Type: String
For projects with js includes defined in multiple files. This sets the path to write javascript source files to.
Type: String
For projects with js includes defined in multiple files. This sets the path to write the files containing the <script>
tags. The include files will have the name of the asset package, for example main.js.pkg generates an include file named main.html.
Type: String
Default value: ' '
Allows normalization of filepaths between builds of different modes. In package files, anything after this character will be copied into the build directory.
Eg, if the path in the asset folder is written as: src/js/ module/file.js
The build directory will contain: module/file.js
Type: Object
Default value: { js: 'js', css: 'css' }
Group files in the build directory under these folders, eg: js/module/file.js css/module/file.css
In this example, index and asset files live within the src
folder. These will be compiled to a new folder named build
.
grunt.initConfig({
asset_packager: {
options: {
index: 'src/index.html',
dest: 'build'
},
build: {
files: [
{ src: ['src/asset_packages/**/*.pkg'], expand: true}
]
}
},
})
asset_packager expects a grunt config variable named 'mode' to be set to either 'DEVELOPMENT' or 'PRODUCTION'. Below is an example of how this can be done.
// Allow setting the global config that is read by asset_packager
grunt.registerTask('set_config', 'Set a config property.', function(name, val){
grunt.config.set(name, val);
});
grunt.registerTask('dev', ['set_config:mode:DEVELOPMENT', 'asset_packager']);
grunt.registerTask('prod', ['set_config:mode:PRODUCTION', 'asset_packager']);
The mode must be set, there is no default option.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
(Nothing yet)
Copyright (c) 2013 Peter Hastie. Licensed under the MIT license.
FAQs
Packages javascript and stylesheets similarly to the smart_asset gem.
We found that grunt-asset-packager demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.