I'm using Rollup to build a UMD version of my module.
This rollup.config.js
successfully builds my module, without including @tensorflow/tfjs
:
import path from 'path';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
export default {
input: "dist/tmp/index.js",
output: {
file: "dist/umd/index.js",
format: 'umd',
name: 'Foo',
globals: {
'@tensorflow/tfjs': 'tf',
}
},
context: 'window',
external: ['@tensorflow/tfjs'],
}
However, I rely on a second module (tensor-as-base64
) that I do want to include in the bundle. I cannot figure out how to include that specific module.
From a lot of googling it seems like I need to use @rollup/plugin-commonjs
and @rollup/plugin-node-resolve
, but I can't find any examples for how to scope the includes to a specific folder under node_modules
. I've tried something like this:
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
export default {
input: "dist/tmp/index.js",
output: {
file: "dist/umd/index.js",
format: 'umd',
name: 'Foo',
globals: {
'@tensorflow/tfjs': 'tf',
}
},
context: 'window',
external: ['@tensorflow/tfjs'],
plugins: [
nodeResolve({
}),
commonjs({
include: [/tensor-as-base64/],
namedExports: {
'tensor-as-base64': ['tensorAsBase64'],
},
}),
]
};
This seems to just hang with no output.
Any tips on how to include a single specific module from the node_modules
folder (and ignore everything else in that folder)?
Update 1
I tried this config:
export default {
input: "dist/tmp/index.js",
output: {
file: "dist/umd/index.js",
format: 'umd',
name: 'Foo',
globals: {
'@tensorflow/tfjs': 'tf',
}
},
context: 'window',
external: ['@tensorflow/tfjs'],
plugins: [
nodeResolve({
resolveOnly: [
/^(?!.*(@tensorflow\/tfjs))/,
],
}),
],
})
This produces the following output:
dist/tmp/index.js → dist/umd/index.js...
[!] Error: 'default' is not exported by ../../node_modules/tensor-as-base64/dist/index.js, imported by dist/tmp/upscale.js
Which is accurate in that tensor-as-base64
does not export default
.
After including the commonjs plugin, it gets into an infinite loop. I think that's where I'm missing some bit of configuration.
I should add that this is a monorepo, so maybe there's an issue with node_modules
being at the root of the folder?