Skip to content
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

fix(plugins): fix file loader behavior [LIBS-399] #779

Merged
merged 1 commit into from
Feb 16, 2023
Merged
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
21 changes: 5 additions & 16 deletions cli/config/plugin.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ module.exports = ({ env: webpackEnv, config, paths }) => {
chunkFilename: isProduction
? 'static/js/plugin-[name].[contenthash:8].chunk.js'
: 'static/js/plugin-[name].chunk.js',
// ! dhis2: this at least gets fonts to match the CRA build,
// but is re-outputting them
assetModuleFilename: 'static/media/[name].[hash][ext]',
// TODO: investigate dev source maps here (devtoolModuleFilenameTemplate)
},
optimization: {
Expand Down Expand Up @@ -275,33 +272,25 @@ module.exports = ({ env: webpackEnv, config, paths }) => {
},
}),
},
// dhis2: 'asset/resource' fixes fonts, but 'file-loader' breaks css modules
// when used for all asset types. So use each for respective files
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: 'static/media/[name].[hash][ext]',
},
},
// "file" loader makes sure those assets get served by WebpackDevServer.
// When you `import` an asset, you get its (virtual) filename.
// In production, they would get copied to the `build` folder.
// This loader doesn't use a "test" so it will catch all modules
// that fall through the other loaders.
{
loader: require.resolve('file-loader'),
// Exclude `js` files to keep "css" loader working as it injects
// its runtime that would otherwise be processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
// by webpack's internal loaders.
exclude: [
/^$/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this newly added regex only matches an empty string. I wonder if this is actually useful, or perhaps a remnant of some early stage experimentation.....
Screenshot 2023-02-16 at 15 05 24

Could you explain why this is needed here?

/\.(js|mjs|jsx|ts|tsx)$/,
/\.html$/,
/\.json$/,
],
options: {
name: 'static/media/[name].[hash:8].[ext]',
type: 'asset/resource',
generator: {
filename: 'static/media/[name].[hash][ext]',
},
},
],
Expand Down