Write files from folder into one `importable` file

Hello first off I am pretty new to broccoli and ember cli (node stuff) so my apologies in advance if I get a few things wrong. I would like to read an entire folder of files and merge the content into on file which I can import somewhere in the application. So I started to play around in the ember-cli build file which seems to be a logical place to start.

The files I want to export are simple objects, which is a problem as es6 does not allow to just have

    { test: 'hello', test2: 'oh' }

you always need some thing like

    export default { test: 'hello', test2: 'no' }

besides that I thought I could use the broccoli-concat plugin.

    const mirage = concatFilter(
        inputFiles: ['test-*.js'],
        outputFile: '/merged-files.js',
        header: 'export default [',
        footer: ']',
        separator: ',',

And with that the end-result should look like something like this

export default [
  { test: 'world', test2: 'hello' },
  { test: 'world', test2: 'hello' }

which kind of does what I want it to do but it fails to create the merged file because its failing parsing the input files. So I have 2 problems to solve:

  1. how do make the concat plugin not parse the files (I cant see that there is an option in the source)
  2. How would I import such a file?

Other then that, does anyone maybe has a better idea how I can achieve such a thing.

Best regards Thomas

This can be deleted, its obsolete.

what was the solution?

There was no solution, the problem became a non-problem once I discovered that I dont have to any of this.

(Questions are useful to everyone searching the forum, even if you’ve found a solution.)

I think the parsing is because it’s trying to generate sourcemaps for you. You can pass { sourceMapConfig: false } to try turning that off.

As for how to get that file into your build, there are choices. I would probably do it via the vendor tree like:

let app = new EmberApp(defaults, {
  trees: {
    vendor() {
       // your broccoli code goes here
       return concatFilter(...);
1 Like

That is also a good answer. :grinning:

1 Like

This is still a very good thing to know, thank you.

1 Like