├── .gitignore ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Chris Liechty 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ng-annotate-webpack-plugin 2 | ========================== 3 | 4 | ng-annotate is deprecated. Consider using https://github.com/schmod/babel-plugin-angularjs-annotate instead. 5 | 6 | --- 7 | 8 | WebPack plugin that runs [ng-annotate](https://github.com/olov/ng-annotate) on your bundles 9 | 10 | Based on [ngmin-webpack-plugin](https://github.com/jeffling/ngmin-webpack-plugin) 11 | 12 | # Usage 13 | In webpack.config.js: 14 | ```javascript 15 | var webpack = require('webpack'); 16 | var ngAnnotatePlugin = require('ng-annotate-webpack-plugin'); 17 | 18 | module.exports = { 19 | /// ... rest of config 20 | plugins: [ 21 | new ngAnnotatePlugin() 22 | ] 23 | } 24 | ``` 25 | To modify the default plugin options or to add options for `ng-annotate`: 26 | ```javascript 27 | var webpack = require('webpack'); 28 | var ngAnnotatePlugin = require('ng-annotate-webpack-plugin'); 29 | 30 | module.exports = { 31 | /// ... rest of config 32 | plugins: [ 33 | new ngAnnotatePlugin({ 34 | add: true, 35 | // other ng-annotate options here 36 | }) 37 | ] 38 | } 39 | ``` 40 | 41 | Since version 0.4.0: for performance reasons, chunks where the name starts with `vendors~` are not 42 | annotated. To customize this behavior, set the option `annotateChunk` to a method that returns 43 | `true` if a chunk should be annotated: 44 | 45 | ```javascript 46 | var webpack = require('webpack'); 47 | var ngAnnotatePlugin = require('ng-annotate-webpack-plugin'); 48 | 49 | module.exports = { 50 | /// ... rest of config 51 | plugins: [ 52 | new ngAnnotatePlugin({ 53 | add: true, 54 | annotateChunk: (chunk) => !chunk.name || !chunk.name.startsWith("vendors~"), 55 | // other ng-annotate options here 56 | }) 57 | ] 58 | } 59 | ``` 60 | 61 | If you are looking for a loader instead of a plugin, use [ng-annotate-loader](https://github.com/huston007/ng-annotate-loader) instead 62 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | var ngAnnotate = require('ng-annotate'), 3 | SourceMapSource = require('webpack-core/lib/SourceMapSource'); 4 | 5 | function ngAnnotatePlugin(options) { 6 | this.options = options || { add: true, sourceMap: false }; 7 | } 8 | 9 | ngAnnotatePlugin.prototype.apply = function apply(compiler) { 10 | var options = this.options; 11 | 12 | // Skip vendor chunks by default unless options.annotateChunk is provided 13 | var annotateChunk = options.annotateChunk || function(chunk) { 14 | return !chunk.name || !chunk.name.startsWith("vendors~"); 15 | }; 16 | 17 | compiler.hooks.compilation.tap('NgAnnotateWebpackPlugin', function(compilation) { 18 | compilation.hooks.optimizeChunkAssets.tapAsync('NgAnnotateWebpackPlugin', function(chunks, callback) { 19 | var files = []; 20 | 21 | function getFilesFromChunk(chunk) { 22 | if (annotateChunk(chunk)) { 23 | files = files.concat(chunk.files); 24 | } 25 | } 26 | 27 | function annotateFile(file) { 28 | if (options.sourceMap) { 29 | options.map = { 30 | inFile: file, 31 | sourceRoot: "" 32 | }; 33 | } 34 | var value = ngAnnotate(compilation.assets[file].source(), options); 35 | 36 | var asset = compilation.assets[file]; 37 | 38 | if (options.sourceMap && asset.sourceAndMap) { 39 | var sourceAndMap = asset.sourceAndMap(); 40 | var map = sourceAndMap.map; 41 | var input = sourceAndMap.source; 42 | } else { 43 | map = asset.map(); 44 | } 45 | 46 | if (!value.errors) { 47 | if (options.sourceMap && asset.sourceAndMap) { 48 | compilation.assets[file] = new SourceMapSource(value.src, file, JSON.parse(value.map), input, map); 49 | } 50 | else { 51 | compilation.assets[file] = new SourceMapSource(value.src, file, map); 52 | } 53 | } 54 | } 55 | 56 | chunks.forEach(getFilesFromChunk); 57 | 58 | files = files.concat(compilation.additionalChunkAssets); 59 | 60 | files.forEach(annotateFile); 61 | 62 | callback(); 63 | }); 64 | }); 65 | }; 66 | 67 | module.exports = ngAnnotatePlugin; 68 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-annotate-webpack-plugin", 3 | "version": "0.4.0", 4 | "description": "webpack plugin that runs ng-annotate on your bundles", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/cliechty/ng-annotate-webpack-plugin.git" 12 | }, 13 | "keywords": [ 14 | "webpack", 15 | "ng-annotate", 16 | "angular" 17 | ], 18 | "author": "Chris Liechty", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/cliechty/ng-annotate-webpack-plugin/issues" 22 | }, 23 | "homepage": "https://github.com/cliechty/ng-annotate-webpack-plugin", 24 | "dependencies": { 25 | "ng-annotate": "^1.2.1", 26 | "webpack-core": "^0.6.5" 27 | } 28 | } 29 | --------------------------------------------------------------------------------