Skip to content

Commit 384855b

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 9b97030 commit 384855b

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
@@ -16,7 +16,6 @@ const baseConfig = new ScratchWebpackConfigBuilder(
1616
.setTarget('browserslist')
1717
.merge({
1818
output: {
19-
assetModuleFilename: 'static/assets/[name].[hash][ext][query]',
2019
library: {
2120
name: 'GUI',
2221
type: 'umd2'
@@ -32,7 +31,10 @@ const baseConfig = new ScratchWebpackConfigBuilder(
3231
.addModuleRule({
3332
test: /\.(svg|png|wav|mp3|gif|jpg)$/,
3433
resourceQuery: /^$/, // reject any query string
35-
type: 'asset' // let webpack decide on the best type of asset
34+
type: 'asset', // let webpack decide on the best type of asset
35+
generator: {
36+
filename: 'static/assets/[name].[hash][ext][query]',
37+
},
3638
})
3739
.addPlugin(new webpack.DefinePlugin({
3840
'process.env.DEBUG': Boolean(process.env.DEBUG),

0 commit comments

Comments
 (0)