mariusbalcytis / webpack-bundle

Bundle to Integrate Webpack into Symfony
MIT License
122 stars 36 forks source link

Question about multiple static servers #73

Open Erreke opened 7 years ago

Erreke commented 7 years ago

Hello.

I'm using this bundle. Great job. Thank you.

I have a question. Is it possible to compile styles and scripts in maba/webpack-bundle on multiple static servers? I’m sure you’re aware that with Symfony, it’s possible to specify several static servers during compile.

If in "framework.templating.assets_base_urls" parameters are specified two servers:

    - static-server-1.company.com
    - static-server-2.company.com

then the twig template code looks like this:

{% javascripts output = 'compiled/js/app/bundle.js'
    '@ApplicationBundle/Resources/assets/script_1.js'
    '@ApplicationBundle/Resources/assets/script_2.js'
    '@ApplicationBundle/Resources/assets/script_3.js'
%}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

at different times, it displays links either like this: <script src="//static-server-1.company.com/compiled/js/app/bundle.js"> or this: `

I’d like to be able to get the same result in maba/webpack-bundle... If I have the following settings in webpack.config.js:

...
entry: {
    mainPage: path.resolve(JS_PATH + '/pages/main/MainPage.js')
},
output: {
    path: '/home/app/web/compiled/bundles/',
    publicPath: '/compiled/bundles/',
    filename: '[name].[chunkhash].js'
},
...

and if we have this code in the twig-templates:

{% webpack css named 'mainPage' %}
    <link rel="stylesheet" href="{{ asset_url }}"/>
{% end_webpack %}

In webpack_manifest.php I’d like to see something more like this:

<?php return array (
  'mainPage' =>
    array (
        'js' => array (
            0 => '//static-server-1.company.com/compiled/bundles/mainPage.54798272904eb44eb763.js',
            1 => '//static-server-2.company.com/compiled/bundles/mainPage.54798272904eb44eb763.js',
        )
    ),
);

and at different times, I’d like to get something like this: <script src="//static-server-1.company.com/compiled/bundles/mainPage.54798272904eb44eb763.js"></script> and this: <script src="//static-server-2.company.com/compiled/bundles/mainPage.54798272904eb44eb763.js"></script>

Is it possible to do this in maba/webpack-bundle ?

mariusbalcytis commented 7 years ago

No, currently such feature is not implemented. To include path inside manifest would be questionable as it would include changing, replacing or extending quite standard and popular webpack plugin.

Could you explain the need of such feature? As I see it, most CDNs use single domain for serving traffic all over the world - DNS is used to point to different IPs to the same domain in different parts of the world.

Is this for scaling the traffic between several servers without the need to handle all of it in single reverse proxy?

Erreke commented 7 years ago

I need this functionality for domain sharding: https://blog.stackpath.com/glossary/domain-sharding/ https://wp-rocket.me/blog/difference-cdn-and-domain-sharding/