Skip to content

Commit

Permalink
feat: build javascript using vite
Browse files Browse the repository at this point in the history
  • Loading branch information
tillywoodfield committed Oct 24, 2024
1 parent 5bce8ba commit 8d9ab3c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Preview } from "@storybook/web-components";

import "../src/js/main.js";
import "../src/scss/main.scss";
import DocsTemplate from "./DocsTemplate.mdx";

Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default [
languageOptions: {
globals: {
...globals.node,
...globals.browser,
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"files": [
"src/scss/**/*.scss",
"dist/css/**/*.css"
"dist/css/**/*.css",
"dist/js/**/*.js"
],
"scripts": {
"start": "storybook dev -p 6006",
Expand Down
33 changes: 17 additions & 16 deletions static/js/header.js → src/js/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

show = () => {
this.wrapper.removeAttribute("hidden");
const reflow = this.wrapper.offsetHeight;
document.addEventListener("keydown", (e) => this.handleKeyDown(e));
this.wrapper.classList.add(this.openClass);
setTimeout(() => {
Expand Down Expand Up @@ -48,20 +47,22 @@
}
}

const iatiMobileNav = new IatiMobileNav(
document.querySelector(".js-iati-mobile-nav"),
"iati-mobile-nav--open",
);
document.addEventListener("DOMContentLoaded", function () {
const iatiMobileNav = new IatiMobileNav(
document.querySelector(".js-iati-mobile-nav"),
"iati-mobile-nav--open",
);

const overlay = document.querySelector(".js-iati-mobile-overlay");
const menuOpenBtn = document.querySelector(".js-iati-menu-toggle-open");
const menuCloseBtn = document.querySelector(".js-iati-menu-toggle-close");
const restoreFocus = () => {
menuOpenBtn.focus();
};
menuOpenBtn.addEventListener("click", iatiMobileNav.show);
menuCloseBtn.addEventListener("click", () =>
iatiMobileNav.hide(restoreFocus),
);
overlay.addEventListener("click", () => iatiMobileNav.hide(restoreFocus));
const overlay = document.querySelector(".js-iati-mobile-overlay");
const menuOpenBtn = document.querySelector(".js-iati-menu-toggle-open");
const menuCloseBtn = document.querySelector(".js-iati-menu-toggle-close");
const restoreFocus = () => {
menuOpenBtn.focus();
};
menuOpenBtn.addEventListener("click", iatiMobileNav.show);
menuCloseBtn.addEventListener("click", () =>
iatiMobileNav.hide(restoreFocus),
);
overlay.addEventListener("click", () => iatiMobileNav.hide(restoreFocus));
});
})();
1 change: 1 addition & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./components/header/header.js";
3 changes: 3 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ export default defineConfig({
build: {
lib: {
entry: {
iati: path.resolve(__dirname, "src/js/main.js"),
css: path.resolve(__dirname, "src/scss/main.scss"),
},
fileName: "iati",
formats: ["es"],
},
rollupOptions: {
output: {
entryFileNames: "js/[name].js",
assetFileNames: (assetInfo) => {
if (assetInfo.name == "style.css") {
return `css/iati.css`;
Expand Down

0 comments on commit 8d9ab3c

Please sign in to comment.