简体   繁体   中英

How can I customize this build script with Node?

I have a unique directory structure that I need help making a build script for.
Here is the link (slightly different) or directory structure:

client
  /extensions
  /sandbox
  /widgets
    /form
      /collections
      /models
      /views
      /styles
        custom.css
      /controllers
  main.coffee
server
  /views
    /layouts
    /errors
  app.coffee
  config.coffee

Couple things I need:

  • Compile coffeescript with a watch task into a server-dist + client-dist
  • Copy over all other files into their nested folders, preferably with a watch task also

Problems:

  • If I just compile coffeescript it just copies over the .coffee files to .js into their nested directories but that leaves behind .css / imgs / etc loaded with require.js. I need a way to bring them as well into the -dist directories
  • Main.coffee in the /client folder is a require.config and can be used with requirejs grunt build tool to optimize things.

Anyways the easiest solution is what I am looking for.

I ended up using grunt - with the following tasks:

  • clean : Clears the server / client build directories
  • watch : Monitors .coffee files and both build directories
  • copy : Copies over client / server files to build directories ignoring .coffee files which are managed by the coffee task
  • coffee : Compiles .coffee files to .js moving them to the build directories

Here is the grunt file in its current iteration:

grunt.initConfig({

 clean: {
   build: ['client-dist', 'server-dist'],
   release: []
 },

 watch: {
   coffee: {
     files: ['client/**/*.coffee', 'server/**/*.coffee'],
     tasks: 'coffee reload'
   },
   reload: {
     files: ['client/**/*.!(coffee)', 'server/**/*.!(coffee)'],
     tasks: 'copy reload'
   }
 },

 copy: {
   client: {
     files: {
       "client-dist/": "client/**/*.!(coffee)"
     },
     options: {
       basePath: "client"
     }
   },
   server: {
     files: {
       "server-dist/": "server/**/*.!(coffee)"
     },
     options: {
       basePath: "server"
     }
   }
 },

 coffee: {
   compile: {
     files: {
       'server-dist/*.js': 'server/**/*.coffee',
       'client-dist/*.js': 'client/**/*.coffee'
       }
     }
 }

});

grunt.loadNpmTasks('grunt-contrib');
grunt.loadNpmTasks('grunt-reload');

grunt.registerTask('default', '');
grunt.registerTask('build', 'clean:build copy coffee watch');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM