简体   繁体   English

如何在grunt中提供angularapp的开发版本?

[英]How to serve dev version of angularapp in grunt?

I am trying to serve my angular app with grunt and express. 我正在努力为自己的棱角分明的应用程序提供服务。 Currently the serve task looks like this: 目前,服务任务如下所示:

module.exports = function(grunt) {
    grunt.registerTask('serve', function(target) {

        // Default task
        grunt.task.run([
            'clean',
            // init
            //'concurrent:init',
            // compile html, styles, and scripts
            //'concurrent:compile',

            // 'uglify',
            // 'Karma',
            'express:server',
            'open:browser',
            'watch'
        ]);

    });
};

I just want to serve the angular app without any copying, minification etc. How can I do this? 我只想提供有角度的应用程序,而无需任何复制,缩小等操作。我该怎么做?

A simplest way 最简单的方法

I suggest that you use to use Browserify which is one of the simplest way to serve a JS app via Grunt. 我建议您使用Browserify ,这是通过Grunt服务JS应用程序的最简单方法之一。 Here is an example that supposes your JS application is in an src directory with an index.html at its root : 这是一个示例,假设您的JS应用程序位于src目录中,其根目录为index.html

grunfile.js grunfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    browserSync: {
      bsFiles: {
        src: './src/**/*'
      },
      options: {
        server: './src'
      }
    }
  });

  grunt.loadNpmTasks('grunt-browser-sync');

  grunt.registerTask('default', ['browserSync']);
};

You obviously need to install grunt-browser-sync before ( npm i -D grunt-browser-sync ). 显然,您需要先安装grunt-browser-syncnpm i -D grunt-browser-sync )。


With Express 与快递

If you still wish to use express because that's you'll do in production, I suggest you the grunt-express plugin , there is a complete example app using Angular, Express and Grunt here . 如果您仍然希望使用express,因为那是您将在生产中使用的,我建议您使用grunt-express插件 ,这里有一个使用Angular,Express和Grunt的完整示例应用程序。 It's 3 years old but is still working for an actual Angular + Express application. 它已有3年历史,但仍在实际的Angular + Express应用程序中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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