将express添加到Gruntfile

时间:2015-07-08 21:28:46

标签: node.js express coffeescript gruntjs yeoman

我想在运行grunt server时添加明确的路线。代码是用咖啡脚本编写的,如果你对咖啡脚本没有知识就可以在没有它的情况下回答,我会重写。我尝试了grunt-expressgrunt-express-server和许多其他人没有成功。这是我的Gruntfile。

"use strict"
LIVERELOAD_PORT = 35728
lrSnippet = require("connect-livereload")(port: LIVERELOAD_PORT)
mountFolder = (connect, dir) ->
    connect.static require("path").resolve(dir)
module.exports = (grunt) ->
    require("load-grunt-tasks") grunt
    require("time-grunt") grunt
    yeomanConfig =
        app: "client"
        dist: "dist"
    try
        yeomanConfig.app = require("./bower.json").appPath or yeomanConfig.app
    grunt.initConfig
        yeoman: yeomanConfig
        watch:
            coffee:
                files: ["<%= yeoman.app %>/scripts/**/*.coffee"]
                tasks: ["coffee:dist"]
            compass:
                files: ["<%= yeoman.app %>/styles/**/*.{scss,sass}"]
                tasks: ["compass:server"]
            livereload:
                options:
                    livereload: LIVERELOAD_PORT
                files: [
                    "<%= yeoman.app %>/views/**/*.html"
                ]
        connect:
            options:
                port: 9000
                hostname: "localhost"
            livereload:
                options:
                    middleware: (connect) ->
                        [lrSnippet, mountFolder(connect, ".tmp"), mountFolder(connect, yeomanConfig.app)]
            test:
                options:
                    middleware: (connect) ->
                        [mountFolder(connect, ".tmp"), mountFolder(connect, "test")]
            dist:
                options:
                    middleware: (connect) ->
                        [mountFolder(connect, yeomanConfig.dist)]
        open:
            server:
                url: "http://localhost:<%= connect.options.port %>"
        clean:
            dist:
                files: [
                    dot: true
                    src: [".tmp", "<%= yeoman.dist %>/*", "!<%= yeoman.dist %>/.git*"]
                ]
            server: ".tmp"
        jshint:
            options:
                jshintrc: ".jshintrc"
            all: ["Gruntfile.js", "<%= yeoman.app %>/scripts/**/*.js"]
        compass:
            options:
                sassDir: "<%= yeoman.app %>/styles"
                cssDir: ".tmp/styles"
                generatedImagesDir: ".tmp/styles/ui/images/"
                imagesDir: "<%= yeoman.app %>/styles/ui/images/"
                javascriptsDir: "<%= yeoman.app %>/scripts"
                fontsDir: "<%= yeoman.app %>/fonts"
                importPath: "<%= yeoman.app %>/bower_components"
                httpImagesPath: "styles/ui/images/"
                httpGeneratedImagesPath: "styles/ui/images/"
                httpFontsPath: "fonts"
                relativeAssets: true
            dist:
                options:
                    debugInfo: false
                    noLineComments: true
            server:
                options:
                    debugInfo: true
            forvalidation:
                options:
                    debugInfo: false
                    noLineComments: false
        coffee:
            server:
                options:
                    sourceMap: true
                    sourceRoot: ""
                files: [
                    expand: true
                    cwd: "<%= yeoman.app %>/scripts"
                    src: "**/*.coffee"
                    dest: ".tmp/scripts"
                    ext: ".js"
                ]
            dist:
                options:
                    sourceMap: false
                    sourceRoot: ""
                files: [
                    expand: true
                    cwd: "<%= yeoman.app %>/scripts"
                    src: "**/*.coffee"
                    dest: ".tmp/scripts"
                    ext: ".js"
                ]
        useminPrepare:
            html: "<%= yeoman.app %>/index.html"
            options:
                dest: "<%= yeoman.dist %>"
                flow:
                    steps:
                        js: ["concat"]
                        css: ["concat"]
                    post: []
        usemin:
            html: ["<%= yeoman.dist %>/**/*.html", "!<%= yeoman.dist %>/bower_components/**"]
            css: ["<%= yeoman.dist %>/styles/**/*.css"]
            options:
                dirs: ["<%= yeoman.dist %>"]
        htmlmin:
            dist:
                options: {}
                files: [
                    expand: true
                    cwd: "<%= yeoman.app %>"
                    src: ["*.html", "views/*.html"]
                    dest: "<%= yeoman.dist %>"
                ]
        copy:
            dist:
                files: [
                    expand: true
                    dot: true
                    cwd: "<%= yeoman.app %>"
                    dest: "<%= yeoman.dist %>"
                    src: [
                        "views/**/*"
                    ]
                ,
                    expand: true
                    cwd: ".tmp"
                    dest: "<%= yeoman.dist %>"
                    src: ["styles/**", "assets/**"]
                ,
                    expand: true
                    cwd: ".tmp/images"
                    dest: "<%= yeoman.dist %>/images"
                    src: ["generated/*"]
                ]
            styles:
                expand: true
                cwd: "<%= yeoman.app %>/styles"
                dest: ".tmp/styles/"
                src: "**/*.css"
        concurrent:
            server: ["coffee:server", "compass:server", "copy:styles"]
            dist: ["coffee:dist", "compass:dist", "copy:styles", "htmlmin"]
        concat:
            options:
                separator: grunt.util.linefeed + ';' + grunt.util.linefeed
            dist:
                src: ["<%= yeoman.dist %>/bower_components/angular/angular.min.js"]
                dest: "<%= yeoman.dist %>/scripts/vendor.js"
        uglify:
            options:
                mangle: false
            dist:
                files:
                    "<%= yeoman.dist %>/scripts/app.js": [".tmp/**/*.js"]
    grunt.registerTask "server", (target) ->
        return grunt.task.run(["build", "open", "connect:dist:keepalive"])  if target is "dist"
        grunt.task.run ["clean:server", "concurrent:server", "connect:livereload", "open", "watch"]
    grunt.registerTask "build", ["clean:dist", "useminPrepare", "concurrent:dist", "copy:dist", "concat", "uglify", "usemin"]
    grunt.registerTask "default", ["jshint", "build"]

0 个答案:

没有答案