Moment: λ‘œμΌ€μΌ 없이 μˆœκ°„ ν•„μš”

에 λ§Œλ“  2015λ…„ 06μ›” 12일  Β·  20μ½”λ©˜νŠΈ  Β·  좜처: moment/moment

webpack λΉŒλ“œμ—μ„œ momentλ₯Ό μ‚¬μš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

require('moment') λŠ” CDNμ—μ„œ moment-with-locales.min.js λ₯Ό μ‚¬μš©ν•˜λŠ” 것과 κ°™μŠ΅λ‹ˆλ‹€(주둜 λ‚΄ λ²ˆλ“€μ˜ 크기 μ¦κ°€λ‘œ νŒλ‹¨).

κΈ°λ³Έ μ˜μ–΄ λ‘œμΌ€μΌλ§ŒμœΌλ‘œ μˆœκ°„μ„ μš”κ΅¬ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆκΉŒ? (즉, CDN의 moment.min.js ).

λ‚΄ μ§ˆλ¬Έμ€ # 2373κ³Ό 관련이 μžˆλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€.

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

방금 webpackμ—μ„œ κ·€ν•˜μ™€ λ™μΌν•œ 문제λ₯Ό κ²½ν—˜ν–ˆμŠ΅λ‹ˆλ‹€. 이 SO κ²Œμ‹œλ¬Όμ€ λ‘œμΌ€μΌ νŒ¨ν‚€μ§•μ„ ν”Όν•˜λŠ” 2가지 방법을 λ‹€λ£Ήλ‹ˆλ‹€. http://stackoverflow.com/a/25426019/239965

IgnorePlugin 이 λ‚˜λ₯Ό μœ„ν•΄ μΌν–ˆμŠ΅λ‹ˆλ‹€:

plugins: [
  new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]

λͺ¨λ“  20 λŒ“κΈ€

방금 webpackμ—μ„œ κ·€ν•˜μ™€ λ™μΌν•œ 문제λ₯Ό κ²½ν—˜ν–ˆμŠ΅λ‹ˆλ‹€. 이 SO κ²Œμ‹œλ¬Όμ€ λ‘œμΌ€μΌ νŒ¨ν‚€μ§•μ„ ν”Όν•˜λŠ” 2가지 방법을 λ‹€λ£Ήλ‹ˆλ‹€. http://stackoverflow.com/a/25426019/239965

IgnorePlugin 이 λ‚˜λ₯Ό μœ„ν•΄ μΌν–ˆμŠ΅λ‹ˆλ‹€:

plugins: [
  new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]

μ•„μ£Ό λ©‹μ§€λ„€μš” , κ°μ‚¬ν•©λ‹ˆλ‹€

IgnorePlugin이 μž‘μ—…μ„ μˆ˜ν–‰ν•˜λ©° μˆœκ°„μ„ μΆ”κ°€ν•  λ•Œ 11kb둜 μ••μΆ•λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

λ‘œμΌ€μΌκ³Ό ν•¨κ»˜ λ˜λŠ” λ‘œμΌ€μΌ 없이 μš”κ΅¬ν•˜λŠ” μ˜΅μ…˜μ΄ 있으면 μ—¬μ „νžˆ 쒋을 κ²ƒμž…λ‹ˆλ‹€. 이미 #2373이 μžˆμœΌλ―€λ‘œ 이것을 λ‹«μŠ΅λ‹ˆλ‹€.

이 의견 에 λ”°λ₯΄λ©΄ npmjs에 λ‘œμΌ€μΌμ΄ μ—†λŠ” μˆœκ°„μ΄ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€.

이 λͺ¨λ“ˆμ€ λ‘œμΌ€μΌ 없이 μˆœκ°„μ„ λ…ΈμΆœν•©λ‹ˆλ‹€ https://github.com/ksloan/moment-mini

moment λ₯Ό angular-cli moment 와 ν•¨κ»˜ μ‚¬μš©ν•˜λ©΄ 전체 λ‘œμΌ€μΌμ΄ λ‚΄ λ²ˆλ“€μ— ν¬ν•¨λ©λ‹ˆλ‹€.

image

--eject ν”Œλž˜κ·Έ λ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ— https://github.com/moment/moment/issues/2416#issuecomment -111713308이 μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ‘œμΌ€μΌμ„ μ œμ™Έν•˜κΈ° μœ„ν•΄ angular-cli λ₯Ό μ‚¬μš©ν•˜λŠ” μ†”λ£¨μ…˜μ΄ μžˆμŠ΅λ‹ˆκΉŒ?

@balexand κ°μ‚¬ν•©λ‹ˆλ‹€, 그것은 μ €μ—κ²Œ νš¨κ³Όμ μž…λ‹ˆλ‹€

