developit / preact-cli-plugin-async

Preact CLI plugin that adds converts async/await to Promises.
https://npm.im/preact-cli-plugin-async
44 stars 10 forks source link

Seems to be broken with latest preact-cli (3.0.0-rc6) #25

Open kmiyashiro opened 4 years ago

kmiyashiro commented 4 years ago

preact build output:

✖ ERROR Error: TypeError: Cannot read property 'filter' of undefined

at ode_modules/preact-cli-plugin-async/dist/async-plugin.js:1:51

Which corresponds to this:

module.exports=function(e){var r=e.module.loaders.filter

Could be the change from webpack 3 to 4.

afflitto commented 4 years ago

module.loaders were deprecated since webpack 2 and are now removed in favor of module.rules.

as per webpack's To v4 from v3 page

1337rout commented 2 years ago

I fixed this by pulling async-plugin.js into our codebase and changing it to this.


export default function asyncPlugin(config) {
    let babel = config.module.rules.filter(loader => loader.loader && loader.loader.includes('babel-loader'))[0].options;

    // Blacklist regenerator within env preset:
    babel.presets[0][1].exclude.push('transform-async-to-generator');

    // Add fast-async
    babel.plugins.push([require.resolve('fast-async'), { spec: true }]);
}
developit commented 2 years ago

This shouldn't be necessary in preact-cli 3, since most browsers will be loading the modern JS bundles that use native async/await.