With the decline of Flash in the web, sometimes it can be hard to find the tools for it in modern platforms, such as Node. That happened with me when I was preparing a Grunt build script for FlashWarp and discovered that there is no Node package for building Flash SWC libraries. And so I made it myself - grunt-compc, a Grunt plugin that can build SWC files with the compc compiler from the Flex SDK. It depends on node-flex-sdk, so you can use it alongside with grunt-mxmlc, grunt-asdoc and other Flash tools for Node out there.

Installing Flash tools

The first thing to do to make your Grunt project Flash-enabled is to install the Flex SDK:

npm install flex-sdk@4.6.0 --save-dev

You can find the complete list of available SDK versions here.

The next thing to do is to install packages that provide wrappers for Flash compilers:

npm install grunt-mxmlc –save-dev
npm install grunt-compc –save-dev

And you are ready to go.

Configuring Grunt

Let’s assume that your Flex project consists of two parts: a library and a Flex app. In this case, your Grunt code for building that application could look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
compc: {
compc: {
src: ['lib/src/**/*.as', 'lib/src/**/*.mxml'],
dest: 'lib/bin/example-lib.swc',
options: {
'source-path': ['lib/src/']
}
}
},

mxmlc: {
options: {
rawConfig: '-library-path+=lib/bin'
},
mxmlc: {
files: {
'app/bin-release/app.swf': ['app/src/**/*.as', 'app/src/**/*.mxml']
}
}
}

You can find the complete example project here.