GithubHelp home page GithubHelp logo

kossnocorp / static-files-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 5.0 65 KB

A companion plugin for static-file-loader, it emits a JSON file with paths to included static files.

JavaScript 100.00%

static-files-webpack-plugin's Introduction

StaticFilesWebpackPlugin

Build Status Build Status

A companion plugin for static-file-loader, it emits a JSON file with processed static file paths.

It's like assets-webpack-plugin but for static assets.

Installation

Install static-file-loader and file-loader:

npm install static-file-loader file-loader --save-dev

Install the plugin:

npm install static-files-webpack-plugin --save-dev

Example

In a webpack config:

var path = require('path')
var StaticFilesWebpackPlugin = require('static-files-webpack-plugin')

// ...

var distPath = path.join(process.cwd(), 'dist')

module.exports = {
  // ...

  output: {
    path: distPath,
    publicPath: '/',

    // ...
  },

  plugins: [new StaticFilesWebpackPlugin({
    outputPath: path.join(distPath, 'static.json')
  })]
}

In an entry:

require.context('!!static-file!./static', true, /.+/)

// ...

Run webpack to build entries:

webpack

cat dist/static.json:

{
  "/Users/koss/src/date-fns/date-fns.org/ui/static/img/favicon.png": "/e09ef13032827f865ef8004c185277f7.png"
}

Options

outputPath

Specifies an output path for the JSON file. By default outputPath equals to path.join(process.cwd(), 'static.json').

It could be an absolute path:

new StaticFilesWebpackPlugin({
  outputPath: path.join(distPath, 'static.json')
})

โ€ฆ or a path relative to process.cwd():

new StaticFilesWebpackPlugin({
  outputPath: 'static.json'
})

useRelativePaths

Allows to omit process.cwd() in the JSON keys. By default it equals to false and produces such output:

{
  "/Users/koss/src/date-fns/date-fns.org/ui/static/img/favicon.png": "/e09ef13032827f865ef8004c185277f7.png"
}

If useRelativePaths is true, then it will looks like this:

{
  "ui/static/img/favicon.png": "/e09ef13032827f865ef8004c185277f7.png"
}

The option also could be a string (an absolute path or a path relative to process.cwd()):

new StaticFilesWebpackPlugin({
  useRelativePaths: 'ui/static'
})
{
  "img/favicon.png": "/e09ef13032827f865ef8004c185277f7.png"
}

prefix

Use prefix for replacing the string part of the path that was passed to useRelativePaths.

new StaticFilesWebpackPlugin({
  useRelativePaths: 'ui/static',
  prefix: 'vendor/ui'
})
{
  "vendor/ui/img/favicon.png": "/e09ef13032827f865ef8004c185277f7.png"
}

replace

Use replace for rewriting the resulting relative paths. For example, when some static assets are symlinked from the different folder you might want to replace specific part of the path.

new StaticFilesWebpackPlugin({
  useRelativePaths: true,
  replace: (processedPath) => { processedPath.replace('img', 'static/img') }
})
{
  "static/img/favicon.png": "/e09ef13032827f865ef8004c185277f7.png"
}

License

MIT

static-files-webpack-plugin's People

Contributors

doug-wade avatar ertrzyiks avatar falsefalse avatar kossnocorp avatar kri0-gen avatar sunesimonsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

static-files-webpack-plugin's Issues

Test current node versions

Currently, we test node 0.12 and 4, but we do not test node 6 and 8, which are active lts and current, respectively. To ensure this project is working for all nodes, we should test them all on CI.

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.