Almost no config!!! Snowpack ❄️ + React + TS

Subscribe to my newsletter and never miss my upcoming articles

Recently, I have seen Snowpack so many times, so I think it's time to try it.

Actually, we can use create-snowpack-app to create a base app, but I think trying to create a simple app without using that can be helpful to understand the basics of Snowpack. In this article, I tried Snowpack with reactjs and typescript.

What I made is here. {% github koji/snowpacktest %}

What is Snowpack?

Snowpack is a modern, lightweight build tool for faster web development. Traditional JavaScript build tools like webpack and Parcel need to rebuild & rebundle entire chunks of your application every time you save a single file. This rebundling step introduces lag between hitting save on your changes and seeing them reflected in the browser.

How Snowpack Works

Create a project dir and init project

$ mkdir snowpacktest
$ yarn init

Install Snowpack and add npm script

$ yarn add --dev snowpack
"scripts": {
    "dev": "snowpack dev",
    "build": "snowpack build"

Create snowpack.config.js

In this case, public is set as the root dir.

module.exports = {
  mount: {
    public: { url: "/", static: true },
    src: "/",

Doc: snowpack.config.js

Create index.html

<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>my first snowpack app</title>
        <div id="root"></div>
        <script type="module" src="/index.js"></script>

Install react and typescript

$ yarn add react react-dom
$ yarn add -D typescript @types/react @types/react-dom

Just in case, I put my tsconfig.json

    "compilerOptions": {
        "module": "ESNext",
        "target": "ESNext",
        "strict": true,
        "moduleResolution": "node",
        "esModuleInterop": true,
        "jsx": "preserve",
        "noEmit": true,
        "skipLibCheck": true,
        "typeRoots": [
    "include": [

Create a simple component


import React from 'react';
import { render } from 'react-dom';

const App = () => {
    return (
          <h1>my first snowpack+react app</h1>
              <img src={logo} />
          <h2>hello ❄️Snowpack❄️</h2>
render(<App />, document.getElementById('root'));

Use devServer

$ yarn dev


  http://localhost:8080 •
  Server started in 14ms.

If you know webpack, you may think that's it? since generally, we need to put more lines in config.js file for webpack. But, actually, that is it 😁

Let's try to display an image!

Create types/image.d.ts

To display image, we need to create a .d.ts file. In this case, we put .png, .jpg, and .svg.

declare module '*.png';
declare module '*.jpg';
declare module '*.svg';

Add lines to index.tsx

To display an image, we need to modify index.tsx a little bit.

First, install styled-components since I like it lol

$ yarn add styled-components
$ yarn add -D @types/styled-components

If you are not familiar with styled-components, please see the link.

import React from 'react';
import { render } from 'react-dom';
import logo from './source.png';
import styled from 'styled-components';

const Wrapper = styled.section`
  padding: 4em;
  background: #ededed;

const Title = styled.h1`
  font-size: 3em;
  text-align: center;
  color: #ea1ed4;

const ImageWrapper = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;

const Greeting = styled.h2`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;

const App = () => {
    return (
          <Title>my first snowpack+react app</Title>
              <img src={logo} />
          <Greeting>hello ❄️Snowpack❄️</Greeting>
render(<App />, document.getElementById('root'));

Alt Text

If you prefer to use css, you will need to create a .d.ts for importing css


declare module '*.css' {
  const classNames: { [className: string]: string };
  export default classNames;


Snowpack is pretty cool since not it supports jsx and typescript source code by default. Also we don't need to install any plugin to use dev server which is great. Of course, we can extend the build with custom plugins. I think I will start using Snowpack for my side-project!

Share this
Proudly part of