λˆ„κ΅°κ°€κ°€ 타이핑을 λ†“μΉ˜λ©΄ μ—¬κΈ° λ‚΄ 포크가 μžˆμŠ΅λ‹ˆλ‹€.

https://github.com/kirillgroshkov/moment-mini-ts

npm i moment-mini-ts

import * as moment from 'moment-mini-ts'

λ‚΄κ°€ μ„ νƒν•œ 일뢀λ₯Ό μ œμ™Έν•˜κ³  IgnorePlugin으둜 λͺ¨λ“  λ‘œμΌ€μΌμ„ λ¬΄μ‹œν•˜λŠ” 것은 μ–΄λ–»μŠ΅λ‹ˆκΉŒ? 예λ₯Ό λ“€μ–΄ EN, ES, FR을 μ œμ™Έν•œ λͺ¨λ“  ν•­λͺ©μ„ λ¬΄μ‹œν•©λ‹ˆλ‹€. μ •κ·œ ν‘œν˜„μ‹μœΌλ‘œ ν•  수 μžˆμŠ΅λ‹ˆκΉŒ?

plugins: [
  new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]

νŽΈμ§‘ : λˆ„κ΅°κ°€κ°€ μ—¬μ „νžˆ 그것을 ν•„μš”λ‘œν•˜λŠ” 경우λ₯Ό λŒ€λΉ„ν•˜μ—¬ μ•Œμ•„ λƒˆμŠ΅λ‹ˆλ‹€. https://stackoverflow.com/a/25426019/2477303 μ—μ„œ μ°Ύμ•˜μŠ΅λ‹ˆλ‹€.

plugins: [
  new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en|es|fr/),
  // new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]

@kuncevic , angular-cli locale λ₯Ό μ œμ™Έμ‹œν‚€μ…¨λ‚˜μš”?

λ‚˜λŠ” 그것이 μΌμ’…μ˜ ν•΄ν‚Ήμ΄λΌλŠ” 것을 μ•Œκ³  μžˆμ§€λ§Œ 우리 ν”„λ‘œμ νŠΈλ₯Ό μœ„ν•΄ λ‹€μŒ λ‚΄μš©μœΌλ‘œ moment-angular-cli-patch.js νŒŒμΌμ„ λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€.

'use strict';

const fs = require( 'fs' );

console.log( 'Patchin internal Angular CLI configuration ...' );
const webpackProductionConfigPath = './node_modules/@angular/cli/models/webpack-configs/production.js';
fs.readfile( webpackProductionConfigPath, 'utf-8', ( error, fileContent ) => {
  const momentFix = 'extraPlugins.push( new webpack.ContextReplacementPlugin( /moment[\\/\\\\]locale$/, /de.js/ ) );';
  if ( fileContent.indexOf( momentFix ) === -1 ) {
    const uniqueContent = 'return {'; // Line 112
    const modifiedFileContent = fileContent.replace( uniqueContent, `${ momentFix }\n    ${ uniqueContent }` );
    fs.writeFile( webpackProductionConfigPath, modifiedFileContent, 'utf-8', ( error ) => {
      console.log( 'Done.' );
    } );
  } else {
    console.log( 'Nothing to do.' );
  }
} );

μœ„μ˜ μŠ€ν¬λ¦½νŠΈλŠ” 독일어λ₯Ό μ œμ™Έν•œ λͺ¨λ“  λ‘œμΌ€μΌμ„ λ¬΄μ‹œν•˜λ©° @angular/cli 1.5.0 용으둜 νŠΉλ³„νžˆ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€(λ‹€λ₯Έ 버전은 λ‹€λ₯΄κ²Œ μ²˜λ¦¬ν•΄μ•Ό ν•  μˆ˜λ„ 있음). package.json 파일 λ‚΄μ—μ„œ μŠ€ν¬λ¦½νŠΈμ— μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.

"scripts": {
  "postinstall": "node ./moment-angular-cli-patch.js"
}

ν›Œλ₯­ν•œ μ†”λ£¨μ…˜μ€ μ•„λ‹ˆμ§€λ§Œ μž‘λ™ν•˜λŠ” μ†”λ£¨μ…˜ ...

@dominique-mueller ν₯미둜운 μ•„μ΄λ””μ–΄μž…λ‹ˆλ‹€. κ³΅μœ ν•΄ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€.

@dominique-mueller μ§€κΈˆμ€ ν₯미둜운 μ•„μ΄λ””μ–΄μž…λ‹ˆλ‹€. κ°μ‚¬ν•©λ‹ˆλ‹€.

@dominique-mueller 아이디어 μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€! λ‚˜λŠ” Angular cli λŒ€μ‹  μˆœκ°„μ„ νŒ¨μΉ˜ν–ˆμŠ΅λ‹ˆλ‹€.

