144 lines
3.5 KiB
JavaScript
144 lines
3.5 KiB
JavaScript
var path = require("path");
|
|
var child_process = require("child_process");
|
|
|
|
var underscore = require("underscore");
|
|
var webpack = require("webpack");
|
|
|
|
var BUILD_DIR = path.resolve(__dirname, "..", "q3stats", "web_app");
|
|
var STATIC_DIR = path.resolve(BUILD_DIR, "static");
|
|
var HTML_DIR = path.resolve(BUILD_DIR, "templates");
|
|
var VERSION = child_process.execSync("git rev-parse HEAD").toString("utf-8").trim();
|
|
|
|
var devWebpackConfig = require("./webpack.config.js");
|
|
var distWebpackConfig = underscore.extend(
|
|
underscore.clone(devWebpackConfig),
|
|
{
|
|
devtool: false,
|
|
output: {
|
|
path: path.resolve(STATIC_DIR, "js"),
|
|
filename: "q3stats-" + VERSION + ".min.js"
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
"backbone": "backbone/backbone-min.js",
|
|
"jquery": "jquery/dist/jquery.min.js",
|
|
"react": "react/dist/react.min.js",
|
|
"react-dom": "react-dom/dist/react-dom.min.js",
|
|
"redux": "redux/dist/redux.min.js",
|
|
"underscore": "underscore/underscore-min.js"
|
|
}
|
|
},
|
|
plugins: [
|
|
new webpack.optimize.UglifyJsPlugin({minimize: true})
|
|
]
|
|
}
|
|
);
|
|
|
|
module.exports = function (grunt) {
|
|
grunt.loadNpmTasks("grunt-contrib-clean");
|
|
grunt.loadNpmTasks("grunt-contrib-copy");
|
|
grunt.loadNpmTasks("grunt-contrib-sass");
|
|
grunt.loadNpmTasks("grunt-contrib-watch");
|
|
grunt.loadNpmTasks("grunt-webpack");
|
|
grunt.loadNpmTasks("gruntify-eslint");
|
|
|
|
grunt.initConfig({
|
|
clean: {
|
|
options: {
|
|
force: true,
|
|
},
|
|
all: [STATIC_DIR]
|
|
},
|
|
copy: {
|
|
assets: {
|
|
files: [
|
|
{
|
|
cwd: "",
|
|
dot: true,
|
|
dest: STATIC_DIR,
|
|
expand: true,
|
|
src: ["./fonts/**/*", "./img/**/*.png"]
|
|
}
|
|
]
|
|
},
|
|
devHtml: {
|
|
files: [
|
|
{
|
|
cwd: "",
|
|
dot: true,
|
|
dest: HTML_DIR,
|
|
expand: true,
|
|
src: ["./index.html", "./error.html"]
|
|
}
|
|
]
|
|
},
|
|
distHtml: {
|
|
cwd: "",
|
|
dot: true,
|
|
dest: HTML_DIR,
|
|
expand: true,
|
|
src: ["./index.html", "./error.html"],
|
|
options: {
|
|
process: function (content, srcPath) {
|
|
return content.replace(
|
|
/q3stats\.(css|js)/g, "q3stats-" + VERSION + ".min.$1"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
eslint: {
|
|
sources: {
|
|
src: ["./src/**/*.js"]
|
|
}
|
|
},
|
|
sass: {
|
|
dev: {
|
|
src: ["./sass/main.scss"],
|
|
dest: path.resolve(STATIC_DIR, "css", "q3stats.css"),
|
|
options: {
|
|
compass: true,
|
|
precision: 10,
|
|
sourcemap: "auto",
|
|
style: "expanded"
|
|
}
|
|
},
|
|
dist: {
|
|
src: ["./sass/main.scss"],
|
|
dest: path.resolve(
|
|
STATIC_DIR, "css", "q3stats-" + VERSION + ".min.css"
|
|
),
|
|
options: {
|
|
compass: true,
|
|
precision: 10,
|
|
sourcemap: "none",
|
|
style: "compressed"
|
|
}
|
|
}
|
|
},
|
|
watch: {
|
|
sass: {
|
|
files: ["./sass/**/*.scss", "./img/**/*.png"],
|
|
tasks: ["sass:dev", "copy:assets"]
|
|
},
|
|
js: {
|
|
files: ["./src/**/*.js", "./index.html", "./error.html"],
|
|
tasks: ["webpack:dev", "copy:devHtml"]
|
|
}
|
|
},
|
|
webpack: {
|
|
dev: devWebpackConfig,
|
|
dist: distWebpackConfig
|
|
}
|
|
});
|
|
|
|
grunt.registerTask("dev", [
|
|
"clean", "webpack:dev", "sass:dev", "copy:assets", "copy:devHtml"
|
|
]);
|
|
|
|
grunt.registerTask("dist", [
|
|
"clean", "eslint", "webpack:dist", "sass:dist", "copy:assets",
|
|
"copy:distHtml"
|
|
]);
|
|
};
|