【问题标题】:Run distribution code using grunt使用 grunt 运行分发代码
【发布时间】:2015-04-14 10:31:12
【问题描述】:

我是 gruntjs 的新手。我已经安装了咕噜声。也有应用程序。我使用grunt build 缩小了代码。它创建了/dist 目录,其中包含所有文件的缩小版本。

如何使用 grunt 运行此分发代码 (/dist) 进行生产。无法弄清楚。 grunt serve 命令默认取/app 目录

【问题讨论】:

  • grunt serve,取决于您如何实现它(可能是grunt-serve 包?)很可能用于生产,仅在开发期间使用。 /dist 文件夹中生成的文件应该进入生产就绪的 Web 服务器,如 Apache HTTPD、IIS、LightHTTPD 和许多其他服务器。
  • @SergiuParaschiv 好的,现在我明白了,我有点好奇为什么它不适合生产使用? ——
  • 因为没有考虑到效率。其目的是使提供文件变得轻松,并可能在此过程中转换它们(less、sass 等)。在开发过程中,serve 任务消耗多少内存以及它执行多少 I/O 通常并不重要,尤其是在您还使用 livereload 的情况下。这并不意味着没有基于 NodeJS 的快速服务器 - Express 非常好。也请阅读:stackoverflow.com/questions/18345179/…

标签: angularjs gruntjs


【解决方案1】:

使用grunt-contrib-connect (enter link description here) 之类的包。首先安装它:

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

在你的 Gruntfile.js 中

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

// ...
// In your config object
grunt.initConfig({
    // ...
    connect: {
        dist: {
            options: {
                port: 8000,
                base: 'dist',
                keepAlive: true
            }
        }
    }
    // ...
});

然后运行你的 grunt 任务:

$ grunt connect:dist

然后导航到http://localhost:8000(或更改配置中的端口)。

注意:如果您使用手表,请设置keepAlive: false

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多