-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Allow customizing order of bify transforms/plugins #13483
Conversation
We use Browserify to compile our JavaScript code into a distributable format. You can use Browserify in a few different ways, but we use the API, which is detailed [here][1]. The way we use it is as follows: ``` javascript const bundlerOpts = { entries: [], transform: [], plugin: [], require: [], manualExternal: [], manualIgnore: [], } // ... change bundlerOpts in various ways ... // then, later: const bundler = browserify(bundlerOpts); bundler.bundle(); ``` Note that all transforms and all plugins are passed to `browserify` in one go. This creates a problem, because transforms and plugins are processed in the same order in which they are specified. That is, specifying transform A, then plugin B, then transform C, is NOT the same as specifying transform A, then transform C, then plugin B. The way to correct this is to make use of Browserify's full API, which provides `transform` and `plugin` methods, as well as other specific methods to specify other options. This commit, then, updates the part of the build system that configures Browserify to use this API. The order dependency as it relates to transforms and plugins will come into play when introducing TypeScript into the build system. Namely, we will be introducing a `tsify` Browserify plugin, which will need to be specified before specifying `babelify`, as demonstrated [here][2]. Hence we need this commit to be in place so that this is possible. [1]: https://www.npmjs.com/package/browserify#browserifyfiles--opts [2]: https://github.com/TypeStrong/tsify#es2015-formerly-known-as-es6
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
addTransform( | ||
createRemoveFencedCodeTransform(buildType, shouldLintFenceFiles), | ||
); | ||
// Transpile top-level code |
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.
This is where tsify
will go. According to the documentation, it needs to go before babelify
.
// call the completion event to handle any post-processing | ||
events.emit('bundleDone'); | ||
} | ||
async function performBundle({ bundler, events }) { |
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.
I didn't see a real reason this was nested within bundleIt
, and considering most of bundleIt
is this function anyway, I pulled it out.
Builds ready [0115b86]Page Load Metrics (1106 ± 15 ms)
|
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.
Lovely solution! More modular, succint, and got rid of the "manual" code 👍
@digiwand Made a small change in response to your feedback. Can you take another quick look? |
Builds ready [94b5c58]Page Load Metrics (1097 ± 24 ms)
|
Builds ready [b8e1e9d]Page Load Metrics (1098 ± 30 ms)
|
Builds ready [5ab2295]Page Load Metrics (1155 ± 38 ms)
|
Builds ready [843f9ef]Page Load Metrics (1162 ± 31 ms)
|
Builds ready [d7ffcfd]Page Load Metrics (1082 ± 28 ms)
|
This PR may no longer be necessary since we're no longer adding |
We won't need this after all so I am closing this. |
We use Browserify to compile our JavaScript code into a distributable
format. You can use Browserify in a few different ways, but we use the
API, which is detailed here. The way we use it is as follows:
Note that all transforms and all plugins are passed to
browserify
inone go. This creates a problem, because transforms and plugins are
processed in the same order in which they are specified. That is,
specifying transform A, then plugin B, then transform C, is NOT the same
as specifying transform A, then transform C, then plugin B.
The way to correct this is to make use of Browserify's full API, which
provides
transform
andplugin
methods, as well as other specificmethods to specify other options. This commit, then, updates the part of
the build system that configures Browserify to use this API.
The order dependency as it relates to transforms and plugins will come
into play when introducing TypeScript into the build system. Namely, we
will be introducing a
tsify
Browserify plugin, which will need to bespecified before specifying
babelify
, as demonstrated here. Hencewe need this commit to be in place so that this is possible.
Manual testing steps:
dist/
).yarn start
. Reload the extension if need be. You should not see a white screen. Click around in the extension for a bit. You should not encounter any error screens.yarn start:test
. Run an e2e test. It should pass.yarn dist
. Reload the extension if need be. You should not see a white screen. Click around in the extension for a bit. You should not encounter any error screens.