symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 198 forks source link

asset/inline Asset Module complains about generator property which isn't there #1237

Open dusandz opened 11 months ago

dusandz commented 11 months ago

I'm having an issue with asset/inline and would appreciate some help.

This is the rule I'm trying to add:

 .addRule({
        test: /my-module[/\\]static-assets/,
        type: 'asset/inline',
    })

And that triggers a warning when I try to build the assets:

warn  in ./assets/js/my-module/static-assets/ sync ^\.\/.*$                                                                                                                                     

Module not found: ValidationError: Invalid generator object. Asset Modules Plugin has been initialized using a generator object that does not match the API schema.
 - generator has an unknown property 'filename'. These properties are valid:
   object { dataUrl? }
   -> Generator options for asset/inline modules.

The error message makes sense (there are no filenames for inlined assets), but I'm not passing any filename parameters to the rule. Thinking that something might be happening under the hood, I tried modifying the config manually:

config = Encore.getWebpackConfig();
config.module.rules.push({
    test: /my-module[/\\]static-assets/,
    type: 'asset/inline',
})
module.exports = config

...but that didn't help. Just as a sanity check, I console-logged that part of the config:

  { test: /my-module[/\\]static-assets/, type: 'asset/inline' }

Looks good, but still complains about the filename. Then I tried writing generator directive explicitly (thinking that Webpack or Encore might be adding its own, if omitted):

{
    test: /my-module[/\\]static-assets/,
    type: 'asset/inline',
    generator: {
        dataUrl: content => {
            return content.toString('base64');
        }
    }
}

...to no avail. Tried on an isolated piece of code (just Webpack), worked fine there.

I can work around this and load the static assets manually using fetch, but I'm really curious to learn what did I do wrong.

carsonbot commented 1 week ago

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?