如何从角构建中排除弯矩区域? [英] How to exclude moment locales from angular build?

查看:73
本文介绍了如何从角构建中排除弯矩区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的angular 5应用程序中,当我使用

In my angular 5 application, when I create build using

ng build --prod --sm

和开放源代码地图浏览器,此刻在main.js文件中占用了大量空间.我发现使用时会加载所有语言环境

and open source map explorer, moment takes lot of space in the main.js file. I have found all the locales gets loaded when I use

import * as moment from 'moment';

我在需要瞬间打包的应用程序中使用了material-moment-adapter来实现某些功能.

I have used material-moment-adapter to some functionality in the application that requires the moment package also.

我已经使用angular-cli创建了该应用程序.我发现使用webpack.config.js中的设置排除了语言环境的许多链接有什么方法可以使用angular-cli排除语言环境?

I have created the application using angular-cli. I have found many links that excludes locales using settings in webpack.config.js Is there any way to exclude locales using angular-cli ?

推荐答案

本文介绍了很好的解决方案:

This article describe good solution: https://medium.jonasbandi.net/angular-cli-and-moment-js-a-recipe-for-disaster-and-how-to-fix-it-163a79180173

简而言之:

  1. ng添加ngx-build-plus

在项目的根目录中添加文件webpack.extra.js:

Add a file webpack.extra.js in the root of your project:

const webpack = require('webpack');
module.exports = {
    plugins: [
        new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    ]
}

  • 运行:

  • Run:

    npm run build --prod --extra-webpack-config webpack.extra.js
    

    在此处输入代码

    警告moment.js已被正式弃用 https://momentjs.com/docs/#/-project-status/(尝试使用day.js或luxon)

    Warning moment.js has been deprecated officially https://momentjs.com/docs/#/-project-status/ (try use day.js or luxon)

    这篇关于如何从角构建中排除弯矩区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