const path = require("path"); module.exports = grunt => { grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), clean: { default: ["dist/*", "!dist/.fo76-dumps-ids.db"], }, copy: { css: { files: [{expand: true, cwd: "src/main/", src: "**/*.css", dest: "dist/", flatten: true}] }, db: { files: [{expand: true, cwd: "src/main/", src: "**/.*.db", dest: "dist/", flatten: true}] }, html: { files: [{expand: true, cwd: "src/main/", src: "**/*.html", dest: "dist/", flatten: true}] }, php: { files: [{expand: true, cwd: "src/main/", src: "**/*.php", dest: "dist/", flatten: true}] }, }, focus: { dev: { include: ["css", "html", "js", "php"], }, }, replace: { dev: { src: ["./dist/**/*.html", "./dist/**/*.js"], replacements: [ { from: "%%VERSION_NUMBER%%", to: "<%= pkg.version %>+" + new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "") } ], overwrite: true }, deploy: { src: ["./dist/*.html", "./dist/*.js"], replacements: [ { from: "%%VERSION_NUMBER%%", to: "<%= pkg.version %>" } ], overwrite: true }, }, watch: { css: { files: ["src/main/**/*.css"], tasks: ["copy:css"], }, html: { files: ["src/main/**/*.html"], tasks: ["copy:html"], }, js: { files: ["src/main/**/*.js"], tasks: ["webpack:dev", "replace:dev"], }, php: { files: ["src/main/**/*.php"], tasks: ["copy:php"], }, }, webpack: { options: { entry: "./src/main/js/index.js", module: { rules: [ { test: /\.js$/, exclude: /node_modules/, }, ], }, resolve: { extensions: [".js"], }, output: { filename: "bundle.js", path: path.resolve(__dirname, "dist/"), }, }, dev: { mode: "development", devtool: "inline-source-map", }, deploy: { mode: "production", }, }, }); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-copy"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-focus"); grunt.loadNpmTasks("grunt-text-replace"); grunt.loadNpmTasks("grunt-webpack"); grunt.registerTask("dev", [ // Pre "clean", // Copy files "copy:css", "copy:db", "copy:html", "copy:php", // Compile JS "webpack:dev", "replace:dev", ]); grunt.registerTask("dev:server", ["dev", "focus:dev"]); grunt.registerTask("deploy", [ // Pre "clean", // Copy files "copy:css", "copy:db", "copy:html", "copy:php", // Compile JS "webpack:deploy", "replace:deploy", ]); grunt.registerTask("default", ["dev"]); };