Git Product home page Git Product logo

webpack-single-build-template's Introduction

What this is

This is a ready to use template for creating modern frontend web applications.

Getting started

  1. Clone the repository.
  2. npm i
  3. npm run start -- to start development. This will open a browser.
  4. npm run build -- to build for production. Your files would be at builds/.

Dot Env

Environment variables

Environment variables defined in .env file would be available as the process.env global object. You should prefix them with APP_, e.g., APP_TEST_VAR="some value", which would be available via process.env.APP_TEST_VAR.

All env variables are being parse to their native data type. Example:

APP_BOOL="true"
APP_TEST_OBJ='{"test1":"value1","test2":"value2","test3":true,"test4":["hello",123,123.56]}'
APP_ARR='["hello",123,123.56]'
  • APP_BOOL will be available as process.env.APP_BOOL which would be a Boolean.
  • APP_OBJ will be available as process.env.APP_TEST_OBJ which would be an Object.
  • APP_ARR will be available as process.env.APP_ARR which would be an Array.

All process.env.APP_VAR instances are being replaced, i.e.:

input: console.log(process.env.APP_TEST_OBJ) output: console.log({"test1":"value1","test2":"value2","test3":true,"test4":["hello",123,123.56]})

WEBSITE_NAME

Is being used for the title in your index.html.

Development

npm run start

The entry file is src/entry.

You can also specify PORT and HOST in the .env. Example:

HOST="dev.domain.loc"
PORT="3000"

This is where your app would be accessible during development.

Build

Inlined with index.html

By default, the main.css is inline with index.html. Babel runtime is also split into a separate chunk that's also inlined.

Scripts

The vendors script and the main script are split and are loaded via async. This improves loading performance on browsers.

PWA

The template is PWA enabled by default. Service worker is powered by workbox.

Dummy icons are available in public/icons (16x16, 24x24, 32x32, 64x64, 128x128, 256x256, 512x512).

Manifest file is also available at public/manifest.json which the index.html already links to.

Code formatting

For code formatting the template is using eslint and prettier.

NPM scripts

  • To run eslint npm run eslint.
  • To run prettier npm run prettier.
  • To run both in the proper order npm run lint.

Styling

Only scss is used for styling because as of the this writing, prettier does not support sass.

Code splitting

You can use webpack's dynamic import BUT it does not work out of the box, you need a bridge like inferno-async-component to handle the component.

Public files

Use the public folder on the root directory to store your public files. You can create folders there like fonts/, css/, images/ if you have to.

Webpack is configured to save all css files you used in your js files in the css/ folder of your build, so to avoid having two folders with only css files in them, you can also create css/ folder in the public directory. Those files would be copied in the css/ directory of the build together with the other css files you may be using, like in font-awesome. For the fonts, save them in the public/fonts/ directory. For images save them in the public/images directory. For js save them in the public/js directory. For svg files, save them in the public/svgs directory.

Serving built files

You can serve built files after running npm run build by running one of the following.

  • npm run serve:web
  • npm run serve:native

This feature is powered by http-server.

webpack-single-build-template's People

Contributors

aprilmintacpineda avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.