Yocto - NodeJS minify assets

844 Views Asked by At

I would like to minify the assets of a project running on node js. I don't want to minify directly on the target as the ARM processor we are using has not enough power to minify all the assets in a reasonable time at startup. Instead I would like to launch the minify process on the build host (Yocto). I have searched on the web for any help around this process but I did not.

Ideally I would like to use something like node-minify that I could run in a js file from the build machine in the do_install task of Yocto.

I asked help first on (meta-nodejs/issues/62) but I did not received assistance. Thus I'm now trying here as we are in a rush and I'm really out of idea on how to acheived this.

Here is a basic recipe and my questions :

SRC_URI = "svn://URL_TO_THE_TARGET_PROJECT \
    file://host-minify-asset-script.js"

DEPENDS = "nodejs-native "
RDEPENDS_${PN} = "nodejs "

inherit npm npm-install

do_install() {

    # This build/install dependency for target ?
    oe_runnpm install
    oe_runnpm prune --production

    # Is it the proper way to install node-minify on the host like this ?
    oe_runnpm_native install https://github.com/srod/node-minify/tarball/2.0.2

    # Now, how can I run natively my script (host-minify-asset-script.js) 
    # to minify the assets present in the work folder of the recipe ?
}    

Best regards,

1

There are 1 best solutions below

5
On BEST ANSWER

You could use uglify to minify your node source.

npm install -g uglify # install uglify

rm -rf ./minified # remove existing minified directory if it exists

# minify each .js file in the current directory and place the output in ./minified
find . -name "*.js" | xargs -I % sh -c 'mkdir -p ./minified/$(dirname %); uglify -s % -o ./minified/%'