V3: Migrate to Vite (#221)
This is version 3 of the boilerplate, which makes significant changes to the build script and local development tooling. It replaces Webpack with Vite, which required some significant changes to how the local development setup works with Google Apps Script. A new dev-server-wrapper.html file is used as the wrapper app in development, which is a standalone html + js file instead of a React app. This reduces the need for a complex build step for the wrapper app. Instead the file is just copied over for each entrypoing and the file location is changed with a "replace" step. Due to the way Vite works, the html templates are changed a bit to support local development. Vite doesn't easily allow completely separate multiple builds, so some Vite plugins and custom plugins are written to support multiple entrypoints (sidebars/dialogs). The externalization for large packages is now handled in the Vite config instead of a plugin, and by manually adding in the script tags into the index.html templates. Additional changes here: - yarn is now used instead of npm as package manager - eslint configs are updated to support vite - GitHub workflows for tests are updated to use yarn and other minor changes such as node versions and OS. - A VS Code launch.json configuration is provided - Dev wrapper setup has been updated (see above description) - ES Modules (import/export) updated throughout - Unneeded packages supporting webpack configurations are removed. Many packages have been upgraded. NPM scripts have been updated to use yarn. - Removed `import React` due to Vite config. - Added script tags to each template since webpack externalization plugin is no longer used - Added <script type="module" src="./index.jsx"></script> to index.html templates to support Vite local development - Changed src/server/sheets.js to .ts typescript as exemplar - Updated tests to support yarn commands, Vite changes, and listening for Vite stdout triggers. - Add Vite-style tsconfig.json - README is updated
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, ChangeEvent, FormEvent } from 'react';
|
||||
import { useState, ChangeEvent, FormEvent } from 'react';
|
||||
import { Form, Button, Col, Row } from 'react-bootstrap';
|
||||
|
||||
interface FormInputProps {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
||||
import { Button, ListGroup } from 'react-bootstrap';
|
||||
import FormInput from './FormInput';
|
||||
|
||||
@@ -3,6 +3,30 @@
|
||||
<head>
|
||||
<base target="_top" />
|
||||
<!-- Add any external scripts and stylesheets here -->
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-transition-group@4.4.2/dist/react-transition-group.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-bootstrap@2.4.0/dist/react-bootstrap.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/@types/react@18.2.66/index.d.ts"
|
||||
></script>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
@@ -18,6 +42,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<section id="index">
|
||||
<script type="module" src="./index.jsx"></script>
|
||||
<!-- bundled js and css will get inlined here during build-->
|
||||
</section>
|
||||
</body>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import SheetEditor from './components/SheetEditor';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, ChangeEvent, FormEvent } from 'react';
|
||||
import { useState, ChangeEvent, FormEvent } from 'react';
|
||||
import { Button, Grid, TextField, Typography } from '@mui/material';
|
||||
|
||||
interface FormInputProps {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Button, Typography } from '@mui/material';
|
||||
|
||||
import FormInput from './FormInput';
|
||||
|
||||
@@ -3,9 +3,30 @@
|
||||
<head>
|
||||
<base target="_top" />
|
||||
<!-- Add any external scripts and stylesheets here -->
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/@mui/material@5.11.11/umd/material-ui.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/@types/react@18.2.66/index.d.ts"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<section id="index">
|
||||
<script type="module" src="./index.jsx"></script>
|
||||
<!-- bundled js and css will get inlined here during build-->
|
||||
</section>
|
||||
</body>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import SheetEditor from './components/SheetEditor';
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useState, ChangeEvent, FormEvent } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const FormInput = ({ submitNewSheet }) => {
|
||||
const FormInput = ({ submitNewSheet }: { submitNewSheet: Function }) => {
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
|
||||
const handleChange = (event) => setInputValue(event.target.value);
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) =>
|
||||
setInputValue(event.target.value);
|
||||
|
||||
const handleSubmit = (event) => {
|
||||
const handleSubmit = (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (inputValue.length === 0) return;
|
||||
|
||||
@@ -18,16 +19,18 @@ const FormInput = ({ submitNewSheet }) => {
|
||||
<form className="flex w-full mx-auto items-center" onSubmit={handleSubmit}>
|
||||
<div className="grow pr-2 py-1">
|
||||
<input
|
||||
className="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-transparent focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 transition-colors duration-200 ease-in-out"
|
||||
onChange={handleChange}
|
||||
value={inputValue}
|
||||
placeholder="New sheet name"
|
||||
className="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-transparent focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 transition-colors duration-200 ease-in-out"
|
||||
onChange={handleChange}
|
||||
value={inputValue}
|
||||
placeholder="New sheet name"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
className="text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded"
|
||||
className="text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded"
|
||||
type="submit"
|
||||
>Add Sheet</button>
|
||||
>
|
||||
Add Sheet
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const SheetButton = ({ sheetDetails, deleteSheet, setActiveSheet }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
||||
import FormInput from './FormInput';
|
||||
import SheetButton from './SheetButton';
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
<head>
|
||||
<base target="_top" />
|
||||
<!-- Add any external scripts and stylesheets here -->
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-transition-group@4.4.2/dist/react-transition-group.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/@types/react@18.2.66/index.d.ts"
|
||||
></script>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Nunito"
|
||||
rel="stylesheet"
|
||||
@@ -10,6 +30,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<section id="index">
|
||||
<script type="module" src="./index.jsx"></script>
|
||||
<!-- bundled js and css will get inlined here during build -->
|
||||
</section>
|
||||
</body>
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import SheetEditor from './components/SheetEditor';
|
||||
import './styles.css';
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const FormInput = ({ submitNewSheet }) => {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const SheetButton = ({ sheetDetails, deleteSheet, setActiveSheet }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
||||
import FormInput from './FormInput';
|
||||
import SheetButton from './SheetButton';
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
<head>
|
||||
<base target="_top" />
|
||||
<!-- Add any external scripts and stylesheets here -->
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-transition-group@4.4.2/dist/react-transition-group.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/@types/react@18.2.66/index.d.ts"
|
||||
></script>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Nunito"
|
||||
rel="stylesheet"
|
||||
@@ -10,6 +30,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<section id="index">
|
||||
<script type="module" src="./index.jsx"></script>
|
||||
<!-- bundled js and css will get inlined here during build -->
|
||||
</section>
|
||||
</body>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import SheetEditor from './components/SheetEditor';
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import React from 'react';
|
||||
|
||||
const About = () => (
|
||||
<div>
|
||||
<p>
|
||||
|
||||
@@ -3,10 +3,18 @@
|
||||
<head>
|
||||
<base target="_top" />
|
||||
<!-- Add any external scripts and stylesheets here -->
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"
|
||||
></script>
|
||||
<script
|
||||
crossorigin
|
||||
src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<section id="index">
|
||||
<!-- bundled js and css will get inlined here during build -->
|
||||
<script type="module" src="./index.jsx"></script>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import About from './components/About';
|
||||
|
||||
@@ -14,18 +14,18 @@ export const getSheetsData = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const addSheet = (sheetTitle) => {
|
||||
export const addSheet = (sheetTitle: string) => {
|
||||
SpreadsheetApp.getActive().insertSheet(sheetTitle);
|
||||
return getSheetsData();
|
||||
};
|
||||
|
||||
export const deleteSheet = (sheetIndex) => {
|
||||
export const deleteSheet = (sheetIndex: number) => {
|
||||
const sheets = getSheets();
|
||||
SpreadsheetApp.getActive().deleteSheet(sheets[sheetIndex]);
|
||||
return getSheetsData();
|
||||
};
|
||||
|
||||
export const setActiveSheet = (sheetName) => {
|
||||
export const setActiveSheet = (sheetName: string) => {
|
||||
SpreadsheetApp.getActive().getSheetByName(sheetName).activate();
|
||||
return getSheetsData();
|
||||
};
|
||||
Reference in New Issue
Block a user