Easily remove unused Moment.js locales in Nuxt.js projects using moment-locales-webpack-plugin.
yarn add moment @nuxtjs/moment
OR npm i moment @nuxtjs/moment
Add @nuxtjs/moment
to modules
section of nuxt.config.js
To strip all locales except “en”:
{
modules: [
'@nuxtjs/moment',
]
}
Or to strip all locales except “en”, “es-us” and “fa“
{
modules: [
['@nuxtjs/moment', ['fa']]
]
}
// or
{
modules: [
'@nuxtjs/moment'
],
moment: {
locales: ['fa']
}
}
Note: “en” is built into Moment and can’t be removed)
You can set a default locale via the defaultLocale
option. It must be included
int the locales you keep (or 'en'
) and will only work when using the plugin option.
modules: [
['@nuxtjs/moment', { locales: ['de'], defaultLocale: 'de' }]
]
This module also registers a nuxt plugin to include all needed locales as well as injecting moment as $moment
to Vue context. You can disable this behaviour using an object config:
modules: [
['@nuxtjs/moment', { locales: ['es-us', 'ru'], plugin: false }]
]
- Clone this repository
- Install dependnecies using
yarn install
ornpm install
- Start development server using
npm run dev
Thanks Ivan Akulov for making this awesome webpack plugin. 💖
Copyright (c) Nuxt Community.