forked from jmdobry/angular-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
158 lines (153 loc) · 5.2 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* angular-cache
* http://jmdobry.github.io/angular-cache/
*
* Copyright (c) 2013-2015 Jason Dobry <http://jmdobry.github.io/angular-cache/>
* Licensed under the MIT license. <https://github.com/jmdobry/angular-cache/blob/master/LICENSE>
*/
module.exports = function (grunt) {
'use strict';
'use strict';
require('jit-grunt')(grunt, {
coveralls: 'grunt-karma-coveralls'
});
require('time-grunt')(grunt);
var webpack = require('webpack');
var pkg = grunt.file.readJSON('package.json');
var banner = 'angular-cache\n' +
'@version ' + pkg.version + ' - Homepage <http://jmdobry.github.io/angular-cache/>\n' +
'@author Jason Dobry <[email protected]>\n' +
'@copyright (c) 2013-2015 Jason Dobry \n' +
'@license MIT <https://github.com/jmdobry/angular-cache/blob/master/LICENSE>\n' +
'\n' +
'@overview angular-cache is a very useful replacement for Angular\'s $cacheFactory.';
// Project configuration.
grunt.initConfig({
pkg: pkg,
clean: {
dist: ['dist/'],
coverage: ['coverage/']
},
watch: {
files: ['src/**/*.js'],
tasks: ['build']
},
uglify: {
main: {
options: {
report: 'min',
sourceMap: true,
sourceMapName: 'dist/angular-cache.min.map',
banner: '/*!\n' +
'* angular-cache\n' +
'* @version <%= pkg.version %> - Homepage <http://jmdobry.github.io/angular-cache/>\n' +
'* @author Jason Dobry <[email protected]>\n' +
'* @copyright (c) 2013-2015 Jason Dobry <http://www.pseudobry.com>\n' +
'* @license MIT <https://github.com/jmdobry/angular-cache/blob/master/LICENSE>\n' +
'*\n' +
'* @overview angular-cache is a very useful replacement for Angular\'s $cacheFactory.\n' +
'*/\n'
},
files: {
'dist/angular-cache.min.js': ['dist/angular-cache.js']
}
}
},
webpack: {
dist: {
entry: './src/index.js',
output: {
filename: './dist/angular-cache.js',
libraryTarget: 'umd',
library: 'angularCacheModuleName'
},
externals: {
'angular': 'angular'
},
module: {
loaders: [
{ test: /(src)(.+)\.js$/, exclude: /node_modules/, loader: 'babel-loader?blacklist=useStrict' }
],
preLoaders: [
{
test: /(src)(.+)\.js$|(test)(.+)\.js$/, // include .js files
exclude: /node_modules/, // exclude any and all files in the node_modules folder
loader: "jshint-loader?failOnHint=true"
}
]
},
plugins: [
{
apply: function (compiler) {
compiler.plugin('compilation', function (compilation) {
compilation.plugin('optimize-chunk-assets', function (chunks, callback) {
chunks.forEach(function (chunk) {
if (chunk.initial) {
chunk.files.forEach(function (file) {
compilation.assets[file]._source.children[0].children[0]._value = compilation.assets[file]._source.children[0].children[0]._value.replace('define(["angular"], factory)', 'define("angular-cache", ["angular"], factory)');
compilation.assets[file]._source.children[0].children[1].children[5].children[11].children[1]._source._source._source._value = compilation.assets[file]._source.children[0].children[1].children[5].children[11].children[1]._source._source._source._value.replace('define([], factory)', 'define("cachefactory", [], factory)');
});
}
});
callback();
});
});
}
},
new webpack.BannerPlugin(banner)
]
}
},
karma: {
options: {
configFile: './karma.conf.js'
},
dist: {},
dev: {
browsers: ['Chrome'],
autoWatch: true,
singleRun: false
},
min: {
browsers: ['Chrome', 'Firefox', 'PhantomJS'],
options: {
files: [
'bower_components/angular-1.2.25/angular.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-mocks-1.2.25/angular-mocks.js',
'dist/angular-cache.min.js',
'./karma.start.js',
'test/**/*.js'
]
}
},
c9: {
browsers: ['PhantomJS'],
options: {
files: [
'bower_components/angular-1.2.25/angular.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-mocks-1.2.25/angular-mocks.js',
'dist/angular-cache.min.js',
'./karma.start.js',
'test/**/*.js'
]
}
}
},
coveralls: {
options: {
coverage_dir: 'coverage'
}
}
});
grunt.registerTask('test', ['build', 'karma:dist', 'karma:min']);
grunt.registerTask('test_c9', ['build', 'karma:c9']);
grunt.registerTask('build', [
'clean',
'webpack',
'uglify'
]);
grunt.registerTask('default', ['build']);
grunt.registerTask('go', ['build', 'watch']);
};