New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

swoop-boilerplate

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swoop-boilerplate

Presets for setting up webpack with hotloading and ES6(2015) using Babel and Flow.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

#Swoop-boilerplate

I really dislike setting up build scripts. Most of the time I want to do the exact same thing:

While developing:

  • easy to setup and run dev server
  • transpile ES6+, JSX, code
  • hotload (a.k.a. live reload) modules when changed

When ready to ship:

  • minify and bundle all the things
  • output minfied, uniquely named static files into public directory
  • be able to generate/customized static HTML file(s) used to deliver my JS app

webpack and the webpack-dev-server can do most of those things pretty well out of the box. But, it sure is a pain to set it all up.

So, this is just a simplified, opinionated way to configure webpack for development and then build for production. That also supports easily generating more files.

If no one uses it but me, it will have still served its purpose.

Usage

Step 1. Create/install it into your project

npm init
npm install -g webpack webpack-dev-server
npm install swoopcmi/swoop-boilerplate
mkdir static && mkdir source

Step 2. Create a webpack.config.js

Put it at the root of your project, a typical config looks something like this:

var getConfig = require("swoop-boilerplate");
var env = process.env.NODE_ENV || "development";

module.exports = getConfig({
    // a boolean specifying whether to minify, output files, etc
    isDev: env === "development",
    // entry point for the app
    in: "source/app.js"
});

Step 3. Configure scripts section of package.json

I usually add something like the following scripts:

"scripts": {
  "start": "webpack-dev-server"
}

Assuming you've got some JS written that you've set as your in in the webpack.config.js you can run npm start and open a browser to http://localhost:3000 and you everything should Just Work™.

When you're wanting to do a build, just run npm run build. The build will generate your files into public.

Now there's a static site in public

note about peerDependencies

swoop-boilerplate specifies many of its dependencies as peerDependencies in order to let you decide which version of, say, babel or React that you want to use in your project without us specifying that directly for you.

In npm 3.x.x peerDependencies will no longer be installed by default.

When this happens, you'll want to run the following to install the related dependencies as well.

Included here for your copy/paste enjoyment:

npm i --save webpack-dev-server

Config options

The main export you get when you require("swoop-boilerplate") is simply a pre-configured webpack.config.js. You could take the result of that and add other plugins if you so chose, but shouldn't be necessary for most common tasks.

in

This should just be the path to the file that serves as the main entry point of your application.

out

Path to directory where we're going to put generated files.

isDev

A boolean to indicate whether or not everything is in production mode (minified, etc.) or development mode (everything hotloaded and unminified).

Additional goodies

Developing on multiple devices at once

If you're building an app that you want to look good on all devices it's nice to be able to run them all at once.

Hotloading makes this extremely nice and convenient.

If you're on a mac, this is fairly simple. Just add a hostname option to your config like so:

var getConfig = require("swoop-boilerplate");
var env = process.env.NODE_ENV || "development";

module.exports = getConfig({
    isDev: env === 'development',
    in: 'src/app.js',
    out: 'public',

    // set this to whatever your machine name is
    // plus `.local`
    // my machine is `loki` so I do:
    hostname: 'loki.local'
})

Now when you run the development instead of going to localhost open: http://{{yourmachine}}.local:3000 on any device that's on your local network, they should all connect and all hotload your style and JS changes.

License

MIT

Credits

All this is possible, thanks to the original author @HenrikJoreteg who published the basis for this boilerplate to https://github.com/henrikjoreteg/hjs-webpack

Keywords

FAQs

Package last updated on 30 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc