# Write files from folder into one \`importable\` file

**URL:** <https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363>\
**Category:** Ember CLI\
**Created:** [August 28, 2018, 6:44am UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363 "2018-08-28T06:44:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![teejay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/teejay/32/13585_2.png) [@teejay](https://discuss.emberjs.com/u/teejay)\
**Post date:** [August 28, 2018, 6:44am UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363/1 "2018-08-28T06:44:22Z")

</div>

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

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

```

you always need some thing like

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

```

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

```nohighlight
    const mirage = concatFilter(
      'mirage/scenarios',
      {
        inputFiles: ['test-*.js'],
        outputFile: '/merged-files.js',
        header: 'export default [',
        footer: ']',
        separator: ',',
      },
      'SimpleConcat'
    )

```

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

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![teejay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/teejay/32/13585_2.png) [@teejay](https://discuss.emberjs.com/u/teejay)\
**Post date:** [August 28, 2018, 8:06am UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363/2 "2018-08-28T08:06:20Z")

</div>

This can be deleted, its obsolete.

---

<div class="post-metadata">

**Author:** ![NullVoxPopuli](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nullvoxpopuli/32/18691_2.png) [@NullVoxPopuli](https://discuss.emberjs.com/u/NullVoxPopuli)\
**Post date:** [August 28, 2018, 9:58am UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363/3 "2018-08-28T09:58:57Z")

</div>

what was the solution?

---

<div class="post-metadata">

**Author:** ![teejay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/teejay/32/13585_2.png) [@teejay](https://discuss.emberjs.com/u/teejay)\
**Post date:** [August 28, 2018, 1:18pm UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363/4 "2018-08-28T13:18:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ef4](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ef4/32/13470_2.png) [@ef4](https://discuss.emberjs.com/u/ef4)\
**Post date:** [August 28, 2018, 1:29pm UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363/5 "2018-08-28T13:29:47Z")

</div>

(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:

```nohighlight
let app = new EmberApp(defaults, {
  trees: {
    vendor() {
       // your broccoli code goes here
       return concatFilter(...);
    }
  }
});
app.import('vendor/path-to-the-concatted/file.js');

```

---

<div class="post-metadata">

**Author:** ![ef4](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ef4/32/13470_2.png) [@ef4](https://discuss.emberjs.com/u/ef4)\
**Post date:** [August 28, 2018, 1:30pm UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363/6 "2018-08-28T13:30:28Z")

</div>

> [@teejay](#):
>
> There was no solution, the problem became a non-problem once I discovered that I dont have to any of this.

That is also a good answer. 😀

---

<div class="post-metadata">

**Author:** ![teejay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/teejay/32/13585_2.png) [@teejay](https://discuss.emberjs.com/u/teejay)\
**Post date:** [August 28, 2018, 10:43pm UTC](https://discuss.emberjs.com/t/write-files-from-folder-into-one-importable-file/15363/7 "2018-08-28T22:43:33Z")

</div>

> [@ef4](#):
>
> (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:
> 
> ```js
> let app = new EmberApp(defaults, {
> trees: {
> vendor() {
> // your broccoli code goes here
> return concatFilter(...);
> }
> }
> });
> app.import('vendor/path-to-the-concatted/file.js');
> 
> ```

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