Cereal
Cereal

Reputation: 3849

How to include import files in Meteor compiler plugin?

Let's say I have a file plugin.js, with the following contents:

class MyCompiler {
  processFilesForTarget(files) {
    files.forEach(file => {
      const output = myExternalFunction(file);
      file.addJavaScript({
        data: output,
        path: `${file.getDisplayPath()}.js`
      });
    })
  }
}

Plugin.registerCompiler({
  extensions: ['rb', 'js.rb'],
  filenames: []
}, () => new MyCompiler());

I also have a file myExternalFile.js, which is located beside plugin.js. I want to import myExternalFunction from myExternalFile to use in plugin.js.

I tried using import { myExternalFunction } from 'myExternalFile'; but that presents the error 'import' and 'export' may only appear at the top level (17:0).

Using require presents this error: require is not defined.

And finally, using Npm.require won't work because it's not an NPM dependency.

So how do I actually accomplish this?

Upvotes: 1

Views: 93

Answers (0)

Related Questions