'Using node.js experimental loaders with rollup

I am using rollup to bundle my Node.js applications - it allows me to deploy them in production as a single file without relying on npm.

I also happen to have my own custom loaders for some special format files that I import in my code by calling

node --experimental-loader=./lib/txt-colormap-es-loader.mjs and then doing

import colormap from './colormaps/01.txt';

One of these is handlebars for which there is a special plugin in rollup.

But I also have my own custom formats with my own custom loaders.

Does anyone see any way I could make rollup work with my custom ES6 loader in Node.js short of writing a new plugin?



Solution 1:[1]

I found a suboptimal solution without developing/publishing/maintaining a new rollup plugin - import the loader itself and call it manually on the file imported as a string. Importing as a string can be accomplished

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mmomtchev