Skip to content

[Experimental] Standalone Frontend Dev Server #1257

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

Conversation

hydrosquall
Copy link

@hydrosquall hydrosquall commented Feb 13, 2020

Motivation

This is an experiment to to make it easier for people to contribute to the frontend by reducing the amount of setup steps (no mongodb) if they're making a frontend-only change. If we like the dev experience, it might be worthwhile to extract the "client" portion of the app to its own package, which the "server" can import.

Changes

  • Changed the references to process based on the simplified definition of index.html (I didn't bind the process variables to the window).
  • Parcel is a "zero config" dev server that we could used instead of running a full dev server. You can find docs here. Next.js is another option that could be worth investigating.
  • I am running 12.16.0 locally since I use nodenv rather than nvm, and 12.16.1 wasn't available. However, hopefully there shouldn't be significant differences.

Testing

  1. Clone this branch
  2. npm run parcel
  3. cp .env.example .env
  4. The app should work on localhost port 1234.

A live version of this app was auto-deployed to now.sh at this url:

(Login and other stateful features are disabled, since I didn't supply any environment variables. However, if supplied locally, those should work too. The API_URL will probably not work out-of-the-box, since it looks like CORS is disabled with the production API.

The now Github integration is capable of automatically building branch previews every time someone opens a PR, but I manually supplied the link here since this is still early-stage.

@welcome
Copy link

welcome bot commented Feb 13, 2020

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already.

@hydrosquall hydrosquall force-pushed the experiment/parcel-frontend-only branch from 50ddfe7 to b16d3bc Compare February 14, 2020 20:46
@catarak
Copy link
Member

catarak commented Feb 25, 2020

Thanks for working on this! Question about using Parcel—is it weird to have both Webpack and Parcel in a project? Does this circumvent Webpack?

@hydrosquall
Copy link
Author

hydrosquall commented Feb 26, 2020 via email

@hydrosquall hydrosquall force-pushed the experiment/parcel-frontend-only branch from b16d3bc to 9131f9c Compare March 5, 2020 21:45
@hydrosquall hydrosquall force-pushed the experiment/parcel-frontend-only branch from 9131f9c to 9b5724d Compare March 5, 2020 21:53
@andrewn
Copy link
Member

andrewn commented Mar 27, 2020

I agree that not having to run the API and mongodb to make front-end changes would be great!

I think we should use the same packager and config for all development environments. This will ensure making a change in the front-end-only env will be the same as the full-stack env and avoid weird bugs with the different packagers.

Perhaps a good way forward is separating the webpack dev server from the API server so that the can be run standalone? Then we could also switch to Parcel if we wanted.

@hydrosquall
Copy link
Author

Hi @andrewn, thanks for the idea! I've filed this as an issue to take on separately from this branch: #1348

Do you have any advice about where to start on this task? I'll see if I can budget some time for it in upcoming weeks.

@catarak
Copy link
Member

catarak commented Apr 7, 2020

Thanks @hydrosquall!

I would be down to explore if it makes sense to move from webpack to parcel. There's really nothing fancy happening with the bundling in this app, and maybe parcel is good enough.

@catarak catarak closed this May 26, 2020
@catarak catarak reopened this May 26, 2020
@catarak catarak changed the base branch from master to develop August 26, 2020 19:06
@hydrosquall
Copy link
Author

hydrosquall commented Feb 11, 2022

I took a look another at trying with the latest Parcel 2 and the latest head of develop.

I ran into a few hurdles due to changes to both this codebase and Parcel itself, some of which seemed time effective to solve, others which do not.

  1. The original index.html in this file did not work. The script type needs to be changed to module. See Browser scripts cannot have imports or exports. Use a <script type="module"> instead fregante/browser-extension-template#51 .
  2. Parcel 2 did not handle importing audio files (mp3) by default. This was fixable by following How to correctly load local assets like audio files parcel-bundler/parcel#1911 , I chose to create a .parcelrc instead of doing the url: prefix method to avoid breaking the existing code.
  3. Parcel 2 does not handle resourceQuery, and there are no plans to do so. ( see Is there a Parcel equivalent to Webpack's resourceQuery? parcel-bundler/parcel#2186 , Suggestion: myurl?static should tell parcel to copy the file as-is parcel-bundler/parcel#1084 ). This is an issue because the P5 editor needs this to load SVG files in 3 different ways:
    a. As raw text files, to inline (?byContent), as part of the replace feature
    b. As URL paths, to inject into stylesheets (?byUrl) (added as part of Make SVG icons web accessible #1420 )
    c. As React components (with the SVGR Loader) (Seemed to mostly change as part of b too).

test: /\.svg$/,
oneOf: [
{
resourceQuery: /byContent/,
use: 'raw-loader'
},
{
resourceQuery: /byUrl/,
use: 'file-loader'
},
{
use: {
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: {
removeViewBox: false
}
}
}
}
}

I look at the code that actually reads these SVGs. It didn't seem worthwhile to rewrite this code such that all SVGs are loaded in 1 way, since there seemed to be legitimate reasons to be loading icons in 3 different ways in the editor for now.

I didn't have confidence that this would be the end of Parcel configuration issues (inability to load relative URLs looked problematic too parcel-bundler/parcel#206 ), so I think may be best to retire the idea of using Parcel 2 to bundle this project, given that the current webpack config has a few customized asset loaders.

It might be more practical to get the standard webpack dev server working instead, so I'm going to try that in a separate PR.

References

@hydrosquall
Copy link
Author

Closing this PR as it will be replaced by #1999 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants