GithubHelp home page GithubHelp logo

jump-marathon's Introduction

Webpack Single Page Boilerplate

A boilerplate for a single page app using webpack

Build Status Dependency Status

Why should I use it

So far, this is the best way I found to build files like index.html into webpack. This boilerplate handles Javascript, CSS and HTML bundling using only webpack.

Usage

The general directory structure is:

├── assets/
│   └── image
│       └── favicon.png
├── index.html
├── package.json
├── environment.json
├── plugins/
│   └── html-plugin.js
├── README.md
├── scripts/
│   └── index.js
├── styles/
│   └── index.less
└── webpack.config.js
  • Your javascript entry point is scripts/index.js
  • Your style entry point is styles/index.less
  • 'environment.json' file provides optional environment variable settings, but you can delete it if you don't need it.
  • The plugins/html-plugin.js file is better explained on the About section, with the html-parser-plugin plugin.

There's a hack to build HTML files, replacing the src and href tags related to images into their corresponding file in dist directory. This way, a index.html file that looks like this:

<!DOCTYPE html>
<html>
  <head>
    <title>Sample App</title>
    <meta charset="utf-8"/>
    <link href="!assets/image/favicon.png" rel="icon"/>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <script src="script.js"></script>
  </body>
</html>

Becomes this:

<!DOCTYPE html>
<html>
  <head>
    <title>Sample App</title>
    <meta charset="utf-8">
    <link href="84eafba88857e5fd2e85d63beaf3fb31.png" rel="icon">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <script src="script.js"></script>
  </body>
</html>

Notice that the favicon.png file was replaced with 84eafba88857e5fd2e85d63beaf3fb31.png. This happened because the favicon.png file link was marked with a ! prepending it - it tells the plugin that the url should be bundled and replaced.

About

This boilerplate includes the following loaders:

  • babel-loader: Enable ES6 features.
  • file-loader: Call require for binary files.
  • img-loader: Optimize image compression.
  • json-loader: Call require for json files.
  • less-loader: Style your pages with less.
  • style-loader: Add exports of a module as style to DOM.

It also includes the following plugins:

  • extract-text-webpack-plugin: Extract css text from bundled styles.
  • html-parser-plugin: Custom experimental plugin to enable html parsing on webpack. It is used to emit a index.html file along with it's images.

License

This code is released under CC0 (Public Domain)

jump-marathon's People

Contributors

nihey 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.