Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1778 migrate from webpack to vite #1822

Merged
merged 27 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0e9e465
feat: install vite
aqandrew Jun 21, 2024
964ed88
refactor: rename all JSX files to .jsx
aqandrew Jun 21, 2024
f011d1c
feat: add Vite config + link index.jsx in index.html
aqandrew Jun 21, 2024
e18c6ff
refactor: rename index.js files to index.jsx
aqandrew Jun 21, 2024
18e57fd
feat: add import aliases to Vite config
aqandrew Jun 21, 2024
61fd551
refactor: rename env vars to be Vite-compatible
aqandrew Jun 21, 2024
2286d61
fix: removeListeners was not defined
aqandrew Jun 21, 2024
359d22f
fix: page title
aqandrew Jun 21, 2024
f690a8a
fix: install vite and @vite/plugin-react
aqandrew Aug 23, 2024
80eec18
refactor: replace process.env wiht import.meta.env
aqandrew Aug 24, 2024
a2fa475
refactor: remove old HMR code from index.jsx
aqandrew Aug 24, 2024
67c85b1
chore: expose Mapbox API token in deployment workflow
aqandrew Aug 28, 2024
64f2d05
chore: remove webpack comment
aqandrew Aug 28, 2024
9b593e3
feat: readd favicon
aqandrew Sep 4, 2024
db8dc1c
feat: add meta tags in react-helmet
aqandrew Sep 4, 2024
36b3062
chore: remove references to webpack
aqandrew Sep 10, 2024
bebb76c
style: rm semicolon
aqandrew Sep 10, 2024
59c2cf7
chore: rm bundle.js and duckdb dist files from /public
aqandrew Sep 10, 2024
bf7dcd2
Merge branch 'main' into 1778-migrate-from-webpack-to-vite
aqandrew Sep 10, 2024
d56e426
docs: update localhost port
aqandrew Sep 20, 2024
26737be
chore: prefix all client-side env vars with VITE_, including in .exam…
aqandrew Sep 26, 2024
b1621c7
chore: use longhand for npm install in setup script
aqandrew Sep 26, 2024
0486bd4
docs: remove extra install step from quick start + add subheadings
aqandrew Sep 26, 2024
f101db3
chore: update checkEnv.js to rename env vars for Vite if necessary
aqandrew Sep 26, 2024
26599df
feat: show alert if Mapbox token lacks `VITE_` prefix
aqandrew Sep 26, 2024
e25aa13
fix: silence Vite CJS warning by using ESM format for JS imports
aqandrew Oct 3, 2024
3f14b6f
chore: set base directory to /311-data/
aqandrew Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.test.js*
**/v1/*
**/dist/*
webpack.*.js
**/node_modules/
**/public/*
**/Temp/*
Expand Down
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
'import/extensions': ['.js', '.jsx'],
'import/resolver': {
node: {},
webpack: 'webpack.config.js',
},
},
plugins: ['react', 'react-hooks'],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Setup environment
run: |
echo "MAPBOX_TOKEN=${{ secrets.MAPBOX_TOKEN }}" > .env
echo "VITE_MAPBOX_TOKEN=${{ secrets.VITE_MAPBOX_TOKEN }}" > .env
echo "SOCRATA_API_URL=${{ secrets.SOCRATA_API_URL }}" >> .env
echo "SOCRATA_TOKEN=${{ secrets.SOCRATA_TOKEN }}" >> .env
echo "CONTENTFUL_SPACE=${{ secrets.CONTENTFUL_SPACE }}" >> .env
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ __snapshots__
tags/
Temp/
*-new.*
webpack-stats.json
*.old
*\ copy.*
stats.json
Expand Down
25 changes: 25 additions & 0 deletions App.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
import React, { useEffect } from 'react';
import PropTypes from 'proptypes';
import { HashRouter } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import { connect } from 'react-redux';
import { getMetadataRequest } from '@reducers/metadata';

import Header from '@components/Header';
import Footer from '@components/Footer';
import AppRoutes from './Routes';

const TITLE = '311-Data Neighborhood Engagement Tool';
const DESCRIPTION =
'Hack for LA’s 311-Data Team has partnered with the Los Angeles Department of Neighborhood Empowerment and LA Neighborhood Councils to create 311 data dashboards to provide all City of LA neighborhoods with actionable information at the local level.';
const URL = 'https://www.311-data.org/';
const SOCIAL_IMAGE = '/social-media-card-image.png';

function App({ getMetadata }) {
useEffect(() => {
getMetadata();
});

return (
<HashRouter>
<Helmet>
<title>{TITLE}</title>
<link rel="icon" href="/favicon.png" />
<meta name="description" content={DESCRIPTION} />

<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:url" content={URL} />
<meta name="twitter:title" content={TITLE} />
<meta name="twitter:image" content={SOCIAL_IMAGE} />
<meta name="twitter:description" content={DESCRIPTION} />

<meta name="og:type" content="website" />
<meta name="og:url" content={URL} />
<meta name="og:title" content={TITLE} />
<meta name="og:image" content={SOCIAL_IMAGE} />
<meta name="og:description" content={DESCRIPTION} />
</Helmet>

<Header />
<AppRoutes />
<Footer />
Expand Down
2 changes: 1 addition & 1 deletion components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Map extends React.Component {

componentDidMount() {
this.isSubscribed = true;
mapboxgl.accessToken = process.env.MAPBOX_TOKEN;
mapboxgl.accessToken = import.meta.env.VITE_MAPBOX_TOKEN;

const map = new mapboxgl.Map({
container: this.mapContainer,
Expand Down
4 changes: 2 additions & 2 deletions components/Map/controls/MapSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MapSearch extends React.Component {
const { map } = this.props;

this.geocoder = new MapboxGeocoder({
accessToken: process.env.MAPBOX_TOKEN,
accessToken: import.meta.env.VITE_MAPBOX_TOKEN,
flyTo: false,
marker: false,
minLength: 1,
Expand Down Expand Up @@ -136,7 +136,7 @@ class MapSearch extends React.Component {
componentWillUnmount() {
// Free memory and remove all event listeners
const geocoderElement = document.getElementById('geocoder')
removeListeners(geocoderElement, settings.map.eventName.reset)
this.removeListeners(geocoderElement, settings.map.eventName.reset)
}

setTab = tab => {
Expand Down
File renamed without changes.
13 changes: 9 additions & 4 deletions components/db/DbProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import * as duckdb from '@duckdb/duckdb-wasm';
import duckdb_wasm from '@duckdb/duckdb-wasm/dist/duckdb-mvp.wasm?url';
import mvp_worker from '@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js?url';
import duckdb_wasm_next from '@duckdb/duckdb-wasm/dist/duckdb-eh.wasm?url';
import eh_worker from '@duckdb/duckdb-wasm/dist/duckdb-browser-eh.worker.js?url';
import Worker from 'web-worker';
import DbContext from '@db/DbContext';
import moment from 'moment';
Expand Down Expand Up @@ -35,14 +39,15 @@ function DbProvider({ children, startDate }) {
try {
console.log('Loading db...');

// https://github.com/duckdb-wasm-examples/duckdbwasm-vitebrowser
const DUCKDB_CONFIG = await duckdb.selectBundle({
mvp: {
mainModule: './duckdb.wasm',
mainWorker: './duckdb-browser.worker.js',
mainModule: duckdb_wasm,
mainWorker: mvp_worker,
},
eh: {
mainModule: './duckdb-eh.wasm',
mainWorker: './duckdb-browser-eh.worker.js',
mainModule: duckdb_wasm_next,
mainWorker: eh_worker,
},
});

Expand Down
2 changes: 1 addition & 1 deletion components/main/Desktop/ShareableLinkCreator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function ShareableLinkCreator({
<Button
variant="contained"
onClick={() => {
// const url = new URL(`${process.env.API_URL}/map`);
// const url = new URL(`${import.meta.env.API_URL}/map`);
const url = new URL(`${window.location.href.split('?')[0]}`);
if (requestStatus.councilId) {
url.searchParams.append('councilId', requestStatus.councilId);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion components/main/Reports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Reports() {
const [isLoading, setIsLoading] = React.useState(true);
const classes = useStyles();

const url = process.env.REPORT_URL;
const url = import.meta.env.REPORT_URL;
const location = useLocation();
const reportPath = location.pathname.slice(REPORTS_PATH.length - 1);
const reportRef = React.useRef(reportPath);
Expand Down
4 changes: 2 additions & 2 deletions hooks/useContentful.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-shadow: ["error", { "allow": ["data", "errors"] }] */
import React from 'react';

const url = `https://graphql.contentful.com/content/v1/spaces/${process.env.CONTENTFUL_SPACE}`;
const url = `https://graphql.contentful.com/content/v1/spaces/${import.meta.env.CONTENTFUL_SPACE}`;

const useContentful = query => {
const [data, setData] = React.useState(null);
Expand All @@ -12,7 +12,7 @@ const useContentful = query => {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.CONTENTFUL_TOKEN}`,
Authorization: `Bearer ${import.meta.env.CONTENTFUL_TOKEN}`,
},
body: JSON.stringify({ query }),
})
Expand Down
7 changes: 1 addition & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,12 @@
}(window.location))
</script>
<!-- End Single Page Apps for GitHub Pages -->

<!-- Webpack injected tags -->
<title>
<%= htmlWebpackPlugin.options.title %>
</title>

</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/index.jsx"></script>
</body>

</html>
3 changes: 0 additions & 3 deletions index.js → index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,3 @@ ReactDOM.render(
</Provider>,
document.getElementById('root'),
);

// hot module replacement during development
if (module.hot) module.hot.accept();
Loading