4

When you get moment.js library from Bower, there are these minified packages:

  • moment.min.js - without locales
  • moment-with-locales.min.js - with all locales included (still quite big file)

My goal is to create ONE minified moment.js file that would include my needed locales using Gulp. Here is my Gulp code:

var config = {
    //...
    moment: 'bower_components/moment/moment.js',
    momentLt: 'bower_components/moment/locale/lt.js',
}

gulp.task('vendor', ['clean-vendor', 'bower'], function () {        
    gulp.src([config.moment, config.momentLt]).
        pipe(concat('moment-custom.js')).
        pipe(rename({suffix: '.min'})).
        pipe(uglify()).
        pipe(gulp.dest('vendor/moment'));

});

File is combined and minified successfully. When I try to load this file using require.js, it is loaded successfully

require.config({
    paths: {
        "jquery": "vendor/jquery/jquery.min",
        "moment": "vendor/moment/moment-custom.min",
    }
});

(TypeScript)

import $ = require("jquery");
import moment = require("moment");

moment;

(JavaScript)

define(["require", "jquery", "moment"], function (require, $, moment) {
        moment;
}

But locale is not working:

moment().locale(); => en
moment().locale('lt');
moment().locale(); => en

My considerations:

  • Is this my problem moment-custom.min.js file?
  • Do I load this file correctly using require?
  • Should I declare another require module for locale exclusively?
ECM4D
  • 156
  • 9

0 Answers0