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 199 forks source link

[ FEATURE ] setEntries() method #1113

Open 6562680 opened 2 years ago

6562680 commented 2 years ago

Always i've wroten setter i must create delete or clear method.

That should be solved via creating methods: setItems() + addItem()

Its a minimum. If you pass setItems([]) - it work like "delete". Then you add "addItems", "deleteItem", "deleteItems" if needed or skip that useless stuff.

Why "set" is needed? We see "Google Pagespeed" recommendation about "separate bundles for ES5 and ES2015+" - almost 50% filesize difference.

We need to create two bundles with two configs.

But ConfigValidator forbid you to .getWebpackConfig() without entries. You add "app" as entry, and next you need to create "app.es5" entry, but inside the list already "app". You cant delete it.

===

Also bug:

    .configureFilenames( {
        // js entries
        js: isEnabledVersioning
            ? 'js/[name].[contenthash].js'
            : 'js/[name].js',

        // css imports
        css: isEnabledVersioning
            ? 'css/[name].[contenthash].css'
            : 'css/[name].css',

        // imported images and fonts, possible url-loader background: url() things
        assets: isEnabledVersioning
            ? 'assets/[ext]/[name].[hash][ext]'
            : 'assets/[ext]/[name][ext]',
    } )

AND

        .configureImageRule( {
            enabled: true,

            type   : 'asset/resource', // asset, asset/resource, asset/inline
            maxSize: 0,

            filename: isEnabledVersioning
                ? 'img/[name].[hash][ext]'
                : 'img/[name][ext]',
        } )

There's no way to define:

const config = Encore.getWebpackConfig();

// js dynamic imports (await import('file.js'))
config.output.chunkFilename = isEnabledVersioning ? 'js/chunk/[name].[contenthash].js' : 'js/chunk/[name].js';
stof commented 2 years ago

if you need to create 2 configs, that's what the Encore.reset() is for.

6562680 commented 2 years ago

thats what am talking about.

1) what about that encore wants to clear output directory starting building from second config? yes, we define something like:

    .cleanupOutputBeforeBuild( [ '!**/*' ] )

2) also encore cant rename 'entrypoints.json', seems it should be two different build folders, otherwise config from one encore could change output of second one

    .configureManifestPlugin( (options) => {
        options.filename = 'manifest.json'; // can rename manifest. cant rename entrypoints. cant merge entrypoints. cant force symfony to use different entrypoints. cant twig get second entrypoints from symfony.
    } )

Moral? Think first.

stof commented 2 years ago

@6562680 the solution to me is to use separate output folders for your modern and legacy builds: public/build and public/legacy-build for instance. This way, you won't have file name conflicts

6562680 commented 2 years ago

Yes, did it, actually build contains images and other shared things. Even if repository ignores any builds at least one required points - using "php encore code" to select from one manifest or two manifest, one entrypoints.json or second.

I had done it myself with raw php without symfony, cus of no twig extension, no symfony config for that, thank god am writing on raw php with those "recommendations" like "its fine, dont worry, get out"

Actually the problem is "create method "set" for sibling "add" - europeans again recommend to find "solution"... That brain is broken. 100th time that shit. They never think standart. They think like "solve here"

carsonbot commented 5 days ago

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