폴리필 구성
1. 폴리필, Unetch 설치
npm i core-js regenerator-runtime unfetchimport 'core-js/stable'
import 'regenerator-runtime/runtime'
import 'unfetch'// 모던 브라우저 감지
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)
}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,
// ...
}
}Last updated