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

Enable regenerator in legacy bundles #1617

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/fresh-paws-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"preact-cli": patch
---

Transpile generators and async functions in legacy bundles. Async functions were inadvertently transpiled to generators in 3.3.0, this transpiles them to ES5.
3 changes: 1 addition & 2 deletions packages/cli/lib/lib/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module.exports = function (env, options = {}) {
modules: options.modules || false,
targets: {
browsers: options.browsers,
},
exclude: ['transform-regenerator'],
}
},
],
],
Expand Down
11 changes: 8 additions & 3 deletions packages/cli/lib/lib/webpack/webpack-base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = function createBaseConfig(env) {
const browserslistDefaults = ['> 0.25%', 'IE >= 9'];
const browserlistConfig = Object(browserslist.findConfig(cwd));
const browsers =
env.browserslist ||
(isProd ? browserlistConfig.production : browserlistConfig.development) ||
browserlistConfig.defaults ||
browserslistDefaults;
Expand Down Expand Up @@ -173,7 +174,7 @@ module.exports = function createBaseConfig(env) {

module: {
rules: [
{
(info) => ({
Copy link
Member

Choose a reason for hiding this comment

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

The tests seem to be failing because this is a function

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this only supported in newer Webpack?

Copy link
Member

Choose a reason for hiding this comment

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

No, isn't supported in newer Webpack either. Rules have to be objects.

// ES2015
enforce: 'pre',
test: /\.m?[jt]sx?$/,
Expand All @@ -182,10 +183,14 @@ module.exports = function createBaseConfig(env) {
loader: require.resolve('babel-loader'),
options: Object.assign(
{ babelrc: false },
createBabelConfig(env, { browsers }),
createBabelConfig(env, {
browsers: info.compiler.name === 'InjectManifest'
Copy link
Member

Choose a reason for hiding this comment

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

what exactly does this do?

Copy link
Member Author

@developit developit Nov 22, 2021

Choose a reason for hiding this comment

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

It's supposed to keep modern syntax in both generated sw.js outputs, since service worker is only supported by fairly modern browsers with generator/async support anyway. The compiler.name check is looking for the child compiler created by the workbox-webpack-plugin InjectManfiest plugin.

Copy link
Member

Choose a reason for hiding this comment

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

ah, right

Copy link
Member

Choose a reason for hiding this comment

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

maybe it would make sense to add a comment for future reference

? 'supports es6-module'
: browsers
}),
babelrc // intentionally overwrite our settings
),
},
}),
{
// LESS
enforce: 'pre',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/lib/lib/webpack/webpack-server-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ function serverConfig(env) {
}

module.exports = function createServerConfig(env) {
env = Object.assign({}, env, { browserslist: 'node >= 12' });
return merge(baseConfig(env), serverConfig(env));
};