diff --git a/.eleventy.js b/.eleventy.js index 47a2987..664a0b3 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,5 +1,5 @@ const { DateTime } = require("luxon"); -const fs = require("fs"); +const { promises: fs, readFileSync } = require("fs"); const pluginRss = require("@11ty/eleventy-plugin-rss"); const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); const pluginNavigation = require("@11ty/eleventy-navigation"); @@ -7,7 +7,7 @@ const markdownIt = require("markdown-it"); const markdownItAnchor = require("markdown-it-anchor"); const pluginSass = require("eleventy-plugin-sass"); const htmlmin = require("html-minifier"); - +const { exec } = require("child_process"); module.exports = function(eleventyConfig) { @@ -49,18 +49,8 @@ module.exports = function(eleventyConfig) { return array.slice(0, n); }); - // compress and combine js files - eleventyConfig.addFilter("jsmin", function(code) { - const UglifyJS = require("uglify-js"); - let minified = UglifyJS.minify(code); - if( minified.error ) { - console.log("UglifyJS error: ", minified.error); - return code; - } - return minified.code; - }); - eleventyConfig.addPassthroughCopy("src/**/*.jpg"); + eleventyConfig.addPassthroughCopy("src/**/*.jpeg"); eleventyConfig.addPassthroughCopy("src/**/*.ico"); eleventyConfig.addPassthroughCopy("src/**/*.png"); eleventyConfig.addPassthroughCopy("src/**/*.svg"); @@ -80,12 +70,11 @@ module.exports = function(eleventyConfig) { // minify html eleventyConfig.addTransform("htmlmin", function(content, outputPath) { if( outputPath.endsWith(".html") ) { - let minified = htmlmin.minify(content, { + return htmlmin.minify(content, { useShortDoctype: true, removeComments: true, collapseWhitespace: true }); - return minified; } return content; }); @@ -96,13 +85,14 @@ module.exports = function(eleventyConfig) { port: 5555, callbacks: { ready: function(err, browserSync) { - const content_404 = fs.readFileSync('_site/404/index.html'); + const content_404 = readFileSync('_site/404/index.html'); browserSync.addMiddleware("*", (req, res) => { // Provides the 404 content without redirect. res.write(content_404); res.end(); }); + exec("npm run build:js"); } } }); diff --git a/.eleventyignore b/.eleventyignore index ec64229..24bba27 100644 --- a/.eleventyignore +++ b/.eleventyignore @@ -1,2 +1,3 @@ README.md _11ty/ +tmp/ diff --git a/netlify.toml b/netlify.toml index 0371fd1..91a6f01 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,6 @@ [build] publish = "_site" - command = "DEBUG=* eleventy" + command = "npm run debug" [[redirects]] from = "/*" to = "/404/" diff --git a/package.json b/package.json index a3b6e42..86b9f23 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,11 @@ "version": "2.0.0", "description": "Static generator for company website", "scripts": { - "build": "npx eleventy", + "build": "npx eleventy && npm run build:js", "watch": "npx eleventy --watch", "serve": "npx eleventy --serve", - "debug": "DEBUG=* npx eleventy" + "debug": "DEBUG=* eleventy && npm run build:js", + "build:js": "rollup -c" }, "repository": { "type": "git", @@ -28,6 +29,16 @@ "luxon": "^1.25.0", "markdown-it": "^8.4.2", "markdown-it-anchor": "^5.3.0", + "rollup-plugin-terser": "^7.0.2", "uglify-js": "^3.11.1" + }, + "dependencies": { + "@babel/core": "^7.12.8", + "@babel/preset-env": "^7.12.7", + "@rollup/plugin-commonjs": "^16.0.0", + "@rollup/plugin-node-resolve": "^10.0.0", + "aos": "^2.3.4", + "rollup": "^2.33.3", + "swiper": "^6.3.5" } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..d116949 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,18 @@ +import nodeResolve from "@rollup/plugin-node-resolve"; +import commonjs from "@rollup/plugin-commonjs"; +import { terser } from "rollup-plugin-terser"; + +module.exports = { + input: "src/_js/main.js", + sourceMap: true, + plugins: [ + nodeResolve(), + commonjs() + ], + output: { + file: "_site/main.js", + format: "iife", + sourceMap: true, + plugins: [terser()] + } +}; diff --git a/src/_includes/footer.njk b/src/_includes/footer.njk index d004ee2..8288e30 100644 --- a/src/_includes/footer.njk +++ b/src/_includes/footer.njk @@ -36,8 +36,8 @@