Nuxt.js: Exclusive Modern Mode Feature

Created on 14 Dec 2018  ·  29Comments  ·  Source: nuxt/nuxt.js

What problem does this feature solve?

As a dev who don't need to support old browsers I would like to have a way to build only the modern version of the build so I could spend less time on generating the final assets

What does the proposed changes look like?

I think in addition to --modern flag we can have smth. like --no-legacy that will disable standard build generation

This feature request is available on Nuxt community (#c8308)
feature-request

Most helpful comment

We really really really would like to see this, build times are terrible.

All 29 comments

We really really really would like to see this, build times are terrible.

This would make things much faster in dev. I think most people should build against latest browsers, and the compile to older browsers at CI. Developers are paying a terrible price during development to support production. Of course, some sort of testing should be done before going live.

Serving static website (after nuxt generate). I can see that both legacy and modern bundles are loaded by the browser. What's the point of "modern" build if a user browser have to load legacy too?

@koresar, are you sure that they both are actually loaded, maybe they only referenced twice?

Here is how I tested it.

$ nuxt generate --modern
$ npx node-static dist/

Open http://localhost:8080
See the Network tab in the browser.

Red - legacy bundle.
Green - modern bundle.
image

I expect only 4 .js files to be downloaded by the browser (it's a fresh new nuxt project). However, as you can see there are 8.

@koresar looks like a bug

Hello @Atinux

Sorry poking you. Please take a look at the screenshot above. Is it a bug?

TL;DR: the generated SPA-mode website downloads both legacy and modern bundles. Thus website gets twice larger.

@koresar Please file a new bug report ☺️ (at https://bug.nuxtjs.org/)

Please try it with nuxt-edge first (yarn remove nuxt && yarn add nuxt-edge) to see if the bug already has been fixed, eg via https://github.com/nuxt/nuxt.js/commit/ecf76d91f1bec8dcab8f2c7715e0e07a19d0b6fe

@koresar did you run your code with explicit --modern flag? As far as I remember this was required until recently. Please, try to recreate it with Nuxt 2.4.2, I think it's already fixed

@AndrewBogdanovTSS looks fixed. Thank oyu.

Any updates on this? Anthing that improves build times would be a welcome addition.

you could use modern only in prod for now @cypressious

@manniL doing exactly that for now :)

Any ideas when was this fixed @koresar @manniL ? I see this still happening in 2.4.3 with generate:

The resource ....js. was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate as value and it is preloaded intentionally.

I see borwser loading both sets of js files

@husayt Could you provide a repo ?

For anyone wants include modern bundles only, actually you don't need to use build.modern.

You can leverage @nuxt/babel-preset-app directly, increase babel transpiling level by:

// nuxt.config
// Note: remove `modern` in nuxt.config
  build: {
    babel: {
      presets: ({ isServer }) => {
        return [[
          '@nuxt/babel-preset-app',
          {
            targets: isServer ? { node: 'current' } : {},
            modern: !isServer 
          }
        ]]
      }
    }
  }

thanks for a workaround @clarkdo but it would be great to see a cleaner built in option that can be applied in nuxt.config

@AndrewBogdanovTSS Working on it recently 😸

@clarkdo I tried your snippet but it didn't change build behavior in any way, still got 2 client builds happening instead of just modern one

With this config, you don't need to specify modern, because default client build will generate modern bundles by babel.

@clarkdo so the actual "green" line means modern build now?

@clarkdo Here is the demo:

https://codesandbox.io/s/r4v8mr729p

I just added this to nuxt-config:

  mode: "spa",
  modern: true,

You can see browser loads both sets of js files modern and classic. I also get a warning in chrome:

The resource https://r4v8mr729p.sse.codesandbox.io/_nuxt/app.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate as value and it is preloaded intentionally.
....

Yes, it's just a way to make bundles have a higher transpilation level, then bundles will be built with only supporting modern browsers.

@husayt Please have a look at my comment above, please remove modern in nuxt.config.

Sorry, I misunderstood the comment context, will have a look asap

I tried various browsers. This happens in Chrome 69, Edge and IE11. Only Firefox 60 behaved as expected and did only load modern bundle.

@clarkdo will it build all 3 bundles for production with such setup? I want only-modern only in dev mode

@AndrewBogdanovTSS We're discussing this, if the proposal gets agreed, I'll work on it asap

@husayt Your issue will be fixed in #5043

@clarkdo any updates on this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

surmon-china picture surmon-china  ·  3Comments

danieloprado picture danieloprado  ·  3Comments

mikekidder picture mikekidder  ·  3Comments

VincentLoy picture VincentLoy  ·  3Comments

pehbehbeh picture pehbehbeh  ·  3Comments