-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
WIP: use esbuild for building main renderer code #722
Draft
achou11
wants to merge
46
commits into
master
Choose a base branch
from
esbuild
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
9076ec2
chore: upgraded electron and node
ErikSin aa774f2
bring back map server using latest
achou11 3184ed1
replace electron.remote with @electron/remote
achou11 6ec4819
fix usage of electron-is-dev module
achou11 ba81279
add patch for ecstatic
achou11 5ce26c8
remove duplicate code in app.js
achou11 5248e38
fix import of electron remote in renderer
achou11 3d06334
remove electron remote from externals
achou11 b1c0c25
fix issue with creating map server db before directory exists
achou11 5cc4c5b
fix mapServer scoping error when quitting app
achou11 364241b
upgrade react-intl to remove usage of broken peer dep
achou11 d92a821
remove unused livereload functionality
achou11 536c002
remove commented-out webpack plugin
achou11 c548a1a
update comment in new api file
achou11 9ea06e0
adjustments for window.mode in background windows
achou11 d78ae70
upgrade electron to 22.2.0
achou11 4278c40
ci changes
achou11 1d62322
Merge branch 'master' into es/chore-electron-upgrade
achou11 39fabc8
maybe fix electron build issue with fsevents
achou11 d230364
maybe fix rimraf issue on windows ci
achou11 666ba8f
partially undo previous
achou11 9e9e37d
try node script for ci artifact removal
achou11 461bf68
upgrade map server to latest
achou11 3f98e7d
upgrade electron to latest 22
achou11 41f5a65
update babel config
achou11 c730f47
Merge branch 'master' into es/chore-electron-upgrade
achou11 709fa4d
update electron to latest v22
achou11 fa7bd87
upgrade electron to v22.3.2
achou11 1029845
update defineMessages usage to avoid using react-intl babel transform
achou11 68c6cf7
add react-pdf step to script
achou11 5526975
move preload scripts
achou11 e2e4672
project config stuff
achou11 26c0090
fix es module issue with react-mapbox-gl
achou11 b6c34c2
changes to renderer code
achou11 e85b801
update main.html
achou11 30c888f
make backend work okay with dev server
achou11 f1740dc
clean up static dir
achou11 a4a0255
update files based on static directory changes
achou11 a55a572
update build script
achou11 a6089eb
update readme
achou11 0359290
more changes to build config
achou11 c94707b
random package.json changes
achou11 04dee39
update build script to use parseArgs
achou11 163a0ab
WIP: worker stuff
achou11 e7c7697
Merge branch 'master' into esbuild
achou11 4106593
Revert "WIP: worker stuff"
achou11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
#!/usr/bin/env node | ||
|
||
// @ts-check | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { promisify, parseArgs } from 'node:util' | ||
import rimraf from 'rimraf' | ||
import * as esbuild from 'esbuild' | ||
|
||
const VALID_COMMANDS = ['build', 'watch', 'clean'] | ||
const VALID_MODES = ['dev', 'prod'] | ||
const OUTPUT_DIR = 'static' | ||
|
||
// Changes based on Electron version | ||
// See https://releases.electronjs.org/releases/stable | ||
const CHROME_VERSION = 108 | ||
|
||
/** | ||
* @type {import('esbuild').Plugin} | ||
*/ | ||
const copyNodeModulesAssetsPlugin = { | ||
name: 'copy-node-modules-assets', | ||
setup (build) { | ||
const { outdir } = build.initialOptions | ||
|
||
if (!outdir) { | ||
console.warn( | ||
'copy-node-modules-assets failed to run. no `outdir` defined' | ||
) | ||
return | ||
} | ||
|
||
// TODO: Consider moving iD + Mapbox CSS assets to static/css | ||
// Would need to update builder.config.js | ||
|
||
// fs.copyFileSync( | ||
// path.resolve('node_modules/id-mapeo/dist/iD.css'), | ||
// path.join(outdir, 'css/id-mapeo.css') | ||
// ) | ||
// fs.copyFileSync( | ||
// path.resolve('node_modules/mapbox-gl/dist/mapbox-gl.css'), | ||
// path.join(outdir, 'css/mapbox-gl.css') | ||
// ) | ||
|
||
// https://github.com/wojtekmaj/react-pdf#standard-browserify-esbuild-and-others | ||
fs.copyFileSync( | ||
path.resolve('node_modules/pdfjs-dist/build/pdf.worker.js'), | ||
path.join(outdir, 'pdf.worker.js') | ||
) | ||
|
||
console.log('copy-node-modules-assets ran successfully!') | ||
} | ||
} | ||
|
||
await runCommand(extractArgs()) | ||
|
||
/* ------------------------------------------------------- */ | ||
|
||
/** | ||
* @returns {{command: 'build'|'watch'|'clean', mode: 'dev'|'mode'}} | ||
*/ | ||
function extractArgs () { | ||
const { values, positionals } = parseArgs({ | ||
options: { | ||
mode: { | ||
type: 'string', | ||
short: 'm' | ||
} | ||
}, | ||
allowPositionals: true | ||
}) | ||
|
||
const command = positionals[0] | ||
const mode = values.mode || 'dev' | ||
|
||
if (!VALID_COMMANDS.includes(command)) { | ||
const message = | ||
(command | ||
? `Invalid command '${command}' specified.` | ||
: `No command specified`) + | ||
`\nPlease use one of the following: ${VALID_COMMANDS.join(', ')}` | ||
|
||
console.error(message) | ||
|
||
process.exit(1) | ||
} | ||
|
||
if (!VALID_MODES.includes(mode)) { | ||
const message = | ||
`Invalid mode '${mode}' specified.` + | ||
`\nPlease use of of the following: ${VALID_MODES.join(', ')}` | ||
|
||
console.error(message) | ||
|
||
process.exit(1) | ||
} | ||
|
||
return { | ||
command, | ||
mode | ||
} | ||
} | ||
|
||
/** | ||
* @param {Object} opts | ||
* @param {'build'|'watch'|'clean'} opts.command | ||
* @param {'dev' | 'prod'} opts.mode | ||
*/ | ||
async function runCommand (opts) { | ||
const buildOptions = createBuildOptions(opts.mode) | ||
|
||
switch (opts.command) { | ||
case 'clean': { | ||
await cleanBuildAssets() | ||
|
||
console.log(`Successfully cleaned ${buildOptions.outdir}`) | ||
|
||
break | ||
} | ||
case 'build': { | ||
await cleanBuildAssets() | ||
|
||
await esbuild.build(buildOptions) | ||
|
||
console.log('Successfully built!') | ||
|
||
break | ||
} | ||
case 'watch': { | ||
const ctx = await esbuild.context(buildOptions) | ||
|
||
await cleanBuildAssets() | ||
|
||
await ctx.watch() | ||
|
||
const { host, port } = await ctx.serve({ | ||
host: 'localhost', | ||
servedir: '.' | ||
}) | ||
|
||
console.log(`Listening at http://${host}:${port}`) | ||
|
||
break | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {'dev'|'prod'} mode | ||
* @returns {import('esbuild').BuildOptions} | ||
*/ | ||
function createBuildOptions (mode) { | ||
return { | ||
entryPoints: [ | ||
{ in: 'src/renderer/app.js', out: 'app' }, | ||
{ in: 'src/renderer/components/MapFilter/index.js', out: 'map-filter' }, | ||
{ in: 'src/renderer/components/MapEditor/index.js', out: 'map-editor' }, | ||
Comment on lines
+155
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
in: 'src/renderer/components/MapFilter/ReportView/renderReport.worker.js', | ||
out: 'reportWorker' | ||
} | ||
], | ||
entryNames: '[name].bundle', | ||
chunkNames: '[name]-[hash].chunk', | ||
outdir: OUTPUT_DIR, | ||
// Think Electron disables ESM but this should be okay, I think | ||
// https://github.com/electron/electron/issues/21457 | ||
format: 'esm', | ||
splitting: true, | ||
minify: mode === 'prod', | ||
bundle: true, | ||
target: `chrome${CHROME_VERSION}`, | ||
plugins: [copyNodeModulesAssetsPlugin], | ||
loader: { | ||
'.js': 'jsx', | ||
'.svg': 'file', | ||
'.ttf': 'file' | ||
}, | ||
// Anything specified here has to use `require` to import in renderer app code | ||
external: [ | ||
'electron', | ||
'process', | ||
'path', | ||
'https', | ||
'fs', | ||
'child_process', | ||
'os', | ||
'crypto', | ||
'stream', | ||
'constants', | ||
'http', | ||
'domain', | ||
'zlib', | ||
'timers' | ||
] | ||
} | ||
} | ||
|
||
async function cleanBuildAssets () { | ||
return promisify(rimraf)(`./${OUTPUT_DIR}/*.{bundle,chunk}.{js,css}`) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
top level
await
...the future is now