Skip to content

Makes common development resources accessible when developing in a local environment.

License

Notifications You must be signed in to change notification settings

dustin-ruetz/gulp-webserver

Repository files navigation

dev-webserver

This webserver makes common development resources available when developing in a local environment.

Purpose

  1. Prevents the need for creating/maintaining separate copies of common development resources across multiple projects.
  2. It adds the Access-Control-Allow-Origin header to the server's response. This header modifies the server's cross-origin resource sharing (CORS) policy, thereby allowing it to share local fonts, images, stylesheets, scripts, and any other desired resources.

Installation

  1. Prerequisite: Have Node.js installed.
  2. Download a clone/copy of this repository.
  3. Open a terminal window at the root of the repository.
  4. Run npm install to download all dependencies.

Usage

Note: These instructions assume default ports of 4000 for the webserver and 3000 for other local projects. Edit gulpfile.js if you wish to change this configuration.

  1. Use npm run gulp to start the server at the default localhost:4000 location.
  2. Place the resources you wish to share in the public/ directory.
    • Static resources (favicons, fonts, images, etc.) can be placed directly in the public/ folder.
    • Resources that require compilation (such as SCSS files and JavaScript written in ES6 syntax) can be developed in the dev/ folder. The gulp task will compile them to browser-compatible CSS and JS files and output these to the public/ folder.
      • An example of a compilable/shareable resource that can be used in responsive web development projects is window-dimensions-helper (SCSS and JS files are included in the dev/ folder). It is a simple helper module that is dynamically injected into the DOM and its contents are updated every time the window is resized.
  3. Open another project and link to your resources normally via localhost:4000/public/ (example below).
<!doctype html>
<html lang="en">
    <head>
        <title>Project Title</title>
        <link rel="icon" type="image/png" href="http://localhost:4000/public/icons/special-dev-favicon.png">
        <link rel="stylesheet" href="http://localhost:4000/public/fonts/special-font.css">
        <link rel="stylesheet" href="http://localhost:4000/public/styles/window-dimensions-helper.css">
        <link rel="stylesheet" href="styles/main.css">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>

        ... (rest of document) ...

        <script src="http://localhost:4000/public/scripts/window-dimensions-helper.js"></script>
        <script src="scripts/main.js"></script>
    </body>
</html>

License

MIT License

Copyright 2017 Dustin Ruetz.

About

Makes common development resources accessible when developing in a local environment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published