/
Gruntfile.js
140 lines (129 loc) · 3.55 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
"use strict";
var _ = require("lodash");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
// Optional S3 credentials if using the deploy task
var S3_CONFIG_FILE = "./s3.config.json";
module.exports = function(grunt) {
var s3Config = grunt.file.exists(S3_CONFIG_FILE) ?
grunt.file.readJSON(S3_CONFIG_FILE) : {};
var config = {
clean: ["./build", "./static"],
concurrent: {
dev: ["nodemon:dev", "webpack:dev"],
options: {
logConcurrentOutput: true
}
},
execute: {
static: {
options: {
cwd: "./static"
},
src: ["./app/static.js"]
}
},
copy: {
static: {
files: [{
expand: true,
cwd: "app/assets/",
src: ["**/*"],
dest: "static/"
}, {
expand: true,
cwd: "build/",
src: "client.css*",
dest: "static/"
}]
}
},
nodemon: {
dev: {
script: "./app/server.js",
options: {
ignore: ["./build/**"],
ext: "js,jsx"
}
}
},
webpack: {
dev: {
resolve: {
extensions: ["", ".js", ".jsx"]
},
entry: "./app/client.js",
output: {
path: "./build",
filename: "client.js"
},
module: {
loaders: [
{test: /\.css$/, loader: "style!css"},
// Use "css-loader?minimize!less-loader" for minification
{test: /\.less$/, loader: ExtractTextPlugin.extract("style-loader",
"css-loader!less-loader")},
{test: /\.jsx$/, loader: "jsx-loader"}
]
},
plugins: [new ExtractTextPlugin("client.css")],
stats: {
colors: true
},
devtool: "source-map",
watch: true,
keepalive: true
}
},
uglify: {
options: {
},
static: {
files: {
"static/client.js": ["build/client.js"]
}
}
},
s3: {
options: {
accessKeyId: s3Config.key,
secretAccessKey: s3Config.secret,
bucket: s3Config.bucket,
region: s3Config.region || "us-west-2",
access: "public-read",
// important for pages without .html extension
mimeDefault: "text/html"
},
deploy: {
cwd: "static/",
src: "**"
}
},
eslint: {
target: ["Gruntfile.js", "app/**/*.js", "app/**/*.jsx"]
}
};
// Copy the dev webpack configuration but don't watch
config.webpack.static = _.clone(config.webpack.dev);
config.webpack.static.watch = false;
config.webpack.static.keepalive = false;
grunt.initConfig(config);
grunt.loadNpmTasks("grunt-concurrent");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-nodemon");
grunt.loadNpmTasks("grunt-webpack");
grunt.loadNpmTasks("grunt-execute");
grunt.loadNpmTasks("grunt-aws");
grunt.loadNpmTasks("grunt-npm-install");
grunt.loadNpmTasks("grunt-eslint");
// Run the node server and watch for changes
grunt.registerTask("default", ["clean", "npm-install", "concurrent:dev"]);
// Build the static site
grunt.registerTask("static", ["clean", "npm-install", "webpack:static",
"copy:static", "uglify:static", "execute:static"]);
// Build and deploy the static site
grunt.registerTask("deploy", ["static", "s3:deploy"]);
// For testing, just execute the static script
grunt.registerTask("static-only", ["execute:static"]);
};