Nuxt.js: Plugin Filename drives mode via addPlugin

Created on 10 May 2019  路  8Comments  路  Source: nuxt/nuxt.js

What problem does this feature solve?

With the latest version of nuxt, plugins go to the right build via their filename when they are referenced in nuxt.config.js

plugin.server.js > goes to server bundle
plugin.client.js > goes to client bundle
plugin.js > goes to both

This functionality doesn't seem to work when adding plugins via modules using .addPlugin

This forces people to do .addPlugin( src:'...', mode:'something') when I'd expect the 'default' mode to be based off the source filename

https://nuxtjs.org/api/internals-module-container#addplugin-template-

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

Most helpful comment

@hecktarzuli Right. I got the issue. It is because without providing fileName the generated name will be like mode-test.plugin.client.530b6c6a.js and regex fails to detect extension. Will open a PR for fix.

All 8 comments

@hecktarzuli thanks for this note. Yes, that would be more consistent. PR welcome. However, if we support this feature in a nuxt minor release, your module is only compatible with this version upwards and unsafe to use on older versions.

BTW are you sure omitting mode does not triggers auto mode detection? addPlugin adds to the same array and it will be processed here: https://github.com/nuxt/nuxt.js/blob/dev/packages/builder/src/builder.js#L272

Reproduce: https://github.com/pi0/nuxt-module-plugin-mode

Plugin is only included in client side.

Yes, I tried it first omitting mode, assuming it worked as expected. Then I inspected ./nuxt/index.js and saw the plugin comment said 'all'.

After passing mode, it changed to whatever i passed

image

image

@hecktarzuli Right. I got the issue. It is because without providing fileName the generated name will be like mode-test.plugin.client.530b6c6a.js and regex fails to detect extension. Will open a PR for fix.

@pi0 as Whitney Houston once said, "did you ever know that you are my hero?"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

o-alexandrov picture o-alexandrov  路  3Comments

lazycrazy picture lazycrazy  路  3Comments

vadimsg picture vadimsg  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

surmon-china picture surmon-china  路  3Comments