Skip to content

Commit 545c5a8

Browse files
committed
build process refactoring: compressed and uncompressed sources
1 parent 0391f87 commit 545c5a8

File tree

6 files changed

+95
-77
lines changed

6 files changed

+95
-77
lines changed

Gruntfile.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
// Build configurations.
21
module.exports = function (grunt) {
32
grunt.loadNpmTasks('grunt-karma');
43
grunt.loadNpmTasks('grunt-contrib-connect');
54
grunt.loadNpmTasks('grunt-contrib-watch');
65
grunt.loadNpmTasks('grunt-contrib-jshint');
76
grunt.loadNpmTasks('grunt-contrib-copy');
7+
grunt.loadNpmTasks('grunt-contrib-clean');
88
grunt.loadNpmTasks('grunt-webpack');
99

10+
var webpackSettings = require('./webpack.config.js');
11+
1012
grunt.initConfig({
1113
connect: {
1214
app: {
@@ -30,36 +32,34 @@ module.exports = function (grunt) {
3032
}
3133
},
3234
karma: {
33-
dev: {
34-
options: {
35-
autoWatch: true,
36-
colors: true,
37-
configFile: './test/karma.conf.js',
38-
keepalive: true,
39-
port: 8082,
40-
runnerPort: 9100
41-
}
35+
options: {
36+
configFile: './test/karma.conf.js',
37+
runnerPort: 9100
4238
},
43-
prod: {
39+
default: {},
40+
compressed: {
4441
options: {
45-
colors: true,
46-
configFile: './test/karma.conf.js',
47-
runnerPort: 9100,
42+
files: require('./test/karma.conf.files.js').compressedFiles,
43+
port: 9876,
44+
autoWatch: false,
45+
keepalive: false,
4846
singleRun: true
4947
}
5048
}
5149
},
5250
webpack: {
53-
options: require("./webpack.config.js").config,
54-
prod: {
55-
cache: false,
56-
plugins: require("./webpack.config.js").prodPlugins
57-
},
58-
dev: {
59-
cache: false,
60-
plugins: require("./webpack.config.js").devPlugins
51+
options: webpackSettings.config,
52+
default: {},
53+
compressed: {
54+
plugins: webpackSettings.compressedPlugins,
55+
output: {
56+
filename: '[name].min.js'
57+
}
6158
}
6259
},
60+
clean: {
61+
temp: ['temp']
62+
},
6363
copy: {
6464
sources: {
6565
files: [
@@ -69,6 +69,9 @@ module.exports = function (grunt) {
6969
jqLiteExtrasFake: {
7070
files: [
7171
{expand: true, src: ['ui-scroll-jqlite.js'], cwd: 'src', dest: 'dist/'},
72+
{expand: true, src: ['ui-scroll-jqlite.js'], cwd: 'src', dest: 'dist/', rename: function(dest, src) {
73+
return dest + src.replace(/\.js$/, ".min.js");
74+
}}
7275
]
7376
}
7477
},
@@ -109,11 +112,6 @@ module.exports = function (grunt) {
109112
}
110113
});
111114

112-
/**
113-
* Starts a web server
114-
* Enter the following command at the command line to execute this task:
115-
* grunt server
116-
*/
117115
grunt.registerTask('server', [
118116
'connect',
119117
'watch'
@@ -122,26 +120,30 @@ module.exports = function (grunt) {
122120
grunt.registerTask('default', ['server']);
123121

124122
grunt.registerTask('test', [
125-
'webpack:dev',
126-
'karma:dev'
123+
'clean:temp',
124+
'webpack:default',
125+
'karma:default'
127126
]);
128127

129128
grunt.registerTask('buildWatcher', [
130129
'jshint:sources',
131-
'webpack:dev'
130+
'clean:temp',
131+
'webpack:default'
132132
]);
133133

134134
grunt.registerTask('build', [
135135
'jshint:tests',
136136
'jshint:sources',
137-
'webpack:prod',
138-
'karma:prod',
137+
'clean:temp',
138+
'webpack:compressed',
139+
'karma:compressed',
140+
'webpack:default',
139141
'copy:sources',
140142
'copy:jqLiteExtrasFake'
141143
]);
142144

143145
grunt.registerTask('travis', [
144-
'webpack:prod',
145-
'karma:prod'
146+
'webpack:compressed',
147+
'karma:compressed'
146148
]);
147149
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"clean-webpack-plugin": "^0.1.15",
2929
"express": "^4.14.0",
3030
"grunt": "^1.0.1",
31+
"grunt-contrib-clean": "^1.0.0",
3132
"grunt-contrib-connect": "^1.0.2",
3233
"grunt-contrib-copy": "^1.0.0",
3334
"grunt-contrib-jshint": "^1.1.0",

src/ui-scroll-jqlite.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
/* Will be removed soon... */
2-
angular.module('ui.scroll.jqlite', []);
1+
/*!
2+
* angular-ui-scroll
3+
* https://github.com/angular-ui/ui-scroll.git
4+
* This module is deprecated since 1.6.0 and will be removed in further versions!
5+
* License: MIT
6+
*/
7+
(function () {
8+
'use strict';
9+
10+
angular.module('ui.scroll.jqlite', []);
11+
12+
}());

test/karma.conf.files.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var files = [
2+
'http://code.jquery.com/jquery-1.9.1.js',
3+
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js',
4+
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-mocks.js',
5+
'test.css',
6+
'datasources.js',
7+
'scaffolding.js',
8+
'**/*Spec.js',
9+
{
10+
pattern: '../temp/*.js.map',
11+
included: false
12+
}
13+
];
14+
15+
module.exports.defaultFiles = files.concat([
16+
'../temp/ui-scroll.js',
17+
'../temp/ui-scroll-grid.js'
18+
]);
19+
20+
module.exports.compressedFiles = files.concat([
21+
'../temp/ui-scroll.min.js',
22+
'../temp/ui-scroll-grid.min.js'
23+
]);

test/karma.conf.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,8 @@ module.exports = function (config) {
1313

1414

1515
// list of files / patterns to load in the browser
16-
files: [
17-
'http://code.jquery.com/jquery-1.9.1.js',
18-
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js',
19-
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-mocks.js',
20-
'test.css',
21-
'../temp/ui-scroll.js',
22-
'../temp/ui-scroll-grid.js',
23-
'datasources.js',
24-
'scaffolding.js',
25-
'**/*Spec.js',
26-
{
27-
pattern: '../temp/*.js.map',
28-
included: false
29-
}
30-
],
16+
files: require('./karma.conf.files.js').defaultFiles,
17+
3118

3219
// list of files to exclude
3320
exclude: [],
@@ -39,7 +26,7 @@ module.exports = function (config) {
3926

4027

4128
// web server port
42-
port: 9876,
29+
port: 8082,
4330

4431

4532
// enable / disable colors in the output (reporters and logs)
@@ -55,6 +42,9 @@ module.exports = function (config) {
5542
autoWatch: true,
5643

5744

45+
keepalive: true,
46+
47+
5848
// Start these browsers, currently available:
5949
// - Chrome
6050
// - ChromeCanary

webpack.config.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
var path = require('path');
22
var webpack = require('webpack');
33

4+
var packageJSON = require('./package.json');
5+
6+
var getBanner = function (compressed) {
7+
return packageJSON.name + (compressed ? ' (compressed)' : ' (uncompressed)') + '\n' +
8+
packageJSON.homepage + '\n' +
9+
'Version: ' + packageJSON.version + ' -- ' + (new Date()).toISOString() + '\n' +
10+
'License: ' + packageJSON.license;
11+
};
12+
413
module.exports.config = {
514
entry: {
615
'ui-scroll': './src/ui-scroll.js',
@@ -10,6 +19,7 @@ module.exports.config = {
1019
path: path.join(__dirname, 'temp'),
1120
filename: '[name].js'
1221
},
22+
cache: false,
1323
devtool: 'source-map',
1424
module: {
1525
loaders: [
@@ -22,31 +32,13 @@ module.exports.config = {
2232
}
2333
}
2434
]
25-
}
35+
},
36+
plugins: [
37+
new webpack.BannerPlugin(getBanner(false))
38+
]
2639
};
2740

28-
/**** plugins ****/
29-
30-
var packageJSON = require('./package.json');
31-
var CleanWebpackPlugin = require('clean-webpack-plugin');
32-
33-
var banner =
34-
packageJSON.name + '\n' +
35-
packageJSON.homepage + '\n' +
36-
'Version: ' + packageJSON.version + ' -- ' + (new Date()).toISOString() + '\n' +
37-
'License: ' + packageJSON.license;
38-
39-
var plugins = [
40-
new CleanWebpackPlugin(['temp'], {
41-
root: process.cwd(),
42-
verbose: true,
43-
dry: false,
44-
})
45-
];
46-
47-
module.exports.devPlugins = plugins.concat([]);
48-
49-
module.exports.prodPlugins = plugins.concat([
41+
module.exports.compressedPlugins = [
5042
new webpack.optimize.UglifyJsPlugin({
5143
compress: {
5244
warnings: true,
@@ -55,5 +47,5 @@ module.exports.prodPlugins = plugins.concat([
5547
comments: false,
5648
},
5749
}),
58-
new webpack.BannerPlugin(banner)
59-
]);
50+
new webpack.BannerPlugin(getBanner(true))
51+
];

0 commit comments

Comments
 (0)