Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import without locales #212

Open
mhosman opened this issue Apr 19, 2019 · 2 comments
Open

Import without locales #212

mhosman opened this issue Apr 19, 2019 · 2 comments

Comments

@mhosman
Copy link

mhosman commented Apr 19, 2019

It could be great to add a way to import ngx-moment without locales and add the availability to import only the locales I want.

@rramo012
Copy link

This issue may have a solution for you: moment/moment#2416

@mcescalante
Copy link

I'm using Angular 8 and was looking to save the ~400kb from locales as I'm not using them myself. This may be a more "modern" solution for Angular 7/8 and is confirmed working with me by comparing my build outputs with webpack-bundle-analyzer:

  1. Install the custom-webpack angular builder npm i -D @angular-builders/custom-webpack
  2. Create a new file, extra-webpack.config.js in your project:
const webpack = require('webpack');

module.exports = {
  plugins: [
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  ]
}
  1. In angular.json update the architect build builder option to use custom-webpack and also add the customWebpackConfig to the options pointing to the file created in step 1:
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "path": "./extra-webpack.config.js"
            },
... (rest of config)
  1. Build and check your bundles, moment locales should be gone.

You can read/find more documentation for the custom-webpack builder here: https://www.npmjs.com/package/@angular-builders/custom-webpack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants