Skip to content

Feature: Add support for multiple files per entry #2476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package/environments/__tests__/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe('Environment', () => {
)
})

test('should return multi file entry points', () => {
const config = environment.toWebpackConfig()
expect(config.entry.multi_entry.sort()).toEqual(
[
resolve('app', 'javascript', 'packs', 'multi_entry.css'),
resolve('app', 'javascript', 'packs', 'multi_entry.js')
]
)
})

test('should return output', () => {
const config = environment.toWebpackConfig()
expect(config.output.filename).toEqual('js/[name]-[contenthash].js')
Expand Down
13 changes: 12 additions & 1 deletion package/environments/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ const getEntryObject = () => {
paths.forEach((path) => {
const namespace = relative(join(rootPath), dirname(path))
const name = join(namespace, basename(path, extname(path)))
result.set(name, resolve(path))
let assetPaths = resolve(path)

// Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
// Transforms the config object value to an array with all values under the same name
let previousPaths = result.get(name)
if (previousPaths) {
previousPaths = Array.isArray(previousPaths) ? previousPaths : [previousPaths]
previousPaths.push(assetPaths)
assetPaths = previousPaths
}

result.set(name, assetPaths)
})
return result
}
Expand Down
4 changes: 4 additions & 0 deletions test/test_app/app/javascript/packs/multi_entry.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Dummy file #1 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
* This file must be named the same
*/
4 changes: 4 additions & 0 deletions test/test_app/app/javascript/packs/multi_entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Dummy file #2 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
* This file must be named the same
*/