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

Switch to ESModule #372

Closed
wants to merge 22 commits into from
Closed

Switch to ESModule #372

wants to merge 22 commits into from

Conversation

Jack-Works
Copy link
Member

@Jack-Works Jack-Works commented Nov 11, 2019

⚠⚠⚠ I've decided not to merge this due to bad DX ⚠⚠⚠

⚠⚠⚠ Don't delete this branch ⚠⚠⚠

close #221

The new architecture of Maskbook

TL;DR

With our new architecture, you can...

  1. ✔️ use import.meta
  2. ✔️ use dynamic import import() in any way you want
  3. ✔️ still use process.env.*
  4. ✔️ only start the minimal build tasks you need (e.g. gulp watch-esm or gulp watch-assets).
  5. ✔️ easily to debug in the Chrome Devtools.
  6. ✔️ use Hot Module Reload for React Components (experimental!!)
  7. ✔️ still support webext toolchain
  8. ❌ use require()
  9. ❌ use all Webpack variables like __webpack_public_path__
  10. ❌ tree shaking based on process.env.NODE_ENV

Caution about these things!

  1. ⚠️ import a JSON file is supported, but not encouraged, please load the JSON file by fetch when possible.
  2. ⚠️ When you change a JSON file that imported by example.ts, you need to change example.ts to recompile it because the JSON files are inlined to example.ts.
  3. ⚠️ DO NOT publish the build on your machine to the store unless you remove the temp folder before the build because old files are not removed.
  4. ⚠️ NEVER run tsc in this project! Run ttsc instead!
  5. ⚠️ webext toolchain is not migrated to the new toolchain yet! That means you cannot automatically install this on Android. I'll try to add it later.

Under the hood

Compile time

  • We now use gulp as our build tool. Use gulp --tasks to see what tasks are available.

    Don't think gulp is an outdated tool! I deliberately select the correct tool based on the situation. For unbundled development, gulp is the best tool in the old days to handle multiple files without bundling them into a single file.

  • Source codes (./src/) are compiled by the TypeScript compiler directly to emit ES Module files.

  • All dependencies (./node_modules/) are compiled by Webpack and served as a global variable __deps__. (In future we will migrate some to rollup and snowpack).

  • Web Workers are compiled by Webpack.

  • The injected script is compiled by Webpack.

  • We use TypeScript incremental build to speed up build time.

Runtime

To land this...

  • Test it on Chrome
  • Test it on Firefox
  • Test it on Firefox for Android
  • Test it on iOS
  • Test it on GeckoView

What's next?

  • Support React Dev tools
  • Better dependencies splitting
  • Investigate ES Module hot reload to improve DX.
  • Deprecates JSON import
  • Switch to rollup and Snowpack when possible
  • Move all image assets in the ./public/ folder to where they are be used and load them by import.meta

@Jack-Works Jack-Works force-pushed the feature/experiment-pika branch 2 times, most recently from 787f1d2 to 319e9d4 Compare January 29, 2020 09:34
@Jack-Works Jack-Works changed the title Experiment: Pika ESModule for background page Jan 30, 2020
@Jack-Works Jack-Works changed the title ESModule for background page Switch to ESModule May 16, 2020
@Jack-Works Jack-Works force-pushed the feature/experiment-pika branch 4 times, most recently from 0daf88b to a46d5e0 Compare July 20, 2020 03:06
package.json Show resolved Hide resolved
@Jack-Works
Copy link
Member Author

@guanbinrui hi! can you help me to find why the E2E test failed?

@guanbinrui
Copy link
Member

guanbinrui commented Jul 24, 2020

@guanbinrui hi! can you help me to find why the E2E test failed?

Failed to open the browser. I think the build/ folder which generated by build:e2e is absent.

@Jack-Works
Copy link
Member Author

@guanbinrui it's moved to temp/extension

@Jack-Works Jack-Works force-pushed the feature/experiment-pika branch 2 times, most recently from 38c668f to eec7c56 Compare July 24, 2020 14:32
@Jack-Works Jack-Works marked this pull request as ready for review July 25, 2020 15:55
@Jack-Works
Copy link
Member Author

This PR is ready for review! @guanbinrui please help me to fix the E2E test thanks!

Also, please run this branch in the watch mode and try to modify src/components/InjectedComponents/DecryptedPost/DecryptedPost.tsx this component to see if Hot Module Reloading is looking good.

@Jack-Works Jack-Works self-assigned this Jul 25, 2020
.storybook/main.js Show resolved Hide resolved
e2e/tsconfig.json Outdated Show resolved Hide resolved
jest.config.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
scripts/gulp/env.ts Outdated Show resolved Hide resolved
scripts/tsconfig.json Outdated Show resolved Hide resolved
src/env.d.ts Show resolved Hide resolved
src/tsconfig.json Outdated Show resolved Hide resolved
.circleci/config.yml Outdated Show resolved Hide resolved
.circleci/config.yml Outdated Show resolved Hide resolved
public/background.html Outdated Show resolved Hide resolved
"build:e2e": "gulp build --e2e",
"build:firefox": "gulp build --fx",
"build:gecko": "gulp build --android",
"build:ios": "gulp build --ios",
"compile:contracts": "./scripts/contracts.sh",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the task not migrate?

* WARNING: THIS FILE IS GENERATED. DO NOT MODIFY IT.
* https://github.com/mozilla/web-ext/issues/1986
*/
declare module 'web-ext' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract to a common library?

@dimensiondev/types

@guanbinrui guanbinrui mentioned this pull request Dec 7, 2020
5 tasks
@Jack-Works Jack-Works deleted the feature/experiment-pika branch June 24, 2021 01:45
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.

Experiment: Use ES Module to load scripts
3 participants