Skip to content

Instantly share code, notes, and snippets.

@soska
Created August 8, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soska/1a012b1cd834674e33b9aee33cae95f8 to your computer and use it in GitHub Desktop.
Save soska/1a012b1cd834674e33b9aee33cae95f8 to your computer and use it in GitHub Desktop.
const defaultPluginOptions = {
extension: /\.worker.js$/,
};
const plugin = (config, pluginOptions, nextOptions) => {
const { extension } = pluginOptions;
config.module.rules.push({
test: extension,
use: [
nextOptions.defaultLoaders.babel,
{
loader: 'worker-loader',
options: {
fallback: true,
inline: false,
},
},
],
});
return config;
};
module.exports = (pluginOptions = defaultPluginOptions) => (
nextConfig = {}
) => {
return Object.assign({}, nextConfig, {
webpack(config, nextOptions) {
if (!nextOptions.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
);
}
config = plugin(config, pluginOptions, nextOptions);
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, nextOptions);
}
return config;
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment