3

Right now to create an extension with Google Chrome Extensions page we select a directory that contains created extension and it generates .crx file.

The problem is that it contains all files from this directory - for example, all docs, asset drafts, etc.

Is it possible to create some blacklist to ignore specified files like *.psd, *.pdf, docs/* ... ?

hsz
  • 148,279
  • 62
  • 259
  • 315

3 Answers3

3

The Chromium team decided not to implement a manifest (or similar mechanism) for including only the desired files in a .CRX.

The recommended workflow is to have a build step that outputs only the needed files in a dist directory, and to create the CRX from that directory. This is common practice for JavaScript libraries.

Community
  • 1
  • 1
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
0

My solution

I have created a .crxignore custom ignore file, like this:

.*
Makefile
*.md
bin

It is made for zip command! It is different than .gitignore. You can't add comments eg! See documentation: https://linux.die.net/man/1/zip , look for --exclude word.

Now you can create a zip without ignred files:

$ zip -qr -9 -X .out/out.zip . -x@.crxignore
#                              ^^^^^^^^^^^^^ using ignore file

After that I can convert zip to crx file with this go script: https://github.com/mmadfox/go-crx3 You have to build it with go build -o out/crx3 crx3/main.go command (you may get missing mod errors, but there will be the commands what you have to run). --> you can move your out/crx3 to where you want. Eg: [project]/bin/crx3.

I haven't tried, maybe chrome command also can convert zip to crx.

You have to generate a private key:

$ bin/crx3 keygen .out/key.pem

Final Makefile

build:
    rm -f .out/out.zip
    zip -qr -9 -X .out/out.zip . -x@.crxignore
    bin/crx3 pack .out/out.zip -p .out/key.pem -o .out/out.crx

Build process:

$ make build
# --> build the .out/out.crx file
-1

Try the command line program "zip", which could be found in cygwin if you're on windows, or is likely present on OSX, and easy to install if you're using linux.

zip package.zip -r * -x package.sh -x *.git* -x "*.*~" -x "*.pdf" docs/* "*.psd"
kzahel
  • 2,765
  • 1
  • 22
  • 31
  • Or you could instead give the list of files you *do* want to include: `zip -r packaged.zip src/*.js src/manifest.json img/*.png img/*.jpg`. However, it seems that the question is really about creating `.crx` files which are kind of like zip files but not quite. It seems that you have to use `chrome://extensions` to do that or `\chrome.exe --enable-apps --pack- extension=`. Either way don't let you pick which files you want and which you don't. @hsz, you'd need to write your own script and move files around. – Timothée Boucher Aug 30 '13 at 21:19
  • [.CRX files are special, signed, ZIP archives](https://developer.chrome.com/extensions/crx), containing the author's public key and the extension signature. Simply zipping up some files won't create that kind of a ZIP archive. – Dan Dascalescu Sep 01 '15 at 01:21