Prevent JS file from being minified

Hi,

I am using child_process fork to do background processing from a classical meteor app. What is the recommended approach to prevent the JS file of the job from being minified in production?

Thanks.

Remove the standard-minifier-js package

Actually, I wanted to keep everything else minified. Just exclude one file. At least the client should be minified.

This is kind of convoluted (I am sorry for even suggesting it), but you could put that file under the private/ folder, access it via the Assets API, and then save it to disk and execute it in a non-minified state that way. I’m not sure that you can just exempt an application source file from being minified in the way that you want.

Yeah for server-side child_process, using the private/ folder would work well.

Something like:

import child_process from 'child_process';

const processOnePath = Assets.absoluteFilePath("background/processOne.js");
const child = child_process.fork(processOnePath);
child.on('message', message => {
  // do something
});
child.send({ data: "someData" });
1 Like

Thanks for the quick reply. That worked nicely except that the forked job cannot find node_modules/mongodb in production (which I confirmed is included in the built bundle).

Any advice?

You can try using assets, as I learned today in another thread.

This part I don’t know…

Maybe you can pass a cwd option at the root where the node_modules live in production?

I managed to solve the node_modules issue.
The problem is that meteor puts the node_modules in a folder called “npm”. So, the paths where node looks for the modules are all wrong. Node looks for node_modules folder in the app directory and all its parents but will never look for it in npm/node modules. The solution was just to change the paths like this, I added this on the top of the scripts to alter the paths:

let cache = require('module')._cache;
let paths = cache[Object.keys(cache)[0]].paths
paths.forEach(p=> paths.push(p.replace(/node_modules/g,"npm/node_modules")));