Trying to write a Build Plugin for custom file types that is Dev-mode only


#1

I’m on a quest :crossed_swords: to write a build plugin that includes/transpiles files with custom extension (say, .myspecialjs) into javascript, but only when running in development/debug mode.

The reason for this is another package I wrote that’s debugOnly, which will then be used by the code in these .myspecialjs-files.

I don’t want these files to be included in the production build.

So far I’ve managed to build a package that’s marked debugOnly and another package that adds a build plugin that does exactly what I want, but…

For this to work, the first package must call api.imply('myBuildPlugin') in the package.js. This seems to cause the inclusion of my build plugin even when building a production bundle, which then causes errors when my .myspecialjs-files try to import stuff from the debugOnly package that didn’t get included.

I also tried to write a minifier plugin that would just remove those files, but then I would have to remove standard-minifier-js, since only one minifier is allowed (naturally).

I’m still trying different strategies, but if you have an idea, please share…


EDIT: On second read, this is really hard to understand. In a nutshell, what I want is to…

  1. A debugOnly-package that includes another package, a build plugin
  2. This build plugin will include specific files to the JS bundle but ONLY in debug/dev-mode


#2

Reading the source code of api.imply, what I’ve done should print an error… but it doesn’t :confused:


#3

For the time being, I solved this by checking

const INCLUDE_MY_MAGIC_FILES = process.env.NODE_ENV === 'development';

if (INCLUDE_MY_MAGIC_FILES) {
   ...

in the build plugin and this seems to do the trick.