Skip to content

Commit 9ef47f3

Browse files
sebjacobschrislo
andcommitted
refactor: group asset loading webpack config together
The existing webpack config customizes the filenames of any assets we import which have not been inlined using the `assetModuleFilename`. This config option is defined at the global level, however it only applies to assets that are processed by the Asset module definition. Rather than configuring this globally, I have opted for defining it within the Asset module definition (nested under the `generator` option) as that makes it clearer that this option is only relevant for those assets thus making it easier for future developers to understand and make changes in the future, especially for those who are less familiar with the intricacies of webpack config. [1] https://webpack.js.org/guides/asset-modules/ Co-Authored-By: Chris Lowis <chris.lowis@gofreerange.com>
1 parent 090a20f commit 9ef47f3

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

webpack.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const baseConfig = new ScratchWebpackConfigBuilder(
2929
.setTarget('browserslist')
3030
.merge({
3131
output: {
32-
assetModuleFilename: 'static/assets/[name].[hash][ext][query]',
3332
library: {
3433
name: 'GUI',
3534
type: 'umd2'
@@ -45,7 +44,10 @@ const baseConfig = new ScratchWebpackConfigBuilder(
4544
.addModuleRule({
4645
test: /\.(svg|png|wav|mp3|gif|jpg)$/,
4746
resourceQuery: /^$/, // reject any query string
48-
type: 'asset' // let webpack decide on the best type of asset
47+
type: 'asset', // let webpack decide on the best type of asset
48+
generator: {
49+
filename: 'static/assets/[name].[hash][ext][query]'
50+
}
4951
})
5052
.addPlugin(new webpack.DefinePlugin({
5153
'process.env.DEBUG': Boolean(process.env.DEBUG),

0 commit comments

Comments
 (0)