eddyerburgh / eddyerburgh/vue-test-loader

Prefer Webpack chunks instead of fs.writeFileSync()?

Open
#5 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
131
Forks
6
PR merge metrics
No merged PRs in 30d

Description

I'm admittedly not a Webpack expert (especially for chunks, which I rarely use), but instead of using [`fs.writeFileSync`](https://github.com/eddyerburgh/vue-test-loader/blob/master/index.js#L22) and have webpack synchronously write out files, wouldn't be better to just use Webpack's [`emitFile` method](https://github.com/webpack/webpack/blob/caf64a95c847adaf06a97edf519907c7c35b9cfe/lib/NormalModule.js#L484) for this? You can see it in [action in the `file-loader`](https://github.com/webpack-contrib/file-loader/blob/master/src/index.js#L81) which emits the file to disk and returns the path.

By emitting a file, I'm pretty sure it gets refed to webpack and extra processing can happen. At that point, you can use [`SplitChunksPlugin`, specifically the .name property](https://webpack.js.org/plugins/split-chunks-plugin/#splitchunksname) to bundle the tests, or not (it becomes up to the user). It'd probably require similar options to `file-loader` tbh, which would get around the hardcoded `__tests__` path.

Perhaps it would just be better to use `file-loader`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.