Skip to content

Commit

Permalink
v3.0 Migration from Webpack to Vite (#54)
Browse files Browse the repository at this point in the history
* Added preferred engines

* Convert project from Webpack to Vite

* add integrity to script tags

* add html attributes to improve internationalization
  • Loading branch information
melledijkstra authored Nov 7, 2024
1 parent cd26533 commit efa2bb8
Show file tree
Hide file tree
Showing 20 changed files with 1,533 additions and 4,750 deletions.
1 change: 0 additions & 1 deletion .claspignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ node_modules/**
# this is a generated file that will be inlined within the generated HTML
# no need to deploy it
main.js
*.txt
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@ certs/

# storybook
storybook-static/

# webpack bundle analyzer
./report.html
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
20
21 changes: 4 additions & 17 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StorybookConfig } from '@storybook/react-webpack5';
import { StorybookConfig } from '@storybook/react-vite';
import { join, dirname } from 'path';

/**
Expand All @@ -15,25 +15,12 @@ const config: StorybookConfig = {
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/addon-webpack5-compiler-swc')
],
framework: {
name: '@storybook/react-webpack5',
options: { builder: { useSWC: true } }
name: getAbsolutePath('@storybook/react-vite'),
options: {},
},
docs: {
autodocs: 'tag',
},
swc: () => ({
"jsc": {
"transform": {
"react": {
"runtime": "automatic"
}
}
}
}),
webpackFinal: async (config) => {
viteFinal: async (config) => {
if (config?.resolve?.alias) {
// @ts-ignore
config.resolve.alias['../utils/serverFunctions'] = require.resolve(
Expand Down
1 change: 1 addition & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const preview: Preview = {
},
},
decorators: [ServerMockDecorator, DialogDecorator],
tags: ['autodocs'],
};

export default preview;
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

## 3.0.0

- **Breaking Change**: Migration from Webpack to Vite
- Storybook converted to use vite

## 2.0.0

- No history... sorry

## 1.0.0

- Initial release, no history... sorry
4 changes: 0 additions & 4 deletions declarations.d.ts

This file was deleted.

87 changes: 87 additions & 0 deletions dev/dev-server-wrapper.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!--
This is a development server page that serves as a wrapper for Google Apps Script (GAS) client-side development.
It is meant to be run inside a Google Sheets/Docs/Forms dialog window during local development.
It loads the gas-client library (as an external), sets up an iframe that points to a local development
server (such as running with vite), and establishes a communication bridge between the GAS server functions and the local development server.
This allows for local development and testing of client-side code while still being able to interact with
the GAS server-side functions.
Two placeholders are used in this file that will need to be replaced in a build step:
- _ _PORT_ _: The port number of the local development server. (e.g. 3000)
- _ _FILE_NAME_ _: The name of the file being loaded. (e.g. dialog-demo-bootstrap/index.html)
-->
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top" />
<title>Dev Server</title>
<!-- Load gas-client as external. Exposed global variable is GASClient. -->
<script
crossorigin
integrity="sha384-pdoLFZ6Km6ToTanpnj5aokMJPkRi1p9b/NI+KaQ230ufwQHp4aRqQkJbY4rmWc4d"
src="https://unpkg.com/[email protected]/dist/index.js"
></script>
<style>
body,
html {
margin: 0;
width: 100%;
height: 100%;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
// These values need to be replaced during the build process
const PORT = '__PORT__';
const FILE_NAME = '__FILE_NAME__';

const iframe = document.getElementById('iframe');
iframe.src = 'https://localhost:' + PORT + '/' + FILE_NAME;
const { serverFunctions } = new window.GASClient.GASClient({
allowedDevelopmentDomains: (origin) =>
/https:\/\/.*\.googleusercontent\.com$/.test(origin),
});

const handleRequest = (event) => {
const request = event.data;
const { type, functionName, id, args } = request;

if (type !== 'REQUEST') return;

serverFunctions[functionName](...args)
.then((response) => {
iframe.contentWindow.postMessage(
{ type: 'RESPONSE', id, status: 'SUCCESS', response },
'https://localhost:' + PORT
);
})
.catch((err) => {
iframe.contentWindow.postMessage(
{
type: 'RESPONSE',
id,
status: 'ERROR',
response: err,
},
'https://localhost:' + PORT
);
});
};
window.addEventListener('message', handleRequest, false);
});
</script>
</head>
<body>
<div style="width: 100%; height: 100%">
<iframe
title="Development Dialog Loader"
id="iframe"
style="width: 100%; height: 100%; border: 0; position: absolute"
></iframe>
</div>
</body>
</html>
Loading

0 comments on commit efa2bb8

Please sign in to comment.