What's the purpose of gruntjs server task?

前端 未结 3 1238
庸人自扰
庸人自扰 2020-12-07 10:36

I\'m learning how to propel use gruntjs. I found the server task but I can\'t get the point.

Can i use the server task mapping concatenated/minified files to test my

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 10:50

    The server task is now the connect task and it's included in the grunt-contrib-connect package.

    The connect task starts a connect web server.

    Install this plugin with this command:

    npm install grunt-contrib-connect --save-dev
    

    Note: --save-dev includes the package in your devDependencies, see https://npmjs.org/doc/install.html

    Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

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

    Run this task with the grunt connect command.

    Note that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed with the keepalive option, and can be enabled ad-hoc by running the task like grunt connect:targetname:keepalive. targetname is equal to "server" in the code sample below.

    In this example, grunt connect (or more verbosely, grunt connect:server) will start a static web server at http://localhost:9001/, with its base path set to the www-root directory relative to the Gruntfile, and any tasks run afterwards will be able to access it.

    // Project configuration.
    grunt.initConfig({
      connect: {
        server: {
          options: {
            port: 9001,
            base: 'www-root'
          }
        }
      }
    });
    

提交回复
热议问题