├── prompts.js
├── generator.js
├── index.js
├── package.json
├── LICENSE
└── README.md
/prompts.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | message: 'Enter a comma seperated list of locales',
4 | name: 'locales',
5 | type: 'input',
6 | },
7 | ];
8 |
--------------------------------------------------------------------------------
/generator.js:
--------------------------------------------------------------------------------
1 | module.exports = function(api, options, rootOptions) {
2 | var normalizedLocales = options.locales
3 | .split(',')
4 | .map(locale => locale.trim().toLowerCase())
5 |
6 | api.extendPackage({
7 | vue: {
8 | pluginOptions: {
9 | moment: {
10 | locales: normalizedLocales,
11 | },
12 | },
13 | },
14 | });
15 | }
16 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 |
3 | function resolveProperty(obj, path) {
4 | return path.split('.').reduce((p, k) => p && p[k], obj);
5 | }
6 |
7 | module.exports = function(api, options) {
8 | var locales = resolveProperty(options, 'pluginOptions.moment.locales') || [];
9 |
10 | if (locales.length) {
11 | var localesRegExp = new RegExp(locales.join('|'));
12 |
13 | api.configureWebpack(function(webpackConfig) {
14 | return {
15 | plugins: [
16 | new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, localesRegExp),
17 | ],
18 | };
19 | });
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-cli-plugin-moment",
3 | "version": "0.1.1",
4 | "description": "moment.js plugin for vue-cli",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/scottbedard/vue-cli-plugin-moment.git"
12 | },
13 | "keywords": [
14 | "vue-cli",
15 | "moment.js"
16 | ],
17 | "author": "Scott Bedard",
18 | "license": "MIT",
19 | "bugs": {
20 | "url": "https://github.com/scottbedard/vue-cli-plugin-moment/issues"
21 | },
22 | "homepage": "https://github.com/scottbedard/vue-cli-plugin-moment#readme"
23 | }
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2018-present, Scott Bedard
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vue-cli-plugin-moment
2 |
3 | [](https://www.npmjs.com/package/vue-cli-plugin-moment)
4 | [](https://github.com/scottbedard/vue-cli-plugin-moment/blob/master/LICENSE)
5 |
6 | This plugin configures webpack's use of moment.js to only include a few locales. Desired locales can be set by entering a CSV of [moment.js locales](https://github.com/moment/moment/tree/develop/locale) during installation, or by setting them manually in your `vue.config.js`. Below is an example configuration that includes only the English locales.
7 |
8 | ```js
9 | module.exports = {
10 | pluginOptions: {
11 | moment: {
12 | locales: ['en']
13 | }
14 | }
15 | }
16 | ```
17 | To demonstrate the payload differences to expect, here is a before and after using the above configuration.
18 |
19 | | Before | After |
20 | | :----: |:-----:|
21 | |
|
|
22 |
--------------------------------------------------------------------------------