diff --git a/package/environments/__tests__/base.js b/package/environments/__tests__/base.js index ca462e54f..492f5acf3 100644 --- a/package/environments/__tests__/base.js +++ b/package/environments/__tests__/base.js @@ -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') diff --git a/package/environments/base.js b/package/environments/base.js index 72b75d9ce..a63f3e6e2 100644 --- a/package/environments/base.js +++ b/package/environments/base.js @@ -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 } diff --git a/test/test_app/app/javascript/packs/multi_entry.css b/test/test_app/app/javascript/packs/multi_entry.css new file mode 100644 index 000000000..54b560f84 --- /dev/null +++ b/test/test_app/app/javascript/packs/multi_entry.css @@ -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 + */ \ No newline at end of file diff --git a/test/test_app/app/javascript/packs/multi_entry.js b/test/test_app/app/javascript/packs/multi_entry.js new file mode 100644 index 000000000..9fea9c084 --- /dev/null +++ b/test/test_app/app/javascript/packs/multi_entry.js @@ -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 + */