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$/)
]
μμ£Ό λ©μ§λ€μ , κ°μ¬ν©λλ€
IgnorePluginμ΄ μμ μ μννλ©° μκ°μ μΆκ°ν λ 11kbλ‘ μμΆλμμ΅λλ€.
λ‘μΌμΌκ³Ό ν¨κ» λλ λ‘μΌμΌ μμ΄ μꡬνλ μ΅μ μ΄ μμΌλ©΄ μ¬μ ν μ’μ κ²μ λλ€. μ΄λ―Έ #2373μ΄ μμΌλ―λ‘ μ΄κ²μ λ«μ΅λλ€.
μ΄ μ견 μ λ°λ₯΄λ©΄ npmjsμ λ‘μΌμΌμ΄ μλ μκ°μ΄ μμ΄μΌ ν©λλ€.
μ΄ λͺ¨λμ λ‘μΌμΌ μμ΄ μκ°μ λ ΈμΆν©λλ€ https://github.com/ksloan/moment-mini
moment
λ₯Ό angular-cli
moment
μ ν¨κ» μ¬μ©νλ©΄ μ 체 λ‘μΌμΌμ΄ λ΄ λ²λ€μ ν¬ν¨λ©λλ€.
--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
κ°μ₯ μ μ©ν λκΈ
λ°©κΈ webpackμμ κ·νμ λμΌν λ¬Έμ λ₯Ό κ²½ννμ΅λλ€. μ΄ SO κ²μλ¬Όμ λ‘μΌμΌ ν¨ν€μ§μ νΌνλ 2κ°μ§ λ°©λ²μ λ€λ£Ήλλ€. http://stackoverflow.com/a/25426019/239965
IgnorePlugin
μ΄ λλ₯Ό μν΄ μΌνμ΅λλ€: