grunt-crx
is a Grunt task used to package Chrome Extensions.
Chrome extensions can either be:
- public: zip files are uploaded on the Chrome Web Store);
- private: crx files are signed with a private key and self-hosted.
Install this grunt plugin next to your project's Gruntfile.js with the following command:
npm install --save-dev grunt-crx
Then add this line to your project's Gruntfile.js
:
grunt.loadNpmTasks('grunt-crx');
This task is a multi task, meaning that grunt will automatically iterate over all crx
targets if a target is not specified.
There will be as many extension packaged as there are targets.
src
(mandatory): ;dest
(string, mandatory): location of a folder where thecrx
file will be available;zipDest
(string): Optional location of a folder to write thezip
archive (unsigned extension package) will be available;options
(object) – options that are directly provided to theChromeExtension
object;baseURL
(string): folder URL where package files will be self hosted (see Autoupdating in Chrome Extension docs);maxBuffer
(Number): amount of bytes available to package the extension (see child_process#exec);privateKey
(string): location of the.pem
file used to encrypt your extension.
privateKey
:key.pem
— which means the task will look forward its file next to thegrunt.js
one;filename
:<%= pkg.name %>-<%= manifest.version %>.crx
– which means it will automagically use yourpackage.json
name andmanifest.json
version to build the filename. Will be ignored ifdest
property contains a file name.zipFilename
:<%= pkg.name %>-<%= manifest.version %>.zip
– which means it will automagically use yourpackage.json
name andmanifest.json
version to build the filename. Will be ignored ifzipDest
property contains a file name.
grunt.initConfig({
crx: {
myPublicPackage: {
"src": "src/**/*",
"dest": "dist/crx/",
}
}
});
This example demonstrates how you can tweak your builds upon your own source architecture.
grunt.initConfig({
crx: {
myHostedPackage: {
"src": [
"src-beta/**/*",
"!.{git,svn}"
],
"dest": "dist/crx-beta/src/my-extension.crx",
"options": {
"baseURL": "http://my.app.net/files/",
"privateKey": "~/.ssh/chrome-apps.pem",
"maxBuffer": 3000 * 1024 //build extension with a weight up to 3MB
}
}
}
});
This example demonstrates how to build separate channels of packages within a same repository location.
Pretty handy to use a Git workflow and pre-release code before deploying it in production.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
manifest: grunt.file.readJSON('src/manifest.json'),
crx: {
staging: {
"src": [
"src/**/*",
"!.{git,svn}",
"!*.pem"
]
"dest": "dist/staging/src/<%= pkg.name %>-<%= manifest.version %>-dev.crx",
"options": {
"baseURL": "http://my.app.intranet/files/",
"filename": "",
"privateKey": "dist/key.pem",
"maxBuffer": 3000 * 1024 //build extension with a weight up to 3MB
}
},
production: {
"src": [
"src/**/*",
"!.{git,svn}",
"!*.pem",
"!dev/**"
],
"dest": "dist/production/src/<%= pkg.name %>-<%= manifest.version %>-dev.crx",
"zipDest": "dist/production/src/<%= pkg.name %>-<%= manifest.version %>-dev.zip",
"options": {
"baseURL": "http://my.app.net/files/",
"maxBuffer": 3000 * 1024 //build extension with a weight up to 3MB
}
}
}
});
It is strongly recommended to store your privates keys outside the source folder of your extensions.
Otherwise we will laught at you.
In lieu of a formal styleguide, take care to maintain the existing coding style.
If you don't add unit tests, someone will take care of that before shipping the module to NPM. Take any contribution as an opportunity to learn.
- Jed Schmidt for the useful crx module
- Grunt authors for this great toolbox
- you, contributor, user or anyone providing a feedback
The MIT License (MIT)
Copyright © 2014 Thomas Parisot, and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.