CINXE.COM
jQueryからTypeScript・Reactまで - Viteで始めるモダンで高速な開発環境構築 - ICS MEDIA
<!DOCTYPE html><html lang="ja" dir="ltr" data-capo=""><head><meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=yes"> <title>jQueryからTypeScript・Reactまで - Viteで始めるモダンで高速な開発環境構築 - ICS MEDIA</title> <script src="https://cdn.ampproject.org/v0.js" async></script> <script src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js" async custom-element="amp-twitter"></script> <script src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js" async custom-element="amp-youtube"></script> <style>.ripple{overflow:hidden;position:relative}.ripple-effect{animation-name:ripple;background:#888;border-radius:50%;display:block;opacity:.2;pointer-events:none;position:absolute;transform:scale(0);-webkit-user-select:none;user-select:none;will-change:opacity,transform}.ripple[data-ripple=light] .ripple-effect{background:#fff!important}.ripple[data-ripple=dark] .ripple-effect{background:#000!important}@keyframes ripple{to{opacity:0;transform:scale(2)}}</style> <style>.btn{background-color:initial;border:1px solid #0000;border-radius:.25rem;color:#000;display:inline-block;font-size:1rem;font-weight:400;line-height:1.5;padding:.375rem .75rem;text-align:center;transition:color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;-webkit-user-select:none;user-select:none}@media (prefers-reduced-motion:reduce){.btn{transition:none}}.btn-group,.btn-group-vertical{display:inline-flex;position:relative;vertical-align:middle}button:focus{outline:5px auto var(--primary)}.btn-group>.btn-group:not(:last-child)>.btn,.btn-group>.btn:not(:last-child,.dropdown-toggle){border-bottom-right-radius:0;border-top-right-radius:0}.btn-group>.btn-group:not(:first-child)>.btn,.btn-group>.btn:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0}.btn-primary{background-color:var(--primary);color:#fff!important}@media (any-hover:hover){@supports (background-color:color-mix(in srgb,#000,#000)){.btn-primary:hover{background-color:color-mix(in srgb,var(--primary),#000 20%)}}}.btn-secondary{background-color:var(--color-btn-secondary)}@media (prefers-color-scheme:dark){.btn-secondary{color:var(--color-text-p)}}@media (any-hover:hover){@supports (background-color:color-mix(in srgb,#000,#000)){.btn-secondary:hover{background-color:color-mix(in srgb,var(--color-btn-secondary),#888 20%)}}}.btn-group-vertical>.btn,.btn-group>.btn{flex:1 1 auto;position:relative}.btn-primary:not(:disabled,.disabled).active:focus,.btn-primary:not(:disabled,.disabled):active:focus,.show>.btn-primary.dropdown-toggle:focus{box-shadow:0 0 0 .2rem #268fff80}.text-center{text-align:center!important}.mx-auto{margin-left:auto!important;margin-right:auto!important}.badge{accent-color:red;border-radius:.25rem;display:inline-block;font-size:75%;font-weight:700;line-height:1;padding:.25em .4em;text-align:center;transition:color .2s,background-color .2s,border-color .2s;vertical-align:initial;white-space:nowrap}.badge-pill{border-radius:10rem;padding-left:.6em;padding-right:.6em}.badge-light{background-color:var(--color-btn-secondary);color:var(--color-text-p)}.badge-primary{background-color:var(--primary);color:#fff}@media (prefers-reduced-motion:reduce){*,:after,:before{animation:none!important;transition:none!important}}html{scroll-padding-top:32px;touch-action:manipulation}body{accent-color:var(--primary);line-break:strict;margin:0;overflow-wrap:anywhere;padding:0;word-break:normal}body ::selection{background-color:rgba(50,35,179,.251)}@media (prefers-color-scheme:dark){body ::selection{background-color:rgba(126,112,254,.251)}}img{vertical-align:bottom}a{color:inherit;-webkit-text-decoration:none;text-decoration:none;-webkit-tap-highlight-color:rgba(0,0,0,.2)}@media (prefers-color-scheme:dark){a{-webkit-tap-highlight-color:rgba(255,255,255,.1)}}ul{padding:0}ul li{list-style:none}button{appearance:none;border:none;cursor:pointer}</style> <style>.language-glsl,.language-html,.language-js{background:var(--color-bg-code);color:#383a42;display:block;overflow-x:auto;padding:.5em}.hljs-comment,.hljs-quote{color:#666}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#a626a4}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#813b32}.hljs-literal{color:#005c7d}.hljs-addition,.hljs-attribute,.hljs-meta-string,.hljs-regexp,.hljs-string{color:#2f612f}.hljs-built_in,.hljs-class .hljs-title{color:#733801}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#7f5901}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#3060bf}.hljs-strong{font-weight:700}.hljs-link{-webkit-text-decoration:underline;text-decoration:underline}</style> <style>@media (prefers-color-scheme:dark){.language-glsl,.language-html,.language-js{background:var(--color-bg-code);color:#abb2bf;display:block;overflow-x:auto;padding:.5em}.hljs-comment,.hljs-quote{color:#5c6370}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#c678dd}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#e06c75}.hljs-literal{color:#56b6c2}.hljs-addition,.hljs-attribute,.hljs-meta-string,.hljs-regexp,.hljs-string{color:#98c379}.hljs-built_in,.hljs-class .hljs-title{color:#e6c07b}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#d19a66}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#61aeee}.hljs-strong{font-weight:700}.hljs-link{-webkit-text-decoration:underline;text-decoration:underline}}</style> <style>:root{--color-text-p:#404040;--color-text-p-secondary:#606060;--color-text-h:#202020;--color-bg:#eff2f5;--color-bg-code:#fff;--color-bg-footer:#f9f9f9;--color-bg-strong:#fff996;--color-bg-btn:#1976d2;--color-btn-secondary:#e0e0e0;--color-text-a:#1976d2;--color-text-a-hover:var(--primary);--color-text-a-visited:var(--color-text-a);--color-border:#0000001a;--primary:#3223b3;--font-sans:Helvetica Neue,Arial,Hiragino Sans,Hiragino Kaku Gothic ProN,BIZ UDPGothic,Meiryo,sans-serif;--font-mono:SFMono-Regular,Menlo,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,BIZ UDGothic,Meiryo,monospace}@media (prefers-color-scheme:dark){:root{--color-text-p:#d0d0d0;--color-text-p-secondary:#a0a0a0;--color-text-h:#fff;--color-bg:#202020;--color-bg-code:#282c34;--color-bg-footer:#090909;--color-bg-strong:#7a0099;--color-text-a:#90caf9;--color-border:#d6d6d61a;--color-btn-secondary:#404040;--primary:#7e70fe}}@supports (-webkit-touch-callout:none) and (font:-apple-system-body){:root{font:-apple-system-body}}body{background-color:var(--color-bg);font-family:var(--font-sans)}iframe{border:none}.btn-primary{background-color:var(--primary);border-color:var(--primary);color:#fff}@media (min-width:768px){br.mobile{display:none}}@media (min-width:992px){br.tablet{display:none}}</style> <style>.ly-top-header[data-v-53af800e]{background-color:var(--color-bg);width:100%;z-index:1}@media print{.ly-top-header[data-v-53af800e]{position:static}}</style> <style>.mediaHeader[data-v-c016e82a]{border-bottom:1px solid var(--color-border);overflow:hidden;width:100%}.mediaHeader-row[data-v-c016e82a]{height:48px;margin:0 auto;max-width:960px;position:relative}@media (min-width:1200px){.mediaHeader-row[data-v-c016e82a]{max-width:1080px}}.mediaHeader-row h1[data-v-c016e82a]{left:50%;margin:0;position:absolute;top:50%;transform:translate(-50%,-50%)}.mediaHeader-row-tool[data-v-c016e82a]{align-items:center;display:flex;position:absolute;right:0;top:50%;transform:translateY(-50%)}.mediaHeader-row-tool a[data-v-c016e82a]{border-radius:6px;box-sizing:initial;color:var(--color-text-p);display:block;height:32px;padding:3px;-webkit-text-decoration:none;text-decoration:none;transition:background .2s}@media (any-hover:hover){.mediaHeader-row-tool a[data-v-c016e82a]:hover{background:#8080804d}}.mediaHeader-row-tool a[data-v-c016e82a]:active{background:#80808080}.mediaHeader-row-tool svg[data-v-c016e82a]{background:#0000;fill:#333}@media (prefers-color-scheme:dark){.mediaHeader-row-tool svg[data-v-c016e82a]{fill:#ccc}}.mediaHeader-row-tool-item[data-v-c016e82a]{margin-left:.5rem}</style> <style>a[data-v-39193113]{align-items:center;background-image:url(/_nuxt/logo-website.Cz5k_taM.png);background-position:50%;background-repeat:no-repeat;background-size:contain;display:flex;height:48px;width:144px}span[data-v-39193113]{visibility:hidden}</style> <style>nav[data-v-5ddcd2fd]{width:100%}.category-list[data-v-5ddcd2fd]{display:flex;justify-content:space-between;margin:0 auto;max-width:960px}@media (min-width:1200px){.category-list[data-v-5ddcd2fd]{max-width:1080px}}@media (max-width:767.98px){.category-list[data-v-5ddcd2fd]{overflow:auto}.category-list[data-v-5ddcd2fd]::-webkit-scrollbar{height:2px}.category-list[data-v-5ddcd2fd]::-webkit-scrollbar-track{border-radius:0}.category-list[data-v-5ddcd2fd]::-webkit-scrollbar-thumb{background-color:#80808080}}.category-list-item[data-v-5ddcd2fd]{flex:1}.category-list-item a[data-v-5ddcd2fd]{color:var(--color-text-p);display:block;font-feature-settings:"palt";font-size:.75rem;font-weight:700;padding:.5rem 1rem;text-align:center;-webkit-text-decoration:none;text-decoration:none;transition:color .2s,background .2s;-webkit-user-select:none;user-select:none;white-space:nowrap;word-break:keep-all}@media (any-hover:hover){.category-list-item a[data-v-5ddcd2fd]:hover{background:var(--primary);color:#fff}}.category-list-item a._current[data-v-5ddcd2fd],.category-list-item a[aria-current=page][data-v-5ddcd2fd]{background:var(--primary);color:#fff}@media (max-width:767.98px){.category-list-item a[data-v-5ddcd2fd]{font-size:.625rem;padding-left:.5rem;padding-right:.5rem}}</style> <style>.heroSpace[data-v-cb0dd5fc]{background:#000;height:256px;overflow:hidden;position:relative;width:100%}.heroSpace-title[data-v-cb0dd5fc]{align-items:center;color:#fff;display:flex;font-weight:400;height:100%;justify-content:center;position:absolute;text-align:center;width:100%}.heroSpace-title p[data-v-cb0dd5fc]{color:#fff;font-feature-settings:"palt";font-size:1rem;font-weight:400;letter-spacing:.01em;margin:0 auto 16px;max-width:1080px}@media (max-width:767.98px){.heroSpace-title p[data-v-cb0dd5fc]{padding-left:16px;padding-right:16px}}.heroSpace-title h1[data-v-cb0dd5fc]{font-feature-settings:"palt";font-size:2rem;font-weight:400;letter-spacing:2px;margin:0 auto;max-width:1080px}@media (max-width:767.98px){.heroSpace-title h1[data-v-cb0dd5fc]{font-size:1.5rem;padding-left:16px;padding-right:16px}}.heroSpace_padding[data-v-cb0dd5fc]{height:326px}@media (max-width:767.98px){.heroSpace_padding[data-v-cb0dd5fc]{height:212px}}.heroSpace_padding .heroSpace-title[data-v-cb0dd5fc]{align-items:center;display:flex;height:100%;justify-content:center;width:100%}.heroSpace iframe[data-v-cb0dd5fc]{height:100%;position:absolute;width:100%}</style> <style>.wbr[data-v-92dd477a]{display:inline-block}</style> <style>.top_link[data-v-da421125]{margin-bottom:64px;text-align:center}.entry-column[data-v-da421125]{display:flex;margin:0 auto;max-width:960px;width:100%}</style> <style>.site_updater[data-v-63cb43db]{background:var(--color-bg-footer);bottom:0;margin-top:20px;position:sticky}.site_updater p[data-v-63cb43db]{margin:0;padding:10px 0;text-align:center}.site_info[data-v-63cb43db]{background:var(--color-bg-footer);color:var(--color-text-p);padding:32px 0}@media (max-width:1199.98px){.site_info[data-v-63cb43db]{padding:32px 16px}}.site_info-sections[data-v-63cb43db]{display:grid;gap:32px;grid-template-columns:repeat(3,1fr);margin:0 auto;max-width:960px;width:100%}@media (max-width:991.98px){.site_info-sections[data-v-63cb43db]{gap:16px}}@media (max-width:767.98px){.site_info-sections[data-v-63cb43db]{grid-template-columns:1fr}}@media (min-width:1200px){.site_info-sections[data-v-63cb43db]{max-width:1080px}}.site_info-sections_item h3[data-v-63cb43db]{color:var(--color-text-h);font-size:1.5rem;font-weight:400;line-height:1;margin-bottom:16px}.site_info-sections_item p[data-v-63cb43db]{color:var(--color-text-p-secondary);font-size:.75rem;line-height:1.75;text-align:justify}.site_info-sections_item ul[data-v-63cb43db]{list-style-position:inside;padding:0 0 0 1rem}.site_info-sections_item ul li[data-v-63cb43db]{font-size:.75rem;line-height:1.75;list-style:circle}.site_info-sections_item a[data-v-63cb43db]{color:var(--color-text-p-secondary);-webkit-text-decoration:none;text-decoration:none;transition:color .2s}@media (any-hover:hover){.site_info-sections_item a[data-v-63cb43db]:hover{color:var(--color-text-a-hover)}}</style> <style>.copyright[data-v-4b34f398]{font-size:1rem;margin-top:32px;text-align:center}@media (min-width:768px){.copyright br.mobile[data-v-4b34f398]{display:none}}.raw-pages[data-v-4b34f398]{display:flex;font-size:.875rem;gap:24px;justify-content:center;margin-bottom:16px;margin-top:16px}@media (max-width:767.98px){.raw-pages[data-v-4b34f398]{flex-direction:column;gap:4px}}.raw-pages a[data-v-4b34f398]{color:var(--color-text-p-secondary);transition:color .2s}@media (any-hover:hover){.raw-pages a[data-v-4b34f398]:hover{color:var(--color-text-a-hover)}}</style> <style>.eyecatch[data-v-921b35f7]{overflow:hidden;position:relative}.eyecatch .eyecatch-blur-container[data-v-921b35f7]{height:100%;overflow:hidden;position:absolute;width:100%}.eyecatch .eyecatch-blur[data-v-921b35f7]{background-size:cover;content:"";filter:brightness(1.25) blur(64px);height:150%;left:-25%;position:absolute;top:-25%;width:150%}@media (max-width:991.98px){.eyecatch .eyecatch-blur[data-v-921b35f7]{display:none}}.eyecatch-inner[data-v-921b35f7]{margin:0 auto;position:relative}@media (min-width:1200px){.eyecatch-inner[data-v-921b35f7]{max-width:1080px}}@media (min-width:992px) and (max-width:1199.98px){.eyecatch-inner[data-v-921b35f7]{max-width:960px}}.eyecatch-inner-img[data-v-921b35f7]{view-transition-name:var(--0e97d286);aspect-ratio:1280/512;contain:paint;height:auto;object-fit:cover;width:100%}@media (max-width:767.98px){.eyecatch-inner-img[data-v-921b35f7]{aspect-ratio:1280/720}}</style> <style>@media (min-width:992px){.entry[data-v-49d92408]{display:flex;flex-direction:row;gap:32px;margin:0 auto}}.entry-article[data-v-49d92408]{margin:0 auto;max-width:720px}@media (min-width:992px) and (max-width:1199.98px){.entry-article[data-v-49d92408]{width:640px}}.entry-sidebar[data-v-49d92408]{flex:1}@media (max-width:991.98px){.entry-sidebar[data-v-49d92408]{display:none}}</style> <style>@charset "UTF-8";.article-date{color:var(--color-text-p-secondary);font-size:.8rem;margin:1rem 0;text-align:center}@media (max-width:767.98px){.article-date{padding:0 1rem}}.article-date a{color:currentcolor;-webkit-text-decoration:none;text-decoration:none;transition:color .2s}@media (any-hover:hover){.article-date a:hover{color:var(--color-text-a-hover)}}.article-date .article-date-slash{margin-left:.25rem;margin-right:.25rem}.article-tag{display:flex;flex-wrap:wrap;gap:8px 4px;justify-content:center;list-style:none;padding:0}.article-tag li{display:inline-block}.article-tag a{border:1px solid var(--color-text-p);border-radius:6px;color:var(--color-text-p);font-size:.75rem;padding:.2em .5em;-webkit-text-decoration:none;text-decoration:none;transition:color .2s,border .2s}@media (any-hover:hover){.article-tag a:hover{border:1px solid var(--color-text-a-hover);color:var(--color-text-a-hover);-webkit-text-decoration:none;text-decoration:none}}.article{color:var(--color-text-p);font-size:1rem;line-break:strict;line-height:200%;overflow-wrap:anywhere;word-break:normal}.article h3{color:var(--color-text-h);font-family:var(--font-sans);font-feature-settings:"palt";font-size:2rem;font-weight:400;letter-spacing:.025em;line-height:1.25;margin-bottom:.5em;margin-top:3em}@media (max-width:767.98px){.article h3{font-size:1.5rem}}.article h3:after{background-color:var(--color-border);content:"";display:block;height:1px;margin-top:.25rem}.article h4,.article h5{color:var(--color-text-h);font-family:var(--font-sans);font-feature-settings:"palt";font-weight:400;letter-spacing:.025em;margin-bottom:1em;margin-top:2em}.article h4{font-size:1.5rem}.article h5{font-size:1.25rem}.article h1,.article h6{background:red;color:#000}.article h1:before,.article h6:before{content:"(この見出しレベルはサポートされてません)"}.article p{text-align:left;word-break:normal}.article p small{color:var(--color-text-p-secondary);font-size:.75em}.article p>a>img,.article p>img{height:auto;max-width:100%}@media (max-width:767.98px){.article p>a>img,.article p>img{margin-left:-1rem;margin-right:-1rem;max-width:none;width:100vw}.article p amp-youtube{margin-left:-1rem;margin-right:-1rem;max-width:100vw}}.article strong{background:linear-gradient(#0000 61%,var(--color-bg-strong) 0,var(--color-bg-strong) 0);font-weight:700}.article code{background-color:var(--color-bg-code);border-radius:.25rem;color:var(--color-text-p);font-family:var(--font-mono);padding:.2rem .4rem}@media (max-width:767.98px){.article{padding:0 1rem}}.article a{color:var(--color-text-a);-webkit-text-decoration:none;text-decoration:none}@media (any-hover:hover){.article a:hover{color:var(--color-text-a);-webkit-text-decoration:underline;text-decoration:underline}}.article a:visited{color:var(--color-text-a-visited)}.article a[target=_blank]:after{background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiMxOTc2ZDJ9PC9zdHlsZT48L2RlZnM+PHBhdGggZD0iTTI0LjU1IDB2M2gxMC4zM0wxNC40NCAyMy40NGwyLjEyIDIuMTJMMzcgNS4xMnYxMC4zNGgzVjB6IiBjbGFzcz0iY2xzLTEiLz48cGF0aCBkPSJNMzAgMzdIM1YxMGgxMVY3SDB2MzNoMzNWMjZoLTN6IiBjbGFzcz0iY2xzLTEiLz48L3N2Zz4=");background-repeat:no-repeat;content:"";display:inline-block;height:.7rem;margin:0 .25rem;width:.7rem}.article ol,.article ul{padding-inline-start:32px}.article li{list-style:inherit}.article>section>iframe{aspect-ratio:16/9;height:auto;width:100%}@media (max-width:767.98px){.article>section>iframe{margin-left:-1rem;margin-right:-1rem;max-width:none;width:100vw}}.article kbd{background-color:var(--color-bg-code);border-radius:4px;color:inherit;font-family:var(--font-mono);padding:.2rem .4rem;white-space:nowrap}.article blockquote{background:var(--color-bg-code);border-radius:6px;color:var(--color-text-p);margin:0;padding:1em}.article blockquote p{margin:0}.article pre{color:var(--color-text-p);font-family:var(--font-mono);font-size:.9rem;line-height:150%;overflow:auto;word-break:break-all;word-wrap:break-word;background:var(--color-bg-code);border-radius:5px}@media (max-width:767.98px){.article pre{font-size:.8rem;margin-left:-1rem;margin-right:-1rem}}.article code.hljs,.article pre>code{box-sizing:border-box;display:block;padding:20px;position:relative}.article code.hljs:before{background:var(--color-text-p);color:var(--color-bg);display:inline;font-size:.5rem;left:20px;line-height:1.25;padding:0 1em;position:absolute;top:0;-webkit-user-select:none;user-select:none}.article code.hljs.language-javascript:before,.article code.hljs.language-js:before{content:"JS"}.article code.hljs.language-json:before{content:"JSON"}.article code.hljs.language-xml:before{content:"XML"}.article code.hljs.language-html:before{content:"HTML"}.article code.hljs.language-css:before{content:"CSS"}.article code.hljs.language-scss:before{content:"SCSS"}.article code.hljs.language-ts:before,.article code.hljs.language-typescript:before{content:"TypeScript"}.article code.hljs.language-actionscript:before{content:"ActionScript 3.0"}.article code.hljs.language-cs:before{content:"C#"}.article code.hljs.language-bash:before{content:"コマンドライン"}.article code.hljs.language-swift:before{content:"Swift"}.article code.hljs.language-glsl:before{content:"GLSL"}.article code.hljs.language-vue:before{content:"Vue"}.breadcrumb{margin:5rem auto 1rem;max-width:1080px}@media (max-width:1199.98px){.breadcrumb{margin:0 1rem}}.breadcrumb ul{display:block;font-size:.9rem;list-style:none;overflow:hidden;padding:0;width:100%}.breadcrumb li{display:inline;word-break:break-all}.breadcrumb li:before{content:"/";margin:0 .5rem}.breadcrumb li:first-child:before{content:none}.breadcrumb li a{color:var(--color-text-p);-webkit-text-decoration:none;text-decoration:none}.breadcrumb li a:visited{color:currentcolor}@media (any-hover:hover){.breadcrumb li a:hover{color:var(--color-text-a-hover)}}.wrap{overflow:hidden}@media (min-width:768px){.wrap{margin:0 auto;max-width:720px}}.wrap_960{margin:0 auto}@media (min-width:1200px){.wrap_960{max-width:1080px}}@media (min-width:992px) and (max-width:1199.98px){.wrap_960{max-width:960px}}footer #copyright{font-size:.75rem;text-align:center}hr{border-color:var(--color-text-p);border-style:inset;border-width:1px;display:block;margin-block:.5em;margin-inline:auto;opacity:.5;overflow:hidden;unicode-bidi:isolate}table{font-size:.9rem;line-height:1.5;width:100%;word-break:break-all}table td,table th{border-top:1px solid var(--color-border);padding:.5rem .25rem;vertical-align:top}table thead th{border-bottom:1px solid var(--color-border);vertical-align:bottom}</style> <style>h2.article_title[data-v-3469d367]{color:var(--color-text-h);font-family:var(--font-sans);font-feature-settings:"palt";font-size:2rem;font-weight:700;letter-spacing:.005em;line-height:1.5;margin-left:auto;margin-right:auto;max-width:720px;text-align:center}@media (max-width:767.98px){h2.article_title[data-v-3469d367]{font-size:5vw;padding:0 .25rem}}h2.article_title[data-v-3469d367] strong{background:none;font-size:1.5em;font-weight:700}h2.article_title[data-v-3469d367] small{font-size:.75em;font-weight:inherit}h2.article_title[data-v-3469d367] span.wbr{display:inline-block}</style> <style>@media (max-width:767.98px){.article-date-item[data-v-d384dd23]{display:inline-block}}</style> <style>.sns-share[data-v-694562d6]{display:flex;gap:8px;justify-content:center;margin:1rem 0;text-align:center}.sns-share-badge[data-v-694562d6]{display:inline-block;font-size:12px;font-weight:700;line-height:1;margin-top:3px;padding:3px 6px;-webkit-user-select:none;user-select:none}.sns-share-btn[data-v-694562d6]{border-radius:6px;display:block;height:44px;transition:background-color .2s;width:44px}.sns-share-btn._x[data-v-694562d6]{background-color:#000;background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' fill='none' viewBox='0 0 240 240'%3E%3Cpath fill='%23fff' d='m88.2 60.66 81.26 118.15h-18.04L70.16 60.66zm4.73-9H53.04l93.64 136.15h39.89zM132.54 109.25l49.7-57.59h-11.25l-43.44 50.33z'/%3E%3Cpath fill='%23fff' d='m105.36 127.72-52.32 60.62H64.3l46.05-53.36z'/%3E%3C/svg%3E");background-repeat:no-repeat;background-size:contain}@media (any-hover:hover){.sns-share-btn._x[data-v-694562d6]:hover{background-color:#111}}.sns-share-btn._facebook[data-v-694562d6]{background-color:#32529f;background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='%23fff' d='M212 197h-37v60h37v176h70V257h50l5-60h-55v-33c0-14 3-20 17-20h38V83h-49c-52 0-76 23-76 67z'/%3E%3C/svg%3E");background-repeat:no-repeat;background-size:contain}@media (any-hover:hover){.sns-share-btn._facebook[data-v-694562d6]:hover{background-color:#2a4887}}.sns-share-btn._hatena[data-v-694562d6]{background-color:#00a4de;background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 500 500'%3E%3Cpath fill='%23fff' d='M278.2 258.1q-13.6-15.2-37.8-17c14.4-3.9 24.8-9.6 31.4-17.3s9.8-17.8 9.8-30.7A55 55 0 0 0 275 166a48.8 48.8 0 0 0-19.2-18.6c-7.3-4-16-6.9-26.2-8.6s-28.1-2.4-53.7-2.4h-62.3v227.2h64.2q38.7 0 55.8-2.6c11.4-1.8 20.9-4.8 28.6-8.9a52.5 52.5 0 0 0 21.9-21.4c5.1-9.2 7.7-19.9 7.7-32.1 0-16.9-4.5-30.4-13.6-40.5m-107-71.4h13.3q23.1 0 31 5.2c5.3 3.5 7.9 9.5 7.9 18s-2.9 14-8.5 17.4-16.1 5-31.4 5h-12.3zM224 317c-6.1 3.7-16.5 5.5-31.1 5.5h-21.7V273h22.6c15 0 25.4 1.9 30.9 5.7s8.4 10.4 8.4 20-3 14.7-9.2 18.4zm133.6-10.9a28.8 28.8 0 1 0 28.8 28.8 28.8 28.8 0 0 0-28.8-28.8m-25-169.7h50v151.52h-50z'/%3E%3C/svg%3E");background-repeat:no-repeat;background-size:contain}@media (any-hover:hover){.sns-share-btn._hatena[data-v-694562d6]:hover{background-color:#0091c8}}</style> <style>.sidebar{position:sticky;top:32px}.sidebarList{background-color:var(--color-bg-content-static);border-radius:8px;font-size:.75rem;line-height:1.5;list-style:none;max-height:calc(100vh - 96px);overflow:auto;padding:16px;position:relative;--color-bg-content-static:#fff;--color-contents-shadow:#0003}@media (prefers-color-scheme:dark){.sidebarList{--color-bg-content-static:#303030;--color-contents-shadow:#0006}}.sidebarList:before{background-color:var(--color-border);content:"";height:calc(100% - 64px);position:absolute;top:32px;width:1px}.sidebarList_item{color:var(--color-text-p-secondary);font-weight:700;padding-left:16px;position:relative;word-break:auto-phrase}.sidebarList_item:before{background-color:var(--color-btn-secondary);border:3px solid var(--color-bg-content-static);border-radius:50%;content:"";height:6px;left:-5.5px;position:absolute;top:6px;transition:background-color .3s;width:6px}@media (any-hover:hover){.sidebarList_item:hover:before{background-color:var(--primary)}}.sidebarList_item>a{display:inline-block;padding:4px 0;position:relative;transition:color .3s;width:100%}.sidebarList_item__sub{font-size:.75rem;font-weight:400}.sidebarList_item__sub:before{height:4px;left:-4.5px;top:8px;width:4px}.sidebarList_item__sub>a{padding-left:1em}.sidebarList_item.is-active>a{color:var(--primary)}.sidebarList_item.is-active:before{background-color:var(--primary)}@media (any-hover:hover){.sidebarList_item>a:hover{color:var(--primary)}}</style> <style>.SnsButtons[data-v-b5cbd36c]{padding-bottom:32px;padding-top:32px}.SnsButtons-sns[data-v-b5cbd36c]{display:flex;flex-flow:row wrap;gap:16px;justify-content:center}.SnsButtons-head[data-v-b5cbd36c],.SnsButtons-top[data-v-b5cbd36c]{text-align:center}.btn-sm[data-v-b5cbd36c]{align-items:center;display:flex;font-size:.875rem;gap:8px;padding:.25rem .5rem}</style> <style>.author-info[data-v-9742c4dd]{display:flex;margin:32px auto;max-width:640px}@media (max-width:767.98px){.author-info[data-v-9742c4dd]{padding-left:16px;padding-right:16px}}.author-info .btn[data-v-9742c4dd]{border:1px solid #0000;border-radius:.25rem;cursor:pointer;display:inline-block;font-size:1rem;font-weight:400;line-height:1.25;padding:.5rem 1rem;text-align:center;transition:all .2s ease-in-out;-webkit-user-select:none;user-select:none;vertical-align:middle;white-space:nowrap}.author-info .btn[data-v-9742c4dd],.author-info .btn[data-v-9742c4dd]:active,.author-info .btn[data-v-9742c4dd]:hover{-webkit-text-decoration:none;text-decoration:none}.author-info .btn-x[data-v-9742c4dd]{align-items:center;display:inline-flex;font-size:.75rem;padding:.1em .25em .1em .1em}.author-info .btn-x svg[data-v-9742c4dd]{margin-right:.25rem}.author-avatar[data-v-9742c4dd]{margin-right:24px}.author-avatar img[data-v-9742c4dd]{border-radius:50%}.author-avatar._large img[data-v-9742c4dd]{height:128px;width:128px}.author-desc[data-v-9742c4dd]{line-height:1.75}.author-desc-name[data-v-9742c4dd]{color:var(--color-text-h);display:flex;font-size:1.25rem;margin:0}@media (min-width:768px){.author-desc-name[data-v-9742c4dd]{align-items:center;gap:16px}}@media (max-width:767.98px){.author-desc-name[data-v-9742c4dd]{flex-direction:column;gap:4px}}.author-desc-script[data-v-9742c4dd]{color:var(--color-text-p);font-size:.9rem}.author-desc-script[data-v-9742c4dd] a{color:var(--color-text-a)}@media (any-hover:hover){.author-desc-script[data-v-9742c4dd] a:hover{color:var(--color-text-a-hover)}}.author-desc-script[data-v-9742c4dd] a:visited{color:var(--color-text-a-visited)}.is-inview img[data-v-9742c4dd]{view-transition-name:var(--475ed944)}</style> <style>.banner-img[data-v-84d78e6a]{border-radius:6px;height:auto;width:100%}@media (max-width:767.98px){.banner-img[data-v-84d78e6a]{border-radius:0}}.banners ul[data-v-84d78e6a]{display:grid;gap:1rem;grid-template-columns:repeat(2,1fr);list-style:none;padding:0}@media (max-width:767.98px){.banners ul[data-v-84d78e6a]{grid-template-columns:repeat(1,1fr)}}@media (any-hover:hover){.banners a[data-v-84d78e6a]:hover{filter:brightness(1.2)}}</style> <style>.related[data-v-c7eaaedb]{margin:64px 0}.related-in[data-v-c7eaaedb]{margin:0 auto;max-width:960px}@media (min-width:1200px){.related-in[data-v-c7eaaedb]{max-width:1080px}}@media (max-width:1199.98px){.related-in[data-v-c7eaaedb]{padding:0 1rem}}.related-in-head[data-v-c7eaaedb]{color:var(--color-text-h);font-family:var(--font-sans);font-feature-settings:"palt";font-size:1.5rem;font-weight:400;text-align:center}.related-in-ul[data-v-c7eaaedb]{display:grid;gap:1rem;grid-template-columns:1fr 1fr 1fr 1fr;list-style:none;margin:0;padding:0}@media (max-width:767.98px){.related-in-ul[data-v-c7eaaedb]{grid-template-columns:repeat(auto-fill,minmax(145px,1fr))}}.related-in-ul-li-thumb[data-v-c7eaaedb]{border-radius:6px;margin:0 0 10px;position:relative;transition:all .2s}.related-in-ul-li-thumb-img[data-v-c7eaaedb]{border-radius:6px;height:auto;width:100%}.related-in-ul-li-thumb[data-v-c7eaaedb]:after{border:2px solid #0000;border-radius:6px;box-sizing:border-box;content:"";display:block;height:100%;left:0;pointer-events:none;position:absolute;top:0;transition:border-color .2s;width:100%}.related-in-ul-li-title[data-v-c7eaaedb]{font-size:.9rem;line-height:1.5;text-align:left}.related-in-ul li a[data-v-c7eaaedb]{color:var(--color-text-p);display:block;-webkit-text-decoration:none;text-decoration:none}@supports (word-break:auto-phrase){.related-in-ul li a[data-v-c7eaaedb]{word-break:auto-phrase}}@media (any-hover:hover){.related-in-ul li a[data-v-c7eaaedb]:hover{color:var(--color-text-a-hover)}.related-in-ul li a:hover .related-in-ul-li-thumb[data-v-c7eaaedb]:after{border-color:var(--primary)}.related-in-ul li a:hover .related-in-ul-li-title[data-v-c7eaaedb]{-webkit-text-decoration:none;text-decoration:none}}</style> <style>.header-breadcrumb[data-v-b934bba3]{background:var(--color-bg);container-type:inline-size;top:0;width:100%;z-index:10}.header-breadcrumb__inner[data-v-b934bba3]{font-size:.75rem;margin:0 auto;max-width:960px}@container (1200px <= width){.header-breadcrumb__inner[data-v-b934bba3]{max-width:1080px}}@media (max-width:991.98px){.header-breadcrumb__inner[data-v-b934bba3]{padding-left:16px;padding-right:16px}}.header-breadcrumb__inner ul[data-v-b934bba3]{margin:0;overflow:hidden;padding:0;width:100%}.header-breadcrumb__inner ul li[data-v-b934bba3]{color:#ccc;display:inline;line-height:36px;margin-right:.5em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.header-breadcrumb__inner ul li a[data-v-b934bba3]{color:var(--color-text-p);line-height:inherit;-webkit-text-decoration:none;text-decoration:none;transition:all .3s}@media (any-hover:hover){.header-breadcrumb__inner ul li a[data-v-b934bba3]:hover{color:var(--color-text-a)}}.header-breadcrumb__inner ul li[data-v-b934bba3]:after{content:"/";margin-left:.5em}.header-breadcrumb__inner ul li[data-v-b934bba3]:last-child{margin-left:0}.header-breadcrumb__inner ul li[data-v-b934bba3]:last-child:after{content:""}.header-breadcrumb__inner ul li .date[data-v-b934bba3]{color:#888}.header-breadcrumb__inner nav[data-v-b934bba3]{line-height:36px;min-width:60px}@media (max-width:1199.98px){.header-breadcrumb__inner nav[data-v-b934bba3]{margin-right:10px}}</style> <link rel="stylesheet" href="/_nuxt/Logo.B08_Goey.css"> <link rel="stylesheet" href="/_nuxt/CopyrightFooter.QnetxqVn.css"> <link rel="stylesheet" href="/_nuxt/style.DVjyf-m9.css"> <link rel="stylesheet" href="/_nuxt/StaffItem.DNxbzzNe.css"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/BO3Z475_.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/DnTd6_Xj.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/DVSz8gjX.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/C-0LdZH-.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/nE6G2Gxl.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/DyrHuGZd.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/BrDd-etF.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/CenQKpRr.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/3M2JxWNy.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/CJSCuD5P.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/DXINm9ZB.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/C8gbhLzQ.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/dDIkWv_L.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/CDC-ftrr.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/C-Yk6U7k.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/DU2oTVfN.js"> <link rel="modulepreload" as="script" crossorigin href="/_nuxt/BTQRFAIC.js"> <link rel="dns-prefetch" href="https://ics-creative.github.io"> <link rel="prefetch" as="image" type="image/png" href="/_nuxt/logo-website.Cz5k_taM.png"> <meta name="referrer" content="unsafe-url"> <meta name="format-detection" content="telephone=no"> <meta name="author" content="株式会社ICS"> <meta name="color-scheme" content="light dark"> <meta name="theme-color" content="#eff2f5" media="(prefers-color-scheme: light)"> <meta name="theme-color" content="#202020" media="(prefers-color-scheme: dark)"> <meta name="apple-mobile-web-app-title" content="ICS MEDIA"> <meta name="apple-mobile-web-app-status-bar-style" content="default"> <link rel="icon" href="/_assets/icons/favicon.png"> <link rel="apple-touch-icon" href="/_assets/icons/apple-touch-icon.png"> <link rel="alternate" type="application/rss+xml" href="/feed/atom.xml"> <link rel="manifest" href="/_assets/manifest_static.json"> <link rel="author" href="http://www.hatena.ne.jp/ics-media/"> <meta name="description" content="Vite(ヴィート=フランス語で「速い」の意味)は2020年に発表された新しいフロントエンドのビルドツールです。"> <meta property="article:author" content="https://www.facebook.com/icswebjp"> <meta property="fb:pages" content="1414915712086775"> <meta property="og:locale" content="ja_JP"> <meta property="og:type" content="website"> <meta property="og:title" content="jQueryからTypeScript・Reactまで - Viteで始めるモダンで高速な開発環境構築 - ICS MEDIA"> <meta property="og:description" content="Vite(ヴィート=フランス語で「速い」の意味)は2020年に発表された新しいフロントエンドのビルドツールです。"> <meta property="og:url" content="https://ics.media/entry/210708/"> <meta property="og:site_name" content="ICS MEDIA"> <meta property="og:image" content="https://ics.media/entry/210708/images/eyecatch.png"> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:description" content="Vite(ヴィート=フランス語で「速い」の意味)は2020年に発表された新しいフロントエンドのビルドツールです。"> <meta name="twitter:title" content="jQueryからTypeScript・Reactまで - Viteで始めるモダンで高速な開発環境構築 - ICS MEDIA"> <meta name="twitter:image" content="https://ics.media/entry/210708/images/eyecatch.png"> <meta name="twitter:site" content="@icsweb"> <meta property="article:published_time" content="2021-07-08T00:00:00+09:00"> <meta property="article:modified_time" content="2022-01-21T00:00:00+09:00"> <meta property="og:updated_time" content="2022-01-21T00:00:00+09:00"> <meta name="date" content="2022-01-21T00:00:00+09:00"> <meta name="robots" content="max-image-preview:large"> <link rel="canonical" href="https://ics.media/entry/210708/"> <script type="application/ld+json">{"@context":"http://schema.org","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"https://ics.media/entry/210708/"},"headline":"jQueryからTypeScript・Reactまで - Viteで始めるモダンで高速な開発環境構築","image":{"@type":"ImageObject","url":"/entry/210708/images/eyecatch.png","height":512,"width":1280},"datePublished":"2021-07-08","dateModified":"2022-01-21","author":{"@type":"Organization","name":"株式会社ICS"},"publisher":{"@type":"Organization","name":"株式会社ICS","logo":{"@type":"ImageObject","url":"/_assets/icons/apple-touch-icon.png","width":512,"height":512}},"description":""}</script> <script type="module" src="/_nuxt/BO3Z475_.js" crossorigin></script></head><body><div id="__nuxt"><div class="ly-top" data-v-53af800e><div class="ly-top-header" data-v-53af800e><div class="mediaHeader" data-v-53af800e data-v-c016e82a><div class="mediaHeader-row" data-v-c016e82a><h1 data-v-c016e82a><a href="/" class="" title="ICS MEDIA" data-v-c016e82a data-v-39193113><span data-v-39193113>ICS MEDIA</span></a></h1><div class="mediaHeader-row-tool" data-v-c016e82a><span class="mediaHeader-row-tool-item mediaHeader-row-tool-item_search" data-v-c016e82a><a href="/entry/search/" class="" title="サイト内を検索する" data-v-c016e82a><svg width="32" height="32" viewBox="0 0 24 24" data-v-c016e82a><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" data-v-c016e82a></path><path d="M0 0h24v24H0z" fill="none" data-v-c016e82a></path></svg></a></span></div></div></div><nav class="category" categoryid data-v-53af800e data-v-5ddcd2fd><ul class="category-list" data-v-5ddcd2fd><!--[--><li class="category-list-item" data-v-5ddcd2fd><a href="/entry/category/design/" class="" data-v-5ddcd2fd>UIデザイナー</a></li><li class="category-list-item" data-v-5ddcd2fd><a href="/entry/category/html5/" class="" data-v-5ddcd2fd>HTMLコーダー</a></li><li class="category-list-item" data-v-5ddcd2fd><a href="/entry/category/frontend/" class="" data-v-5ddcd2fd>フロントエンジニア</a></li><li class="category-list-item" data-v-5ddcd2fd><a href="/entry/category/creative/" class="" data-v-5ddcd2fd>クリエイティブコーダー</a></li><li class="category-list-item" data-v-5ddcd2fd><a href="/entry/category/3d/" class="" data-v-5ddcd2fd>3Dデベロッパー</a></li><!--]--></ul></nav></div><div itemscope itemtype="http://schema.org/Article" style="display:none;" data-v-53af800e data-v-cb0dd5fc><div class="heroSpace_padding heroSpace" data-v-cb0dd5fc><iframe src="/_assets/top_hero/archives.html" width="100%" height="100%" tabindex="-1" aria-hidden="true" loading="lazy" data-v-cb0dd5fc></iframe><div class="heroSpace-title" data-v-cb0dd5fc><header data-v-cb0dd5fc><p data-v-cb0dd5fc><!--[--><!--]--></p><h1 itemprop="name" data-v-cb0dd5fc><!--[--><!--]--></h1></header></div></div></div><!--[--><div data-v-da421125><div class="eyecatch" data-v-da421125 style="--0e97d286:eyecatch-210708;" data-v-921b35f7><div class="eyecatch-blur-container" data-v-921b35f7><img class="eyecatch-blur" fetchpriority="high" src="/entry/210708/images/eyecatch.png" width="1280" height="512" alt="" data-v-921b35f7></div><div class="eyecatch-inner" data-v-921b35f7><img src="/entry/210708/images/eyecatch.png" alt="" width="1280" height="512" class="eyecatch-inner-img" fetchpriority="high" data-v-921b35f7></div></div><main class="wrap_960" data-v-da421125 data-v-49d92408><article data-v-49d92408><h2 class="article_title" data-v-49d92408 data-v-3469d367><small>jQueryからTypeScript・Reactまで!</small><br />Viteで始めるモダンで高速な開発環境構築</h2><div class="article-date" data-v-49d92408><!--[--><meta itemProp="datePublished" content="2021-07-08" data-v-d384dd23><span class="article-date-item" data-v-d384dd23><time itemProp="dateModified" dateTime="2022-01-21" title="2021年7月8日に公開" data-v-d384dd23>2022年1月21日</time> 更新</span><!--]--><span class="article-date-item article-date-slash" data-v-49d92408> / </span><a href="/entry/staff/matsumoto/" class="article-date-item" data-v-49d92408>株式会社ICS 松本 ゆき</a></div><ul class="article-tag" data-v-49d92408><!--[--><li data-v-49d92408><a href="/entry/tag/TypeScript/" class="" data-v-49d92408>TypeScript</a></li><li data-v-49d92408><a href="/entry/tag/Vue/" class="" data-v-49d92408>Vue</a></li><li data-v-49d92408><a href="/entry/tag/React/" class="" data-v-49d92408>React</a></li><!--]--></ul><div class="sns-share" data-v-49d92408 data-v-694562d6><div data-v-694562d6><a href="https://twitter.com/intent/tweet?url=https://ics.media/entry/210708/&text=jQueryからTypeScript・Reactまで - Viteで始めるモダンで高速な開発環境構築 - ICS MEDIA" class="sns-share-btn _x" target="_blank" title="X(旧Twitter)でシェア" data-v-694562d6></a><span class="sns-share-badge" data-v-694562d6>269</span></div><div data-v-694562d6><a class="sns-share-btn _hatena" href="https://b.hatena.ne.jp/entry/s/ics.media/entry/210708/" target="_blank" title="はてなブックマークでブックマーク" data-v-694562d6></a><span class="sns-share-badge" data-v-694562d6>561</span></div></div><div class="entry" data-v-49d92408><div class="entry-article article" data-v-49d92408><section data-v-49d92408><p>Vite(ヴィート=フランス語で「速い」の意味)は2020年に発表された新しいフロントエンドのビルドツールです。</p> <p>開発者がVue.jsの作者であるEvan You氏であるため、Vue.jsのツールであると誤解されることもありますが、プレーンなJavaScript(バニラJS)からVue.js・React・Svelteといった流行のフレームワークまで、さまざまな環境で利用できる汎用的なツールです。</p> <p>位置付けとしてはwebpackのようなバンドラーと呼ばれるものに近い存在ですが、それだけではありません。この記事では、Viteを導入してプレーンなJavaScriptから、TypeScript+Vue.js・Reactといったフレームワークまで、快適な開発環境を手に入れる方法を紹介します。</p> <p>この記事で紹介すること:</p> <ul> <li><a href="#contents-anchor-features">Viteの特徴と基本の仕組み</a></li> <li><a href="#contents-anchor-basic">基本の使い方</a></li> <li><a href="#contents-anchor-scss">Vite + SCSS</a></li> <li><a href="#contents-anchor-typescript">Vite + TypeScript</a></li> <li><a href="#contents-anchor-assets">Vite + アセット(画像など)</a></li> <li><a href="#contents-anchor-vue">Vite + TypeScript + Vue</a></li> <li><a href="#contents-anchor-react">Vite + TypeScript + React</a></li> <li><a href="#contents-anchor-config">設定のカスタマイズ</a></li> <li><a href="#contents-anchor-ie11">IE11に対応する方法</a></li> <li><a href="#contents-anchor-pitfalls">落とし穴と回避方法</a></li> </ul> <h3 id="contents-anchor-features">Viteの特徴と基本の仕組み</h3> <p>近年のウェブ開発では、JavaScriptファイルをすべて手書きしてHTMLファイルからひとつひとつ読み込む……といった作業をすることは少なくなりました。分割したモジュールの結合や圧縮を行う「ビルド」のため、なんらかのツールを使うことが多いでしょう。TypeScriptやSassのようなコンパイル(トランスパイル)が必要な言語を使うことも一般的になってきました。</p> <p>Viteはこのビルドで使用するツールです。簡単に特徴を紹介しましょう。</p> <h4 id="%E2%91%A0%E3%83%A2%E3%83%80%E3%83%B3%E3%83%96%E3%83%A9%E3%82%A6%E3%82%B6%E3%81%8C%E5%82%99%E3%81%88%E3%82%8B%E4%BB%95%E7%B5%84%E3%81%BF%EF%BC%88es-modules%E3%82%84dynamic-import%EF%BC%89%E3%82%92%E5%88%A9%E7%94%A8%E3%81%97%E3%81%A6%E9%AB%98%E9%80%9F%E3%81%AA%E8%B5%B7%E5%8B%95%2F%E6%9B%B4%E6%96%B0%E3%81%8C%E3%81%A7%E3%81%8D%E3%82%8B" tabindex="-1">①モダンブラウザが備える仕組み(ES modulesやDynamic import)を利用して高速な起動/更新ができる</h4> <p>Viteの何よりの売りが速さです。webpackを代表とする従来のツールは実行すると、プロジェクトのすべてのファイルをコンパイル・結合してバンドルと呼ばれるひと塊のプログラムを生成します。効率化の仕組みはありますが、概してプロジェクトが大きくなるほど、処理にかかる時間も長くなります。</p> <p>一方Viteは「ES modules」と呼ばれるモジュール分割の仕組みを使い、必要な時に必要なファイルだけをコンパイルしてブラウザーに送ります。この仕組みにより、<strong>大きなプロジェクトでも起動や更新が一瞬で(ほとんどのケースで数百ms)できます。</strong></p> <p>ES modulesはInternet Explorer 11(以下IE11)以外のほとんどのブラウザーで利用できます。標準の機能を利用することで、複雑な仕組みを導入せずとも高速化ができるのです。</p> <h4 id="%E2%91%A1typescript%E3%82%84vue%2Freact%E7%AD%89%E3%81%AE%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%81%8C%E8%A8%AD%E5%AE%9A%E3%81%AA%E3%81%97%E3%81%A7%E3%81%99%E3%81%90%E3%81%AB%E4%BD%BF%E3%81%88%E3%82%8B" tabindex="-1">②TypeScriptやVue/React等のライブラリが設定なしですぐに使える</h4> <p>Viteの主要なコンセプトは「out of the box(箱から出してすぐに使える)」です。この後紹介しますが、Viteではほとんどの一般的な開発で面倒な設定が不要です。<strong>シンプルなJavaScriptだけのウェブページからVue.jsとTypeScriptを使った本格的なウェブアプリケーションまで</strong>、ほとんど同じ早さで開発を始めることができるのです。</p> <p>また、ホットリロード(開発中にファイルを変更すると差分を検知してブラウザーをリロードしてくれる機能)に標準で対応しているのもありがたいポイントです。</p> <h4 id="%E2%91%A2ie%E3%82%92%E5%90%AB%E3%82%81%E3%81%9F%E3%83%97%E3%83%AD%E3%83%80%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%93%E3%83%AB%E3%83%89%E3%82%82%E3%81%A7%E3%81%8D%E3%82%8B" tabindex="-1">③IEを含めたプロダクションビルドもできる</h4> <p>さきほどの説明でViteがIE11では使えないと聞いて、ちょっとがっかりした方もいるかもしれません。確かにViteを使った開発(デバッグ起動)はIE11ではできません。しかし、ビルドした結果はIE11でも動かすことができます。</p> <p>Viteは開発時にはモダンブラウザーのES modulesを使って高速に動作しますが、最終的にビルドする際は従来型のバンドラーと同様、すべてのファイルをひとつにまとめてくれるためです(具体的には、ビルド時は内部的に<a href="https://rollupjs.org/" target="_blank">rollup.js</a>を使用しています)。</p> <p>IE11向けのビルドには追加の設定が必要なので、この記事の後半で解説します。新しいツールではありますが、<strong>プロダクションでも安心して利用できる</strong>と言えるでしょう。</p> <h3 id="contents-anchor-basic">基本の使い方</h3> <p>Viteの使い方はとても簡単です。まずはフレームワークを使わないプレーンなHTML+JavaScriptのウェブページをViteで作ってみましょう。</p> <p>※ この記事では2021年7月時点の最新版であるバージョン2.4をベースに解説します。</p> <h4 id="%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE%E5%88%9D%E6%9C%9F%E5%8C%96" tabindex="-1">プロジェクトの初期化</h4> <p>プロジェクトを作成するため、ターミナル(コマンドプロンプト)で、以下のコマンドを実行します。Viteを事前にインストールする必要はありません。</p> <pre><code class="hljs language-sh">npm init vite@latest </code></pre> <p><code>npm</code>の代わりに<code>yarn</code>を使う場合は<code>yarn create</code>になります。</p> <pre><code class="hljs language-sh">yarn create vite </code></pre> <p>実行すると、「プロジェクト名」「フレームワーク(テンプレート)」「テンプレートのバリエーション」の3つの質問が表示されます。ここでは下の要領で一番シンプルなバニラJSを指定します。</p> <pre><code class="hljs language-sh">? Project name: › hello-vite <span class="hljs-comment"># ①プロジェクト名を入力</span> ? Select a framework: › - Use arrow-keys. Return to submit. ❯ vanilla <span class="hljs-comment"># ②フレームワークを選択(vanilla = フレームワークを使わない)</span> vue react preact lit-element svelte ? Select a variant: › - Use arrow-keys. Return to submit. ❯ vanilla <span class="hljs-comment"># ③バリエーションを選択(TypeScriptは使わない)</span> vanilla-ts </code></pre> <p>作成したプロジェクトは次のような構成になっているはずです。</p> <p><img srcset="/entry/210708/images/210708_dir_vanilla.png 1920w, /entry/210708/images/210708_dir_vanilla__960.png 960w" src="/entry/210708/images/210708_dir_vanilla.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="作成したプロジェクトの構成(バニラJS)" loading="lazy"></img></p> <h4 id="%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E8%B5%B7%E5%8B%95" tabindex="-1">デバッグ起動</h4> <p>以下のようにプロジェクトのディレクトリで<code>npm install</code>と<code>npm run dev</code>を実行すると、開発サーバが起動して動作が確認できるようになります。</p> <pre><code class="hljs language-sh"><span class="hljs-built_in">cd</span> hello-vite <span class="hljs-comment"># ①作成したプロジェクトのフォルダに移動</span> npm install <span class="hljs-comment"># ②モジュールインストールを実行(初回のみ)</span> <span class="hljs-comment"># ... インストール(出力は省略)</span> npm run dev <span class="hljs-comment"># ③開発サーバを起動</span> Vite v2.3.6 dev server running at: > Local: http://localhost:3000/ <span class="hljs-comment"># ... このURLをブラウザーで開く</span> > Network: use `--host` to expose ready <span class="hljs-keyword">in</span> 95ms. </code></pre> <p>この状態で、<code>main.js</code>を編集・保存してブラウザーを見てみましょう。ホットリロードによって即座に変更が反映されるはずです。</p> <p>▼ Viteを起動してファイルを編集する様子。一瞬でブラウザーに変更が反映されている</p> <p><img srcset="/entry/210708/images/210708_hotreload-demo.gif 1920w" src="/entry/210708/images/210708_hotreload-demo.gif" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="ホットリロードのデモ" loading="lazy"></img></p> <h4 id="%E3%83%93%E3%83%AB%E3%83%89" tabindex="-1">ビルド</h4> <p>ビルドするには<code>build</code>コマンドを実行します。</p> <pre><code class="hljs language-sh">npm run build </code></pre> <p>ビルド結果は<code>dist</code>ディレクトリーに出力されます。</p> <h4 id="vite%E3%81%AE%E3%81%BF%EF%BC%88%E3%83%90%E3%83%8B%E3%83%A9js%3D%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AF%E3%81%AA%E3%81%97%EF%BC%89%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB" tabindex="-1">Viteのみ(バニラJS=フレームワークなし)のサンプル</h4> <p>Viteの基本的な構成を使用して、TODOアプリのサンプルを作成しました。</p> <p><img srcset="/entry/210708/images/210708_demo_vanilla.png 1920w, /entry/210708/images/210708_demo_vanilla__960.png 960w" src="/entry/210708/images/210708_demo_vanilla.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="Vite + バニラJSのサンプル" loading="lazy"></img></p> <ul> <li><a href="https://ics-creative.github.io/210708_vite/vite-vanilla-js-jquery/" target="_blank">サンプルを別ウインドウで開く</a></li> <li><a href="https://github.com/ics-creative/210708_vite/tree/main/vite-vanilla-js-jquery" target="_blank">コードを確認する</a></li> </ul> <p>この例では、DOMの操作を簡単にするため、以下のコマンドでjQueryを追加しています。</p> <pre><code class="hljs language-sh">npm install jquery </code></pre> <p>バニラJS + jQueryと聞くと「モダンではない」「開発体験が悪そう」といった印象を持たれるかもしれません。しかし、Viteを使うことで、ソースコードの分割や高速なホットリロードが行え、フレームワークを使用せずとも快適な開発ができるようになります。ぜひ、サンプルをクローンしてViteでの開発を体感してみてください。</p> <h3 id="contents-anchor-scss">Vite + Sass(SCSS)</h3> <p>バニラJSで作成したプロジェクトの<code>main.js</code>を見ると次のようにしてCSSを読み込んでいることがわかります(もちろん、<code>index.html</code>から<code><link></code>タグを使って読み込んでも構いません)。</p> <pre><code class="hljs language-js"><span class="hljs-keyword">import</span> <span class="hljs-string">'./style.css'</span> </code></pre> <p>簡単な作業でこのCSSをSass(SCSS)に変更できます。まず、<code>sass</code>モジュールをインストールしましょう。</p> <pre><code class="hljs language-sh">npm install -D sass </code></pre> <p>インストールが完了したら、<code>style.css</code>を<code>style.scss</code>にリネームし、<code>main.js</code>の<code>import</code>文も変更します。Viteは標準で<code>.scss</code>の拡張子を認識するので、これだけで<code>sass</code>モジュールを使用してCSSのコンパイルをしてくれるようになります。</p> <h3 id="contents-anchor-typescript">Vite + TypeScript</h3> <p>ViteではTypeScriptも簡単に利用できます。<code>npm init vite@latest</code>でプロジェクトを作成し、最後の質問で<code>vanilla-ts</code>を選択するだけです。</p> <pre><code class="hljs language-sh">npm init vite@latest ? Project name: › hello-vite-ts <span class="hljs-comment"># ①プロジェクト名を入力</span> ? Select a framework: › - Use arrow-keys. Return to submit. ❯ vanilla <span class="hljs-comment"># ②フレームワークを選択(vanilla = フレームワークを使わない)</span> vue react preact lit-element svelte ? Select a variant: › - Use arrow-keys. Return to submit. vanilla ❯ vanilla-ts <span class="hljs-comment"># ③TypeScriptを使用する</span> </code></pre> <p>作成されたプロジェクトの構造は次のようになっています。TypeScriptの設定をおこなう<code>tsconfig.json</code>も作成済みです。必要に応じて修正すると良いでしょう。</p> <p><img srcset="/entry/210708/images/210708_dir_ts.png 1920w, /entry/210708/images/210708_dir_ts__960.png 960w" src="/entry/210708/images/210708_dir_ts.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="作成したプロジェクトの構成(TypeScript)" loading="lazy"></img></p> <h4 id="vite-%2B-typescript%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB" tabindex="-1">Vite + TypeScriptのサンプル</h4> <p>Vite + TypeScriptのサンプルとして、3D表現制作の定番ライブラリである<a href="https://threejs.org/" target="_blank">Three.js</a>を組み込んだデモを作成しました。</p> <p><img srcset="/entry/210708/images/210708_demo_ts.png 1920w, /entry/210708/images/210708_demo_ts__960.png 960w" src="/entry/210708/images/210708_demo_ts.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="Vite + TypeScript + Three.jsのサンプル" loading="lazy"></img></p> <ul> <li><a href="https://ics-creative.github.io/210708_vite/vite-typescript-three/" target="_blank">サンプルを別ウインドウで開く</a></li> <li><a href="https://github.com/ics-creative/210708_vite/tree/main/vite-typescript-three" target="_blank">コードを確認する</a></li> </ul> <p><code>npm init vite@latest</code>コマンドでTypeScriptのプロジェクトを作成した後、以下のコマンドでThree.jsと型定義をインストールするだけです。</p> <pre><code class="hljs language-sh">npm install three @types/three </code></pre> <p>サンプルの中でThree.jsを利用する部分は、入門記事<a href="https://ics.media/entry/14771/">『Three.js入門 - 手軽にWebGLを扱える3Dライブラリ』</a>で解説しています。Three.jsは慣れるまでが大変ですが、TypeScriptのサポートとViteの素早い起動や更新は、学習するときにも強い味方となるはずです。</p> <h3 id="contents-anchor-assets">Vite + アセット(画像など)</h3> <p>上で作成した「Vite + TypeScript」のプロジェクトで画像等のアセットを使う方法を確認しましょう。webpackではTypeScriptからアセットを利用するためにやや面倒な設定が必要でしたが、Viteの場合は簡単です。</p> <h4 id="javascript%2Ftypescript%E3%81%8B%E3%82%89%E7%94%BB%E5%83%8F%E3%82%92%E8%AA%AD%E3%81%BF%E8%BE%BC%E3%82%80" tabindex="-1">JavaScript/TypeScriptから画像を読み込む</h4> <p>JavaScript/TypeScriptから画像を読み込むには、その画像のパスを<code>import</code>するだけです。画像を<code>import</code>するとViteではその画像の実際のパス(URL)を返します。ビルドを行うと、画像ファイルは1カ所にまとめられてファイル名も変更されますが、<code>import</code>したURLでアクセスする限り、何も気にする必要はありません。</p> <p>下の例では<code>dog.png</code>と<code>cat.png</code>の2枚の画像を<code>import</code>し、ボタンを押すたびにどちらかをランダムに追加します。</p> <pre><code class="hljs language-ts"><span class="hljs-comment">// 開発時・ビルド時の状態にかかわらず、適切な画像パスが取得できる</span> <span class="hljs-keyword">import</span> srcDog <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/dog.png'</span> <span class="hljs-keyword">import</span> srcCat <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/cat.png'</span> <span class="hljs-comment">// 犬か猫をランダムに追加</span> <span class="hljs-keyword">const</span> <span class="hljs-title function_">addImage</span> = (<span class="hljs-params"></span>) => { <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Image</span>() img.<span class="hljs-property">src</span> = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">random</span>() > <span class="hljs-number">0.5</span> ? srcDog : srcCat <span class="hljs-variable language_">document</span>.<span class="hljs-property">body</span>.<span class="hljs-title function_">appendChild</span>(img) } <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'addButton'</span>).<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">'click'</span>, addImage) </code></pre> <h4 id="%E9%9D%99%E7%9A%84%E3%81%AA%E7%94%BB%E5%83%8F%E3%81%AE%E5%88%A9%E7%94%A8" tabindex="-1">静的な画像の利用</h4> <p>画像のファイル名を実行時に組み立てる場合など、<code>import</code>でパスを指定できない場合には<code>public</code>ディレクトリを使うことができます。</p> <p>プロジェクトルートに<code>public</code>というディレクトリを作成し、画像等のアセットを格納しておくと、それらはビルド時に単純に出力先(<code>dist</code>ディレクトリの直下)にコピーされます。</p> <pre><code class="hljs language-ts"><span class="hljs-comment">// publicディレクトリに入れたimg.pngを表示する</span> <span class="hljs-comment">// パスに"public"はいらないことに注意</span> img.<span class="hljs-property">src</span> = <span class="hljs-string">'img.png'</span> </code></pre> <h4 id="vite-%2B-typescript-%2B-%E3%82%A2%E3%82%BB%E3%83%83%E3%83%88%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB" tabindex="-1">Vite + TypeScript + アセットのサンプル</h4> <p>Vite + TypeScriptのプロジェクトで上記の2通りの画像読み込みを行うサンプルを作成しました。ビルド結果のデモの動作をソースコードと比較し、それぞれの画像読み込みがビルド時にどのように変換されるのか、理解しておくと良いでしょう。</p> <p>▼ assetsフォルダーからimportする例 <img srcset="/entry/210708/images/210708_demo_assets1.png 1920w, /entry/210708/images/210708_demo_assets1__960.png 960w" src="/entry/210708/images/210708_demo_assets1.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="Vite + TypeScript + アセットのサンプル(assetsフォルダーからimportする例)" loading="lazy"></img></p> <p>▼ publicフォルダーを使う例 <img srcset="/entry/210708/images/210708_demo_assets2.png 1920w, /entry/210708/images/210708_demo_assets2__960.png 960w" src="/entry/210708/images/210708_demo_assets2.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="Vite + TypeScript + アセットのサンプル(publicフォルダーを使う例)" loading="lazy"></img></p> <ul> <li><a href="https://ics-creative.github.io/210708_vite/vite-typescript-assets/" target="_blank">サンプルを別ウインドウで開く</a></li> <li><a href="https://github.com/ics-creative/210708_vite/tree/main/vite-typescript-assets" target="_blank">コードを確認する</a></li> </ul> <h3 id="contents-anchor-vue">Vite + TypeScript + Vue</h3> <p>現代でウェブアプリケーションを開発する場合、何かしらのJavaScriptフレームワークを利用することが多いでしょう。Viteでは標準のテンプレートとして<a href="https://ja.vuejs.org/" target="_blank">Vue.js</a>・<a href="https://ja.reactjs.org/" target="_blank">React</a>・<a href="https://preactjs.com/" target="_blank">Preact</a>・<a href="https://lit-element.polymer-project.org/" target="_blank">LitElement</a>・<a href="https://svelte.dev/" target="_blank">Svelte</a>といったメジャーなフレームワークを利用できます。また、標準提供のテンプレート以外にも、さまざまなテンプレートが公開されています。気になる方は<a href="https://github.com/vitejs/awesome-vite#templates" target="_blank">『Awesome Vite.js』</a>をチェックしてみると良いでしょう。</p> <p>とくに<code>Vue</code>については、作者が同じであることから完成度の高いテンプレートが標準提供されています。<code>Vue</code>でプロジェクトを作る場合は、以下のようにフレームワークを選択します。</p> <pre><code class="hljs language-sh">npm init vite@latest ? Project name: › hello-vite-vue <span class="hljs-comment"># ①プロジェクト名を入力</span> ? Select a framework: › - Use arrow-keys. Return to submit. vanilla ❯ vue <span class="hljs-comment"># ②フレームワークとしてVueを選択</span> ... ? Select a variant: › - Use arrow-keys. Return to submit. vue ❯ vue-ts <span class="hljs-comment"># ③TypeScriptを使用する</span> </code></pre> <p>フレームワークを使用しない場合と同様、<code>npm run dev</code>(または<code>yarn dev</code>)でデバッグ起動ができます。<code>Vue CLI</code>を使って開発したことのある方であれば、起動や更新の早さに驚くでしょう。</p> <pre><code class="hljs language-sh"><span class="hljs-built_in">cd</span> hello-vite-vue npm install <span class="hljs-comment"># モジュールインストール(初回のみ)</span> npm run dev <span class="hljs-comment"># デバッグ起動</span> npm run build <span class="hljs-comment"># ビルド</span> </code></pre> <h4 id="vuex%E3%82%84vue-router%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B" tabindex="-1">VuexやVue Routerを追加する</h4> <p>ViteのVueテンプレートはとてもシンプルな構成のため、VuexやVue Routerを使いたい場合には自分で追加の導入作業が必要です。どちらも<code>npm install</code>で簡単に追加できます。</p> <pre><code class="hljs language-sh"><span class="hljs-comment"># Vuexを追加。2021/7時点ではVue3対応版のVuex4系は@nextが必要です</span> npm install vuex@next <span class="hljs-comment"># Vue Routerを追加。こちらも2021/7時点では@4の指定が必要です</span> npm install vue-router@4 </code></pre> <h4 id="vite-%2B-typescript-%2B-vue%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB" tabindex="-1">Vite + TypeScript + Vueのサンプル</h4> <p>Vite + TypeScript + Vueのプロジェクトを作成しました。VuexとVue Routerも最小限機能するものを組み込んでいますので、セットアップの参考にしてください。</p> <p><img srcset="/entry/210708/images/210708_demo_vue.png 1920w, /entry/210708/images/210708_demo_vue__960.png 960w" src="/entry/210708/images/210708_demo_vue.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="Vite + TypeScript + Vueのサンプル" loading="lazy"></img></p> <ul> <li><a href="https://ics-creative.github.io/210708_vite/vite-typescript-vue/" target="_blank">サンプルを別ウインドウで開く</a></li> <li><a href="https://github.com/ics-creative/210708_vite/tree/main/vite-typescript-vue" target="_blank">コードを確認する</a></li> </ul> <h3 id="contents-anchor-react">Vite + TypeScript + React</h3> <p>ViteではVue.jsと同様、Reactも簡単に使うことができます。Reactでプロジェクトを作る場合は、以下のようにフレームワークを選択します。</p> <pre><code class="hljs language-sh">npm init vite@latest ? Project name: › hello-vite-react <span class="hljs-comment"># ①プロジェクト名を入力</span> ? Select a framework: › - Use arrow-keys. Return to submit. vanilla vue ❯ react <span class="hljs-comment"># ②フレームワークとしてReactを選択</span> ... ? Select a variant: › - Use arrow-keys. Return to submit. react ❯ react-ts <span class="hljs-comment"># ③TypeScriptを使用する</span> </code></pre> <p>プロジェクト作成後の起動やビルドのコマンドはフレームワークを使わない場合と変わりません。</p> <pre><code class="hljs language-sh"><span class="hljs-built_in">cd</span> hello-vite-react npm install <span class="hljs-comment"># モジュールインストール(初回のみ)</span> npm run dev <span class="hljs-comment"># デバッグ起動</span> npm run build <span class="hljs-comment"># ビルド</span> </code></pre> <p>なお、2021年後半にリリースされた<a href="https://github.com/vuejs/create-vue" target="_blank">create-vue</a>を使用すると、Vite + Vueのプロジェクトを公式の推薦構成で自動セットアップしてくれます。構築したプロジェクトの使い方や設定の方法はcreate-vueを使った場合も変わりません。create-vueを含めた公式の推薦構成については<a href="https://ics.media/entry/220120/">『2022年の最新標準! Vue 3の新しい開発体験に触れよう』</a>で紹介していますので、参考にしてください。</p> <h4 id="jsx%2Ftsx%E3%82%92%E4%BD%BF%E3%81%86%E5%A0%B4%E5%90%88%E3%81%AE%E6%B3%A8%E6%84%8F" tabindex="-1">jsx/tsxを使う場合の注意</h4> <p>Viteで作成したReactプロジェクトでも、jsxやtsxを問題なく扱うことができます(jsxやtsxはReactだけでなくVue.jsのプロジェクトでも利用できます)。ただし、React17でサポートされた<a href="https://ja.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html" target="_blank">新しい JSX トランスフォーム</a>には対応していないため、若干注意が必要です。</p> <p>Reactでjsx/tsxを使う場合、React16までは<code>import React from 'react'</code>の形で<code>react</code>モジュールを読み込む必要がありました。</p> <pre><code class="hljs language-tsx"><span class="hljs-keyword">import</span> <span class="hljs-title class_">React</span> <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span> <span class="hljs-comment">// ←"React"はコードには出てこないが必要</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">App</span>(<span class="hljs-params"></span>) { <span class="hljs-keyword">return</span> <span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">h1</span>></span>Hello Vite + React!<span class="hljs-tag"></<span class="hljs-name">h1</span>></span></span> } </code></pre> <p>React17の「新しいJSXトランスフォーム」では<code>webpack</code>を使うことで、この<code>import</code>が不要になりました。しかしViteはこの機能に対応していないため、引き続き<code>import</code>が必須です。</p> <p>どうしても<code>import</code>なしでjsx/tsxを使用したい場合、プロジェクトのルートに<code>vite.config.ts</code>という名前の設定ファイルを作成し、以下のように記述することで同等の結果を得ることができます。</p> <p>▼ vite.config.ts</p> <pre><code class="hljs language-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> { <span class="hljs-attr">esbuild</span>: { <span class="hljs-attr">jsxInject</span>: <span class="hljs-string">`import React from 'react'`</span> } } </code></pre> <p>設定ファイルについては次の節で詳しく紹介します。</p> <h3 id="contents-anchor-config">設定のカスタマイズ</h3> <p>冒頭で紹介した通り、Viteのコンセプトは「out of the box(箱から出してすぐに使えること)」です。ここまでの例で紹介したように、テンプレートを選択するだけで十分実用的な開発環境が手に入ります。</p> <p>しかし、実際のプロダクト開発や業務利用では、設定のカスタマイズが必要なことも少なくありません。このような時はプロジェクトのルートディレクトリに<code>vite.config.js</code>(TypeScriptのプロジェクトであれば<code>vite.config.ts</code>)というファイルを作成することで設定のカスタマイズが可能です。</p> <p><code>vite.config.ts</code>ファイルの中身は、基本的には<code>export default {}</code>の形式で設定を記述するだけです。以下のように<code>defineConfig</code>関数を挟むとエディターの補完や型チェックが効くようになるのでオススメです。</p> <p>▼ vite.config.ts</p> <pre><code class="hljs language-ts"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span> <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title function_">defineConfig</span>({ <span class="hljs-comment">// ここに設定を追加</span> }) </code></pre> <p>設定可能な項目は<a href="https://vitejs.dev/config/" target="_blank">公式の『Configuring Vite』</a>に掲載されています。かなりの数になるので、よく使う基本の設定をいくつか紹介しましょう。</p> <h4 id="server.port%EF%BC%9A%E9%96%8B%E7%99%BA%E6%99%82%E3%81%AE%E3%83%9D%E3%83%BC%E3%83%88%E7%95%AA%E5%8F%B7%E8%A1%9D%E7%AA%81%E3%82%92%E9%81%BF%E3%81%91%E3%82%8B" tabindex="-1">server.port:開発時のポート番号衝突を避ける</h4> <p>Viteの開発サーバはデフォルトで<code>3000</code>番ポートを使用します。ポートが使用中の場合は自動的に空いている他のポートを使用しますが、無用な混乱を割けるためにも、複数のプロジェクトを同時に扱う場合にはポート番号を決めておくのも良いでしょう。</p> <p>▼ 例:vite.config.tsでポート番号を8080にする</p> <pre><code class="hljs language-ts"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span> <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title function_">defineConfig</span>({ <span class="hljs-attr">server</span>: { <span class="hljs-attr">port</span>: <span class="hljs-number">8080</span> } }) </code></pre> <p>なお、一時的に変更したいだけであれば、コマンドラインオプションを使用して<code>npm run dev -- --port 12345</code>のように指定することもできます。</p> <h4 id="base%EF%BC%9A%E3%80%8C%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4%E3%81%97%E3%81%9F%E3%82%89%E7%94%BB%E9%9D%A2%E3%81%8C%E5%87%BA%E3%81%AA%E3%81%84%E3%80%8D%E5%95%8F%E9%A1%8C%E3%82%92%E5%9B%9E%E9%81%BF" tabindex="-1">base:「デプロイしたら画面が出ない」問題を回避</h4> <p>Viteではスクリプトや画像等のリソースを読み込む時、<code>/</code>で始まる絶対URLを使用します。GitHub Pagesのようにデプロイ先がウェブサーバーのルートディレクトリではない場合、この設定を変更しないと画面が表示されません。</p> <p>この挙動を変更するのが<code>base</code>です。<code>base</code>には任意のURLを指定できますが、下の例のように<code>./</code>を指定するのが柔軟で良いでしょう。</p> <p>▼ 例:vite.config.tsでbaseに相対パスを指定する</p> <pre><code class="hljs language-ts"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span> <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title function_">defineConfig</span>({ <span class="hljs-attr">base</span>: <span class="hljs-string">'./'</span> }) </code></pre> <h4 id="resolve.alias%EF%BC%9Aimport%E3%81%99%E3%82%8B%E3%83%91%E3%82%B9%E3%81%A7%40components%2F%E3%81%AE%E3%82%88%E3%81%86%E3%81%AA%E3%82%A8%E3%82%A4%E3%83%AA%E3%82%A2%E3%82%B9%E5%90%8D%E3%82%92%E4%BD%BF%E3%81%88%E3%82%8B%E3%82%88%E3%81%86%E3%81%AB%E3%81%99%E3%82%8B" tabindex="-1">resolve.alias:importするパスで<code>@components/</code>のようなエイリアス名を使えるようにする</h4> <p>Vue CLIで作成したプロジェクトでは、デフォルトで<code>import HelloWorld from '@/components/HelloWorld.vue'</code>のような、<code>@/</code>で始まるパスを利用できました。Viteで同じ機能を利用するには、<code>resolve.alias</code>の設定が必要です。</p> <p>▼ vue-tsテンプレートで作成したプロジェクトのvite.config.tsにエイリアスの設定を追加する</p> <pre><code class="hljs language-ts"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span> <span class="hljs-keyword">import</span> vue <span class="hljs-keyword">from</span> <span class="hljs-string">'@vitejs/plugin-vue'</span> <span class="hljs-keyword">import</span> path <span class="hljs-keyword">from</span> <span class="hljs-string">'path'</span> <span class="hljs-comment">// https://vitejs.dev/config/</span> <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title function_">defineConfig</span>({ <span class="hljs-attr">plugins</span>: [<span class="hljs-title function_">vue</span>()], <span class="hljs-attr">resolve</span>: { <span class="hljs-attr">alias</span>: { <span class="hljs-string">'@/'</span>: path.<span class="hljs-title function_">join</span>(__dirname, <span class="hljs-string">'./src/'</span>) } } }) </code></pre> <p>上記はVue.jsのプロジェクトの例ですが、Vue以外のフレームワークを使う場合も設定は同様です。</p> <p>※ 以前のバージョンでは<code>alias</code>は設定のルート階層にありましたが、現在ではdeprecatedになっています。<code>resolve.alias</code>を使用しましょう。</p> <h3 id="contents-anchor-ie11">IE11に対応する方法</h3> <p>IE11向けのビルドを作成するには、ビルドに追加の設定が必要です。幸い、ほとんどの設定は<a href="https://github.com/vitejs/vite/tree/main/packages/plugin-legacy" target="_blank">@vitejs/plugin-legacy</a>というプラグインがまとめて提供しています。以下のコマンドでインストールします。</p> <pre><code class="hljs language-sh"><span class="hljs-comment"># IE11向けビルドを行うプラグインを追加</span> npm install -D @vitejs/plugin-legacy </code></pre> <p>インストールができたら、設定ファイルにこのプラグインを使用する記述を追加します。</p> <p>▼ vite.config.ts(JavaScriptの場合はvite.config.js)</p> <pre><code class="hljs language-ts"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span> <span class="hljs-keyword">import</span> legacy <span class="hljs-keyword">from</span> <span class="hljs-string">'@vitejs/plugin-legacy'</span> <span class="hljs-comment">// https://vitejs.dev/config/</span> <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title function_">defineConfig</span>({ <span class="hljs-comment">// IE11向けの変換を行うプラグインの設定</span> <span class="hljs-attr">plugins</span>: [ <span class="hljs-title function_">legacy</span>({ <span class="hljs-attr">targets</span>: [<span class="hljs-string">'ie >= 11'</span>], <span class="hljs-attr">additionalLegacyPolyfills</span>: [<span class="hljs-string">'regenerator-runtime/runtime'</span>] }) ] }) </code></pre> <p>あとは今まで同様、<code>npm run build</code>でビルドするだけです。</p> <h4 id="%E3%81%99%E3%81%B9%E3%81%A6%E3%81%8C%E5%A4%89%E6%8F%9B%E3%81%A7%E3%81%8D%E3%82%8B%E3%82%8F%E3%81%91%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%84%E3%81%AE%E3%81%A7%E6%B3%A8%E6%84%8F%EF%BC%81" tabindex="-1">すべてが変換できるわけではないので注意!</h4> <p>プラグインを使用することで簡単にIE11向けのビルドを作成できるようになりますが、対応できるのはあくまで古い構文(ES5)への変換やポリフィルの使用でサポートできる範囲です。これはwebpack等他のツールを使用した場合と基本的には変わりません。</p> <p>たとえば、ViteでVue.jsのプロジェクトを作成すると、デフォルトではVue3を使用します。しかしVue3はIE11に対応していないため、このプラグインを使用してもIE11では動かすことはできません。このような場合は、IE11でも動作可能なVue2を使用するなど、個別の対応が必要になります。</p> <p>使用するライブラリやフレームワークごとにIE11向けの変換が可能か、確認した上で導入するようにしましょう。</p> <h4 id="ie11%E5%AF%BE%E5%BF%9C%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB" tabindex="-1">IE11対応のサンプル</h4> <p>Vite + TypeScript + jQueryで作成し、IEでも動作するように設定・ビルドしたサンプルを作成しました。内容は最初のバニラJSのサンプルと同様のTODOリストです。IEで動作させた場合だけ「legacy」と名前のついた別のJavaScriptファイルを読み込んで動作していることがわかります。</p> <p>▼ IE向けビルドの動作例(左:IE11 / 右:Chromium版Edge) <img srcset="/entry/210708/images/210708_demo_ie.png 1920w, /entry/210708/images/210708_demo_ie__960.png 960w" src="/entry/210708/images/210708_demo_ie.png" sizes="(max-width:720px) 100vw, 720px" width="1920" height="1080" alt="Vite + TypeScript + アセットのサンプル(assetsフォルダーからimportする例)" loading="lazy"></img></p> <ul> <li><a href="https://ics-creative.github.io/210708_vite/vite-typescript-ie/" target="_blank">サンプルを別ウインドウで開く</a></li> <li><a href="https://github.com/ics-creative/210708_vite/tree/main/vite-typescript-ie" target="_blank">コードを確認する</a></li> </ul> <h3 id="contents-anchor-pitfalls">落とし穴と回避方法</h3> <p>Viteは簡単で高速な開発体験を提供してくれますが、落とし穴がないわけではありません。注意すべきケースと回避方法を紹介します。</p> <h4 id="%E3%82%B1%E3%83%BC%E3%82%B91%EF%BC%9A%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83%E3%81%A7%E3%81%AF%E5%8B%95%E3%81%84%E3%81%A6%E3%81%84%E3%82%8B%E3%81%AE%E3%81%AB%E3%80%81%E3%83%93%E3%83%AB%E3%83%89%E3%81%99%E3%82%8B%E3%81%A8%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%AB%E3%81%AA%E3%82%8B" tabindex="-1">ケース1:開発環境では動いているのに、ビルドするとエラーになる</h4> <p>冒頭で紹介した通り、Viteの開発サーバは必要な時に必要なソースコードだけを読み込んでコンパイルすることで高速な起動や更新を実現しています。逆にいうと、文法誤りのような明らかな問題があっても、画面から要求されない限りエラーとして検出されません。</p> <p>通常の開発では、エディターでソースコードを書き換えた時点で、エディター上にエラーが表示されて間違いに気づくことができるので、大きな問題になることはないでしょう。しかし、エディター以外のツールでソースコードを触ってしまったり、機械的な一括置換でコードを修正してしまったりすると、この限りではありません。このままでは<strong>ビルドの通らないコードがコミット・プッシュされることになり大変危険です。</strong></p> <p><strong>対処</strong> <a href="https://git-scm.com/book/ja/v2/Git-%E3%81%AE%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA-Git-%E3%83%95%E3%83%83%E3%82%AF" target="_blank">Gitフック</a>やCIを使用して、コミットやプッシュ・マージの前に最低限ビルドが通ることを確認すると良いでしょう。TypeScriptの型チェックが目的であれば、これらのタイミングで<code>tsc --noEmit</code>を実行するだけでも十分かもしれません。</p> <h4 id="%E3%82%B1%E3%83%BC%E3%82%B92%EF%BC%9A%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%82%84%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%82%92%E8%BF%BD%E5%8A%A0%E3%83%BB%E6%9B%B4%E6%96%B0%E3%81%97%E3%81%9F%E3%81%AE%E3%81%AB%E5%8F%8D%E6%98%A0%E3%81%95%E3%82%8C%E3%81%AA%E3%81%84" tabindex="-1">ケース2:ライブラリやモジュールを追加・更新したのに反映されない</h4> <p>前述の通り、Viteは必要な時に必要なものだけを読み込んでコンパイルします。しかしこの方法で<code>node_modules</code>にインストールされた大量の依存モジュールを読み込んでいてはキリがありません。このためViteは<code>node_modules</code>のモジュールについては事前に取りまとめ(バンドル)を行い、キャッシュする仕組みを持っています。</p> <p>依存モジュールが変わるとこのキャッシュも自動的に再生成されますが、<code>package.json</code>を手で編集した場合などは、再生成がうまく行われないこともあるので、注意が必要です。</p> <p><strong>対処</strong> <code>dev</code>コマンドに<code>--force</code>オプションをつけることで強制的にキャッシュをクリアできます。</p> <pre><code class="hljs language-sh"><span class="hljs-comment"># npmを使う場合</span> npm run dev -- --force <span class="hljs-comment"># yarnを使う場合</span> yarn dev --force </code></pre> <p>変更したはずの依存モジュールがうまく読み込めていないと思ったら、まずは試してみると良いでしょう。</p> <h3 id="%E3%81%BE%E3%81%A8%E3%82%81%EF%BC%9A%E3%83%A2%E3%83%80%E3%83%B3%E3%81%AA%E9%96%8B%E7%99%BA%E3%81%AE%E5%85%A5%E9%96%80%E3%81%8B%E3%82%89%E3%83%97%E3%83%AD%E3%81%AE%E7%8F%BE%E5%A0%B4%E3%81%BE%E3%81%A7%E3%80%81vite%E3%81%AF%E5%B9%85%E5%BA%83%E3%81%8F%E4%BD%BF%E3%81%88%E3%82%8B%E9%96%8B%E7%99%BA%E3%83%84%E3%83%BC%E3%83%AB" tabindex="-1">まとめ:モダンな開発の入門からプロの現場まで、Viteは幅広く使える開発ツール</h3> <p>Viteは登場してからまだ1年余りの新しいツールです。その新しさゆえ、導入はまだ先と考えている方も多いでしょう。しかし、Viteの技術はウェブ標準や実績のあるOSSライブラリを下敷きにしており、すでに十分実用に耐えるレベルです。ICSでは2021年にバージョン2がリリースされてから、徐々にViteを業務に利用しています。</p> <p>その一方で、Viteはwebpackと比較すると細かな設定がやりにくく、周辺ツールやウェブ上の情報もまだまだ十分とは言えません。当面は小規模で開発のスピード感を重視するプロジェクトを中心に利用され、webpackとは棲み分けていくことになるでしょう。</p> <p>なお、Nuxt.jsをViteで動かす<a href="https://vite.nuxtjs.org/" target="_blank">『Nuxt Vite』</a>の開発や、<a href="https://github.com/vercel/next.js/discussions/22406" target="_blank">Next.jsでViteをサポートするディスカッション</a>も進んでいるようです。これらのフレームワークを利用している方は動向をチェックしておくと良いでしょう。</p> <p>もうひとつのViteの魅力は、これらの最新のフレームワークに馴染みがない方でも、好きな構成で快適に開発を始められることです。まずはシンプルなJavaScriptからはじめて、徐々にモダンなフレームワークを学習していくのもViteなら難しくありません。ぜひこの機会にチャレンジしてみてください。</p> </section><!----></div><div class="entry-sidebar" data-v-49d92408><div class="sidebar" data-v-49d92408><ol class="sidebarList"><li class="sidebarList_item"><a href="#top">冒頭</a></li><!--[--><li data-index="0" class="sidebarList_item"><a href="#contents-anchor-features">Viteの特徴と基本の仕組み</a></li><li data-index="1" class="sidebarList_item sidebarList_item__sub"><a href="#%E2%91%A0%E3%83%A2%E3%83%80%E3%83%B3%E3%83%96%E3%83%A9%E3%82%A6%E3%82%B6%E3%81%8C%E5%82%99%E3%81%88%E3%82%8B%E4%BB%95%E7%B5%84%E3%81%BF%EF%BC%88es-modules%E3%82%84dynamic-import%EF%BC%89%E3%82%92%E5%88%A9%E7%94%A8%E3%81%97%E3%81%A6%E9%AB%98%E9%80%9F%E3%81%AA%E8%B5%B7%E5%8B%95%2F%E6%9B%B4%E6%96%B0%E3%81%8C%E3%81%A7%E3%81%8D%E3%82%8B">①モダンブラウザが備える仕組み(ES modulesやDynamic import)を利用して高速な起動/更新ができる</a></li><li data-index="2" class="sidebarList_item sidebarList_item__sub"><a href="#%E2%91%A1typescript%E3%82%84vue%2Freact%E7%AD%89%E3%81%AE%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%81%8C%E8%A8%AD%E5%AE%9A%E3%81%AA%E3%81%97%E3%81%A7%E3%81%99%E3%81%90%E3%81%AB%E4%BD%BF%E3%81%88%E3%82%8B">②TypeScriptやVue/React等のライブラリが設定なしですぐに使える</a></li><li data-index="3" class="sidebarList_item sidebarList_item__sub"><a href="#%E2%91%A2ie%E3%82%92%E5%90%AB%E3%82%81%E3%81%9F%E3%83%97%E3%83%AD%E3%83%80%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%93%E3%83%AB%E3%83%89%E3%82%82%E3%81%A7%E3%81%8D%E3%82%8B">③IEを含めたプロダクションビルドもできる</a></li><li data-index="4" class="sidebarList_item"><a href="#contents-anchor-basic">基本の使い方</a></li><li data-index="5" class="sidebarList_item sidebarList_item__sub"><a href="#%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE%E5%88%9D%E6%9C%9F%E5%8C%96">プロジェクトの初期化</a></li><li data-index="6" class="sidebarList_item sidebarList_item__sub"><a href="#%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E8%B5%B7%E5%8B%95">デバッグ起動</a></li><li data-index="7" class="sidebarList_item sidebarList_item__sub"><a href="#%E3%83%93%E3%83%AB%E3%83%89">ビルド</a></li><li data-index="8" class="sidebarList_item sidebarList_item__sub"><a href="#vite%E3%81%AE%E3%81%BF%EF%BC%88%E3%83%90%E3%83%8B%E3%83%A9js%3D%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AF%E3%81%AA%E3%81%97%EF%BC%89%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB">Viteのみ(バニラJS=フレームワークなし)のサンプル</a></li><li data-index="9" class="sidebarList_item"><a href="#contents-anchor-scss">Vite + Sass(SCSS)</a></li><li data-index="10" class="sidebarList_item"><a href="#contents-anchor-typescript">Vite + TypeScript</a></li><li data-index="11" class="sidebarList_item sidebarList_item__sub"><a href="#vite-%2B-typescript%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB">Vite + TypeScriptのサンプル</a></li><li data-index="12" class="sidebarList_item"><a href="#contents-anchor-assets">Vite + アセット(画像など)</a></li><li data-index="13" class="sidebarList_item sidebarList_item__sub"><a href="#javascript%2Ftypescript%E3%81%8B%E3%82%89%E7%94%BB%E5%83%8F%E3%82%92%E8%AA%AD%E3%81%BF%E8%BE%BC%E3%82%80">JavaScript/TypeScriptから画像を読み込む</a></li><li data-index="14" class="sidebarList_item sidebarList_item__sub"><a href="#%E9%9D%99%E7%9A%84%E3%81%AA%E7%94%BB%E5%83%8F%E3%81%AE%E5%88%A9%E7%94%A8">静的な画像の利用</a></li><li data-index="15" class="sidebarList_item sidebarList_item__sub"><a href="#vite-%2B-typescript-%2B-%E3%82%A2%E3%82%BB%E3%83%83%E3%83%88%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB">Vite + TypeScript + アセットのサンプル</a></li><li data-index="16" class="sidebarList_item"><a href="#contents-anchor-vue">Vite + TypeScript + Vue</a></li><li data-index="17" class="sidebarList_item sidebarList_item__sub"><a href="#vuex%E3%82%84vue-router%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B">VuexやVue Routerを追加する</a></li><li data-index="18" class="sidebarList_item sidebarList_item__sub"><a href="#vite-%2B-typescript-%2B-vue%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB">Vite + TypeScript + Vueのサンプル</a></li><li data-index="19" class="sidebarList_item"><a href="#contents-anchor-react">Vite + TypeScript + React</a></li><li data-index="20" class="sidebarList_item sidebarList_item__sub"><a href="#jsx%2Ftsx%E3%82%92%E4%BD%BF%E3%81%86%E5%A0%B4%E5%90%88%E3%81%AE%E6%B3%A8%E6%84%8F">jsx/tsxを使う場合の注意</a></li><li data-index="21" class="sidebarList_item"><a href="#contents-anchor-config">設定のカスタマイズ</a></li><li data-index="22" class="sidebarList_item sidebarList_item__sub"><a href="#server.port%EF%BC%9A%E9%96%8B%E7%99%BA%E6%99%82%E3%81%AE%E3%83%9D%E3%83%BC%E3%83%88%E7%95%AA%E5%8F%B7%E8%A1%9D%E7%AA%81%E3%82%92%E9%81%BF%E3%81%91%E3%82%8B">server.port:開発時のポート番号衝突を避ける</a></li><li data-index="23" class="sidebarList_item sidebarList_item__sub"><a href="#base%EF%BC%9A%E3%80%8C%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4%E3%81%97%E3%81%9F%E3%82%89%E7%94%BB%E9%9D%A2%E3%81%8C%E5%87%BA%E3%81%AA%E3%81%84%E3%80%8D%E5%95%8F%E9%A1%8C%E3%82%92%E5%9B%9E%E9%81%BF">base:「デプロイしたら画面が出ない」問題を回避</a></li><li data-index="24" class="sidebarList_item sidebarList_item__sub"><a href="#resolve.alias%EF%BC%9Aimport%E3%81%99%E3%82%8B%E3%83%91%E3%82%B9%E3%81%A7%40components%2F%E3%81%AE%E3%82%88%E3%81%86%E3%81%AA%E3%82%A8%E3%82%A4%E3%83%AA%E3%82%A2%E3%82%B9%E5%90%8D%E3%82%92%E4%BD%BF%E3%81%88%E3%82%8B%E3%82%88%E3%81%86%E3%81%AB%E3%81%99%E3%82%8B">resolve.alias:importするパスで@components/のようなエイリアス名を使えるようにする</a></li><li data-index="25" class="sidebarList_item"><a href="#contents-anchor-ie11">IE11に対応する方法</a></li><li data-index="26" class="sidebarList_item sidebarList_item__sub"><a href="#%E3%81%99%E3%81%B9%E3%81%A6%E3%81%8C%E5%A4%89%E6%8F%9B%E3%81%A7%E3%81%8D%E3%82%8B%E3%82%8F%E3%81%91%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%84%E3%81%AE%E3%81%A7%E6%B3%A8%E6%84%8F%EF%BC%81">すべてが変換できるわけではないので注意!</a></li><li data-index="27" class="sidebarList_item sidebarList_item__sub"><a href="#ie11%E5%AF%BE%E5%BF%9C%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB">IE11対応のサンプル</a></li><li data-index="28" class="sidebarList_item"><a href="#contents-anchor-pitfalls">落とし穴と回避方法</a></li><li data-index="29" class="sidebarList_item sidebarList_item__sub"><a href="#%E3%82%B1%E3%83%BC%E3%82%B91%EF%BC%9A%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83%E3%81%A7%E3%81%AF%E5%8B%95%E3%81%84%E3%81%A6%E3%81%84%E3%82%8B%E3%81%AE%E3%81%AB%E3%80%81%E3%83%93%E3%83%AB%E3%83%89%E3%81%99%E3%82%8B%E3%81%A8%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%AB%E3%81%AA%E3%82%8B">ケース1:開発環境では動いているのに、ビルドするとエラーになる</a></li><li data-index="30" class="sidebarList_item sidebarList_item__sub"><a href="#%E3%82%B1%E3%83%BC%E3%82%B92%EF%BC%9A%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%82%84%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%82%92%E8%BF%BD%E5%8A%A0%E3%83%BB%E6%9B%B4%E6%96%B0%E3%81%97%E3%81%9F%E3%81%AE%E3%81%AB%E5%8F%8D%E6%98%A0%E3%81%95%E3%82%8C%E3%81%AA%E3%81%84">ケース2:ライブラリやモジュールを追加・更新したのに反映されない</a></li><li data-index="31" class="sidebarList_item"><a href="#%E3%81%BE%E3%81%A8%E3%82%81%EF%BC%9A%E3%83%A2%E3%83%80%E3%83%B3%E3%81%AA%E9%96%8B%E7%99%BA%E3%81%AE%E5%85%A5%E9%96%80%E3%81%8B%E3%82%89%E3%83%97%E3%83%AD%E3%81%AE%E7%8F%BE%E5%A0%B4%E3%81%BE%E3%81%A7%E3%80%81vite%E3%81%AF%E5%B9%85%E5%BA%83%E3%81%8F%E4%BD%BF%E3%81%88%E3%82%8B%E9%96%8B%E7%99%BA%E3%83%84%E3%83%BC%E3%83%AB">まとめ:モダンな開発の入門からプロの現場まで、Viteは幅広く使える開発ツール</a></li><!--]--></ol></div></div></div></article></main><div class="wrap_960" data-v-da421125><div class="SnsButtons" data-v-da421125 data-v-b5cbd36c><p class="SnsButtons-head" data-v-b5cbd36c>\ SNSでシェアしよう /</p><div class="SnsButtons-sns" data-v-b5cbd36c><a href="https://twitter.com/intent/tweet?url=https://ics.media/entry/210708/&text=jQuery%E3%81%8B%E3%82%89TypeScript%E3%83%BBReact%E3%81%BE%E3%81%A7%20-%20Vite%E3%81%A7%E5%A7%8B%E3%82%81%E3%82%8B%E3%83%A2%E3%83%80%E3%83%B3%E3%81%A7%E9%AB%98%E9%80%9F%E3%81%AA%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83%E6%A7%8B%E7%AF%89%20-%20ICS%20MEDIA" target="_blank" class="btn btn-secondary btn-sm share-x" data-v-b5cbd36c><span data-v-b5cbd36c>X(旧Twitter)でポストする</span></a><a href="https://b.hatena.ne.jp/entry/s/ics.media/entry/210708/" target="_blank" class="btn btn-secondary btn-sm share-facebook" data-v-b5cbd36c><span data-v-b5cbd36c>はてなブックマーク</span></a></div></div><div class="author-info" data-v-da421125 style="--475ed944:staff-matsumoto;" data-v-9742c4dd><div class="author-avatar" data-v-9742c4dd><img src="/_assets/top/staff/ics-staff-matsumoto.jpg" width="64" height="64" alt="" loading="lazy" data-v-9742c4dd></div><div class="author-desc" data-v-9742c4dd><div class="author-desc-name" data-v-9742c4dd><div data-v-9742c4dd>松本 ゆき</div><div data-v-9742c4dd><a class="btn btn-secondary btn-x" target="_blank" href="https://twitter.com/yuneco" data-v-9742c4dd><svg width="16" height="16" viewbox="0 0 240 240" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-9742c4dd><path d="M240 0H0V240H240V0Z" fill="black"></path><path d="M88.2 60.6602L169.46 178.81H151.42L70.16 60.6602H88.2ZM92.93 51.6602H53.04L146.68 187.81H186.57L92.93 51.6602Z" fill="white"></path><path d="M132.54 109.25L182.24 51.6602H170.99L127.55 101.99L132.54 109.25Z" fill="white"></path><path d="M105.36 127.72L53.04 188.34H64.3L110.35 134.98L105.36 127.72Z" fill="white"></path></svg>フォロー </a></div></div><p class="author-desc-script" data-v-9742c4dd>フロントエンドエンジニア。SIer&UXコンサルタントからフロントエンドエンジニアに転身。新しいアイデアを企画段階からプロトタイピングしていくことが得意です。趣味はお絵かきと開発。</p><a href="/entry/staff/matsumoto/" class="btn btn-secondary" data-v-9742c4dd> この担当の記事一覧 </a></div></div></div><aside class="wrap_960 banners" data-v-da421125 data-v-84d78e6a><ul data-v-84d78e6a><li data-v-84d78e6a><a href="/entry/231120/" data-v-84d78e6a><img width="1200" height="640" class="banner-img" alt="バナー:フロントエンドの知識地図" src="/_assets/top/231120_book_banner.jpg" loading="lazy" data-v-84d78e6a></a></li><li data-v-84d78e6a><a href="https://ics-web.jp/recruit/" data-v-84d78e6a><img width="1200" height="640" class="banner-img" alt="バナー:株式会社ICS 採用サイト" src="/_assets/top/190207_recruit_banner.jpg" loading="lazy" data-v-84d78e6a></a></li></ul></aside><aside class="related" data-v-da421125 data-v-c7eaaedb><div class="related-in" data-v-c7eaaedb><h3 class="related-in-head" data-v-c7eaaedb>よく一緒に読まれている記事</h3><ul class="related-in-ul" data-v-c7eaaedb><!--[--><li data-v-c7eaaedb><a href="/entry/16329/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/16329/images/eyecatch__480.jpg" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>TypeScriptとwebpackの環境構築まとめ</p></a></li><li data-v-c7eaaedb><a href="/entry/12140/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/12140/images/eyecatch__480.png" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>webpack入門 - JSのモジュールバンドラ</p></a></li><li data-v-c7eaaedb><a href="/entry/16511/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/16511/images/eyecatch__480.jpg" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>ES Modules入門 - JavaScriptのモジュールを使う方法</p></a></li><li data-v-c7eaaedb><a href="/entry/190325/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/190325/images/eyecatch_percel_typescript__480.png" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>Parcel入門 - TypeScriptの導入方法</p></a></li><li data-v-c7eaaedb><a href="/entry/13838/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/13838/images/eyecatch__480.png" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>npm互換のJSパッケージマネージャーYarn入門</p></a></li><li data-v-c7eaaedb><a href="/entry/200923/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/200923/images/eyecatch__480.jpg" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>フロントエンド開発に適したマシン構成を調査。ビルド時間に顕著にあらわれるCPUの影響</p></a></li><li data-v-c7eaaedb><a href="/entry/190709/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/190709/images/eyecatch__480.jpg" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>フロントエンドエンジニアにアンケート</p></a></li><li data-v-c7eaaedb><a href="/entry/17451/" class="" data-v-c7eaaedb><p class="related-in-ul-li-thumb" data-v-c7eaaedb><img class="related-in-ul-li-thumb-img" src="/entry/17451/images/eyecatch__480.png" alt width="1280" height="512" loading="lazy" style="" data-v-c7eaaedb></p><p class="related-in-ul-li-title" data-v-c7eaaedb>脱jQueryのためにしたこと</p></a></li><!--]--></ul></div></aside><div class="top_link" data-v-da421125><a href="/" class="btn btn-primary" data-v-da421125>トップページに戻る</a></div><div class="header-breadcrumb" data-v-da421125 data-v-b934bba3><div class="header-breadcrumb__inner" data-v-b934bba3><ul itemscope itemtype="http://schema.org/BreadcrumbList" data-v-b934bba3><!--[--><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" data-v-b934bba3><a href="/" class="" itemprop="item" data-v-b934bba3><span itemprop="name" data-v-b934bba3>ICS MEDIA</span><meta itemprop="position" content="1" data-v-b934bba3></a></li><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" data-v-b934bba3><a href="/entry/category/frontend/" class="" itemprop="item" data-v-b934bba3><span itemprop="name" data-v-b934bba3>フロントエンジニア</span><meta itemprop="position" content="2" data-v-b934bba3></a></li><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" data-v-b934bba3><a aria-current="page" href="/entry/210708/" class="router-link-active router-link-exact-active" itemprop="item" data-v-b934bba3><span itemprop="name" data-v-b934bba3>jQueryからTypeScript・Reactまで - Viteで始めるモダンで高速な開発環境構築</span><meta itemprop="position" content="3" data-v-b934bba3></a></li><!--]--></ul></div></div></div><!--]--><footer class="site_info" data-v-53af800e data-v-63cb43db><div class="site_info-sections" data-v-63cb43db><div class="site_info-sections_item" data-v-63cb43db><h3 data-v-63cb43db>このサイトについて</h3><p data-v-63cb43db><ruby data-v-63cb43db>ICS MEDIA<rt data-v-63cb43db>アイシーエス メディア</rt></ruby>は株式会社<ruby data-v-63cb43db>ICS<rt data-v-63cb43db>アイシーエス</rt></ruby>が運営する<strong title="ICS MEDIAはブログではありません" data-v-63cb43db>オウンドメディア</strong>です。UIデザインやフロントエンドのノウハウや最新技術を掲載しています。UIデザインやフロントエンドのノウハウや最新技術を週1回のペースで掲載しています。 </p><ul data-v-63cb43db><li data-v-63cb43db><a href="/entry/about/" class="" data-v-63cb43db>About</a></li><li data-v-63cb43db><a href="https://docs.google.com/forms/d/e/1FAIpQLSdxYknUt8noNJjuuxAIFgnyNL13XpL4MuwQoOrU_inUz8MhGg/viewform?usp=sf_link" target="_blank" data-v-63cb43db> 記事に関するお問い合わせ </a></li></ul></div><div class="site_info-sections_item" data-v-63cb43db><h3 data-v-63cb43db>運営会社について</h3><p data-v-63cb43db> ICSはインタラクションデザイン専門のウェブ制作会社。最先端のウェブテクノロジーを駆使し、オンスクリーンメディアの表現分野で活動しています。 </p><ul data-v-63cb43db><li data-v-63cb43db><a href="https://ics-web.jp/" target="_blank" data-v-63cb43db> 会社サイト </a></li><li data-v-63cb43db><a href="https://ics-web.jp/contact/" target="_blank" data-v-63cb43db> 会社へのお問い合わせ<br class="tablet" data-v-63cb43db>(仕事の相談等) </a></li></ul><p data-v-63cb43db> インタラクションコンテンツの制作に挑戦しながら、互いにスキルを高め合えるスタッフをICSでは募集しています。 </p><ul data-v-63cb43db><li data-v-63cb43db><a href="https://ics-web.jp/recruit/" rel="noopener noreferrer" data-v-63cb43db>採用情報について</a></li></ul></div><div class="site_info-sections_item" data-v-63cb43db><h3 data-v-63cb43db>常に鮮度の高い情報を</h3><p data-v-63cb43db> ICS MEDIAは古い記事でもメンテナンスし続けることで、常に役立つ情報発信を目指しています。 </p><ul data-v-63cb43db><li data-v-63cb43db><a href="/entry/all/" class="" data-v-63cb43db> すべての記事 </a></li><li data-v-63cb43db><a href="/feed/atom.xml" target="_blank" title="ICS MEDIAのRSSをリーダーに登録しよう" data-v-63cb43db> RSS </a></li><li data-v-63cb43db><a href="https://x.com/icsweb" target="_blank" title="ICSのXをフォローしよう" data-v-63cb43db> Xアカウント </a></li></ul></div></div><div class="copyright" role="contentinfo" data-v-63cb43db data-v-4b34f398> Copyright © 2025 <span itemScope="" itemProp="publisher" itemType="https://schema.org/Organization" data-v-4b34f398> ICS INC. </span><br class="mobile" data-v-4b34f398> All Rights Reserved. <br data-v-4b34f398><span class="raw-pages" data-v-4b34f398><div class="raw-pages-item" data-v-4b34f398><a href="/entry/copyright/" class="" data-v-4b34f398>利用規約・免責・著作権</a></div><div class="raw-pages-item" data-v-4b34f398><a href="/entry/privacy/" class="" data-v-4b34f398>プライバシーポリシー</a></div><div class="raw-pages-item" data-v-4b34f398><a href="/entry/quality/" class="" data-v-4b34f398>品質への取り組み</a></div></span></div></footer></div></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="true">[["ShallowReactive",1],{"data":2,"state":4,"once":6,"_errors":7,"serverRendered":9,"path":10,"prerenderedAt":11,"pinia":12},["ShallowReactive",3],{},["Reactive",5],{},["Set"],["ShallowReactive",8],{},true,"/entry/210708/",1742812903097,["Reactive",13],{"page":14,"transition":20},{"id":15,"title":16,"type":17,"line":18,"useHero":19},"frontend","","top","category",false,{"current":16}]</script> <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/",buildId:"d88dd883-c3c8-48e2-a766-0779fa224f8a",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>