Compile less files and minify js files in node.js

2019-05-22 11:56发布

问题:

I am using the Eb Command Line Interface to deploy a node.js project to AWS Elastic Beanstalk. I am using git for version control. So the command I run to deploy is simply 'git aws.push'. Locally, I am using grunt to compile css files from less files and also minify and cmobine js files.

I don't want to include the *.min.css files or *.min.js files in my git repository but would rather have them recompiled on AWS after deployment. Is there a way to do this? Maybe with a .ebextensions hook or something?

回答1:

I am not familiar with grunt, but I guess what you would have to do is install nodejs and grunt on elastic beanstalk and then running your grunt commands once the container is set up.

In a ebextensions hook such as .ebextensions/grunt.config you could do the following :

commands:
  01-install-nodejs-npm:
    command: "yum install -y --enablerepo=epel nodejs npm"
  02-install-grunt:
    command: "npm install -g grunt-cli"

container_commands:
  01-compilecss-minifyjs:
    command: "grunt build mytask"
    leader_only: true

The commands would make sure nodejs, npm and grunt are installed. The container_commands are executed from within your repository's home directory, so the "source" files for your grunt build should be available from there.

Again - I don't work with grunt and can't tell if this would actually work, but I hope it helps anyway.