const fs = require('fs');
const filePath = './node_modules/moment/moment.js';
const patch = {
    find: 'var aliasedRequire = require;',
    replace: 'var aliasedRequire = function(){};'
};

console.log('Patching moment');
let source = fs.readFileSync(filePath);
const index = source.indexOf(patch.find);
if (index === -1) {
    console.log('Nothing to do.');
} else {
    source = source.toString().replace(patch.find, patch.replace);
    fs.writeFileSync(filePath, source, 'utf-8');
    console.log('done');
}

@dominique-mueller ν₯미둜운 μ•„μ΄λ””μ–΄μ§€λ§Œ angular-cli의 λ‚΄λΆ€ μ›ΉνŒ© ꡬ성을 νŒ¨μΉ˜ν•˜λŠ” 것이 μž₯기적으둜 쒋은 생각이라고 μƒκ°ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. νŒ¨μΉ˜κ°€ μ‹€μ œλ‘œ angular-cli 버전에 μ˜μ‘΄ν•˜κ³  당신이 ' 정말 μ‰½κ²Œ μ—…λ°μ΄νŠΈν•  수 μžˆμŠ΅λ‹ˆλ‹€. 패치의 μˆœκ°„ ꡬ성도 λ§ˆμ°¬κ°€μ§€μž…λ‹ˆλ‹€.
이상적인 μ†”λ£¨μ…˜μ€ Angularκ°€ μ›ΉνŒ© ꡬ성을 μ—¬λŠ” κ²ƒμ΄λ―€λ‘œ ν”ŒλŸ¬κ·ΈμΈμ„ μΆ”κ°€ν•˜κ±°λ‚˜ λ²ˆλ“€μ— μ‚¬μš©ν•˜μ§€ μ•Šμ€ ν•­λͺ©μ΄ λ§Žμ§€ μ•Šμ€ μ˜΅μ…˜μ„ μ œκ³΅ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@fergardi 의 의견 외에도 μ •κ·œμ‹μ„ μ•½κ°„ λ³€κ²½ν•˜λ©΄ μ›ν•˜μ§€ μ•ŠλŠ” λ‘œμΌ€μΌμ΄ ν¬ν•¨λ˜λŠ” 것을 방지할 수 μžˆμŠ΅λ‹ˆλ‹€.

plugins: [
  new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /(en|es|fr)$/),
]

μ΄λ ‡κ²Œ ν•˜λ©΄ es-do , es-us λ“±κ³Ό 같은 λͺ¨λ“  es-* λ‘œμΌ€μΌμ„ 얻을 수 μ—†μŠ΅λ‹ˆλ‹€.
μ‹€μ œλ‘œ, 이 λ³€κ²½ μ—†μ΄λŠ” λͺ¨λ“  지역적 차이둜 인해 3κ°œκ°€ μ•„λ‹Œ 13개의 λ‘œμΌ€μΌμ„ κ°–κ²Œ λ©λ‹ˆλ‹€.

ngx-build-plus λ₯Ό μ‚¬μš©ν•˜λ©΄

@SamVerschueren 이것은 λ†€λžμŠ΅λ‹ˆλ‹€ 😸

λ‚΄ λͺ¨λ“ˆμ—μ„œ λͺ‡ 개의 디렉토리λ₯Ό μ–΄λ–»κ²Œ λ¬΄μ‹œν•  수 μžˆμŠ΅λ‹ˆκΉŒ? λ‚΄ ν”„λ‘œμ νŠΈκ°€ κ±°λŒ€ν•˜κ³  prod λΉŒλ“œ 쀑에 μ œκ³΅λ˜λ―€λ‘œ μ²­ν¬λ³„λ‘œ 청크λ₯Ό λΉŒλ“œν•˜λ €κ³  μƒκ°ν•˜λ―€λ‘œ λͺ‡ 개의 디렉토리λ₯Ό λ¬΄μ‹œ/μ œμ™Έν•΄μ•Όν•©λ‹ˆκΉŒ? 쑰금 κΈ΄κΈ‰ν•˜κ²Œ λ„μ™€μ£Όμ„Έμš”. 미리 κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€.

λͺ¨λ²” 사둀λ₯Ό μ‚¬μš©ν•˜λŠ” μ—…λ°μ΄νŠΈκ°€ μžˆμŠ΅λ‹ˆκΉŒ? 졜근 λ¬Έμ œμ—μ„œ 이 μˆ˜μ • 사항을 λ‹€μ‹œ μ°Έμ‘°ν•œ κ²ƒμœΌλ‘œ λ‚˜νƒ€λ‚¬μŠ΅λ‹ˆλ‹€. https://github.com/urish/ngx-moment/issues/212

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