// 모던 브라우저 감지
const isModern = 'fetch' in window && 'assign' in Object
// 모던 브라우저가 아닌 경우
if (!isModern) {
// 동적으로 <script> 요소 생성
const scriptNode = document.createElement('script')
// <script> 요소 속성 설정
scriptNode.async = false
scriptNode.src = './polyfills.js'
// <head> 요소 안쪽 뒤에 삽입 (로딩)
document.head.appendChild(scriptNode)
}
개발용 entry 구성과 빌드용 entry 구성을 구분하기 위해 아래와 같이 조건 처리합니다.
module.exports = (_env, argv) => {
// 엔트리(입력)
const entry = {
main: './src/index.js',
}
// 개발 모드
if (isProd) {
// 엔트리 추가
entry = {
...entry,
'polyfills': './src/polyfills/index.js',
'detect.polyfills': './src/polyfills/detect.js',
}
}
// 구성 객체 반환
return {
entry,
// ...
}
}