[grunt] grunt-ng-annotate 介绍
发布于 5 年前 作者 qjzd 4356 次浏览 来自 码农

git地址

https://github.com/mzgol/grunt-ng-annotate

Getting Started 入门指南

This plugin requires Grunt.

If you haven’t used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you’re familiar with that process, you may install this plugin with this command:

这个插件依赖Grunt
如果你之前还没有接触过Grunt, 务必先阅读Grunt入门指南, 它会解释如何创建一个GruntFile,以及安装使用Grunt插件。一旦你熟悉了这些流程, 你就可以使用以下命令安装插件。
npm install grunt-ng-annotate --save-dev

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

一旦这个插件已经安装,你可以在Gruntfile添加以下一行,来启用这个插件。
grunt.loadNpmTasks('grunt-ng-annotate');

Overview 概览

This project defines the ngAnnotate task. In your project’s Gruntfile, add a section named ngAnnotate to the data object passed into grunt.initConfig().

这个项目声明了任务ngAnnotate, 在你项目的Gruntfile中,添加一个ngAnnotate部分到grunt.initConfig()中。
grunt.initConfig({
    ngAnnotate: {
        options: {
            // Task-specific options go here.
        },
        your_target: {
            // Target-specific file lists and/or options go here.
        },
    },
})

Options 选项

The ngAnnotate task accepts a couple of options:

ngAnnotate任务接受一些参数

add 添加

Tells if ngAnnotate should add annotations.

告诉如果ngAnnotate应该添加注解。

Type: boolean

Default: true

remove

Tells if ngAnnotate should remove annotations.

如果ngAnnotate应该删除注解,告诉之。

Type: boolean

Default: false

Note that both add and remove options can be set to true; in such a case ngAnnotate first removes annotations and then re-adds them (it can be used to check if annotations were provided correctly).

注意,“add”和“remove”选项可以设置为true;在这种情况下“ngAnnotate”第一次删除
注释,然后重新加载它们(它可以用来检查如果能够正确地提供注释)。

regexp

If provided, only strings matched by the regexp are interpreted as module names. You can provide both a regular expression and a string representing one. See README of ng-annotate for further details: https://npmjs.org/package/ng-annotate

如果提供,只解释为正则表达式字符串匹配的模块名称。你可以提供一个正则表达式和一个字符串表示。看到自述ng-annotate详情:https://npmjs.org/package/ng-annotate

Type: regexp

Default: none

singleQuotes

Switches the quote type for strings in the annotations array to single ones; e.g. '$scope' instead of "$scope".

转换注解的引用类型字符串数组转换为单引号, 如'$scope'而不是"$scope"。

Type: boolean

Default: false

separator

Concatenated files will be joined on this string.

将加入这个字符串连接文件。

Type: string

Default: grunt.util.linefeed

If you’re post-processing concatenated JavaScript files with a minifier, you may need to use a semicolon ‘;’ as the separator.

如果你后期处理连接用缩小版的JavaScript文件,您可能需要使用分号“;”作为分隔符。

sourceMap

Enables source map generation.

允许源码映射生成

Type: boolean or string

Default: false

If set to a string, the string points to a file where to save the source map. If set to true, an inline source map will be used.

如果设置为一个字符串,字符串指向一个文件,保存源映射。如果设置为“true”,将使用内联源映射。

ngAnnotateOptions

If ngAnnotate supports a new option that is not directly supported via this Grunt task yet, you can pass it here. These options gets merged with the above specific to ngAnnotate. Options passed here have lower precedence to the direct ones described above.

如果ngAnnotate支持不直接支持通过一个新选项这Grunt的任务,您可以通过这里。这些选项被合并到特定于ngAnnotate上面。这里选择通过优先级较低的直接上面描述的。

Type: object

Default: {}

Usage Examples

grunt.initConfig({
    ngAnnotate: {
        options: {
            singleQuotes: true,
        },
        app1: {
            files: {
                'a.js': ['a.js'],
                'c.js': ['b.js'],
                'f.js': ['d.js', 'e.js'],
            },
        },
        app2: {
            files: [
                {
                    expand: true,
                    src: ['f.js'],
                    ext: '.annotated.js', // Dest filepaths will have this extension.
                    extDot: 'last',       // Extensions in filenames begin after the last dot
                },
            ],
        },
        app3: {
            files: [
                {
                    expand: true,
                    src: ['g.js'],
                    rename: function (dest, src) { return src + '-annotated'; },
                },
            ],
        },
    },
});

grunt.loadNpmTasks('grunt-ng-annotate');

After executing grunt ngAnnotate, you’ll get file a.js annotated and saved under the same name, file b.js annotated and saved as c.js and files d.js and e.js concatenated, annotated and saved as f.js. Annotations will be saved using single quotes.

An annotated version of the f.js file will be saved as f.annotated.js and an annotated version of the g.js file will be saved as g.js-annotated.

回到顶部