ricokahler / next-plugin-preval

Pre-evaluate async functions during builds and import them like JSON
MIT License
255 stars 12 forks source link

Feature request: transpile dependencies (with next-transpile-modules) #45

Open fabien opened 3 years ago

fabien commented 3 years ago

I'm using https://github.com/martpie/next-transpile-modules within a mono-repo for a smooth dev experience. Unfortunately, it is not compatible with next-plugin-preval.

In theory next-transpile-modules would run before next-plugin-preval and it should all just work, but this is not the case. I need them in reverse order to actually have a working app at all.

Would be awesome if it would work transparently.

const withPlugins = require('next-compose-plugins');
const transpileModules = require('next-transpile-modules');
const withTranslations = require('next-translate');

const withPreval = require('next-plugin-preval/config')();

const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});

const coreModules = [];

const nextConfig = {};

const withTM = transpileModules(
  ['lodash-es', ...coreModules],
  {
    resolveSymlinks: true
  }
);

return withPlugins(
  [
    withPreval(), // first
    withTM, // second
    withTranslations,
    withBundleAnalyzer
  ],
  nextConfig
);