Git Product home page Git Product logo

spike-util's Introduction

Spike Util

npm tests dependencies coverage

A grab bag of utilities for spike plugins

Note: This project is in early development, and versioning is a little different. Read this for more details.

Why should you care?

Spike uses webpack as its core compiler, but fundamentally behaves a bit differently from webpack, as it's a full static site compiler rather than a javascript bundler. As such, plugins for spike frequently need to make use of a couple specific utilities. In fact, each of these utilities are used in spike's core plugins.

If you are making a spike plugin, check out the documentation below, and one of these functions might be able to save you a bunch of code ๐Ÿ˜

Installation

npm install spike-util -S

Usage

All of the utilities require access to spike/webpack's options in order to work correctly. As such, the plugins are bundled in a class that must be initialized with the config.

const SpikeUtils = require('spike-util')

// webpack plugin apply function
apply (compiler) {
  const util = new SpikeUtils(compiler.options)
}

With it initialized, you can use any of the following functions:

  • util.addFilesAsWebpackEntries(compilation, files) - adds one or more files to webpack's pipeline so that it is processed without having to be require'd in an entry.
  • util.getOutputPath(path) - given a relative or absolute path to a file in a spike project, return it's output path relative to the project root.
  • util.removeAssets(compilation, files) - removes assets from webpack's pipeline so that they are not written as entries.
  • util.resolveRelativeSourcePath(path) - resolves a relative output path from a spike project to an absolute path to the source file.
  • util.isFileIgnored(file) - given a path to a file in a spike project, returns a boolean for whether the file is ignored or not.
  • util.runAll(compiler, cb) - run the given function when webpack's compiler initializes, bound to both the run and run-watch events.

And some static methods:

  • SpikeUtils.filePathFromLoader(loaderContext) - pass this inside a loader and it will return a file object with the absolute and relative paths to the current file being processed.

For more details on any given function, check out the source! I would never say this for any other library, but this is only one simple file, with fairly small functions that are extremely thoroughly documented, so I think it's worth jumping in.

License & Contributing

spike-util's People

Contributors

greenkeeperio-bot avatar

Watchers

James Cloos avatar Ava Johnson 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.