All Projects β†’ sheerun β†’ babel-plugin-file-loader

sheerun / babel-plugin-file-loader

Licence: MIT license
Like webpack's file-loader, but on server side. Allows for production-grade require('./file.png')

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to babel-plugin-file-loader

hapi-react-fullstack-boilerplate
Hapi, Sequelize, React, etc.
Stars: ✭ 21 (-41.67%)
Mutual labels:  isomorphic
missionlog
πŸš€ lightweight logging β€’ supports level based filtering and tagging β€’ weighs in at around 500 bytes
Stars: ✭ 19 (-47.22%)
Mutual labels:  isomorphic
geo-smart-system
Open Source Realtime Tracking System
Stars: ✭ 36 (+0%)
Mutual labels:  sse
Rephic
πŸ’Ό Rephic ζ˜―δΈ€δΈͺ基于 Koa ηš„ React ζœεŠ‘η«―ζΈ²ζŸ“ε·₯η¨‹θ„šζ‰‹ζžΆγ€‚ζ”―ζŒ React-Router, Redux δ»₯及 Less, Sass。
Stars: ✭ 23 (-36.11%)
Mutual labels:  isomorphic
mutoid
Reactive library for data fetching, caching, state management
Stars: ✭ 24 (-33.33%)
Mutual labels:  isomorphic
Demo.AspNetCore.ServerSentEvents
Demo project for demonstrating functionality of Lib.AspNetCore.ServerSentEvents
Stars: ✭ 52 (+44.44%)
Mutual labels:  sse
SoftLight
A shader-based Software Renderer Using The LightSky Framework.
Stars: ✭ 2 (-94.44%)
Mutual labels:  sse
sseserver
πŸ„ High-performance Server-Sent Events endpoint for Go
Stars: ✭ 88 (+144.44%)
Mutual labels:  sse
isomorphic-relay-app
Example isomorphic React-Relay-(Modern / Classic)-Router app and helper lib that connects to Artsy's GraphQL service
Stars: ✭ 13 (-63.89%)
Mutual labels:  isomorphic
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-47.22%)
Mutual labels:  isomorphic
cpuwhat
Nim utilities for advanced CPU operations: CPU identification, ISA extension detection, bindings to assorted intrinsics
Stars: ✭ 25 (-30.56%)
Mutual labels:  sse
pyro
Parallelized, Incremental Build Automation for TESV, SSE, and FO4 Projects
Stars: ✭ 45 (+25%)
Mutual labels:  sse
FFmpegPlayer
Simple FFmpeg video player
Stars: ✭ 72 (+100%)
Mutual labels:  sse
isomorphic-react-with-mobx
React + MobX + React-Router + Express
Stars: ✭ 52 (+44.44%)
Mutual labels:  isomorphic
react-ssr-starter
πŸ“š Featuring Webpack 4, React 17-18, SSR, HMR, prefetching, universal lazy-loading, and more
Stars: ✭ 18 (-50%)
Mutual labels:  isomorphic
kaonjs
Kaon.js is a react isomorphic app solution. It contains webpack build, hot reloading, code splitting and server side rendering.
Stars: ✭ 21 (-41.67%)
Mutual labels:  isomorphic
sse
HTML5 Server-Sent-Events for Go
Stars: ✭ 84 (+133.33%)
Mutual labels:  sse
webpack-isomorphic-compiler
A compiler that makes your life easier if you are building isomorphic webpack powered apps, that is, single page applications with server-side rendering
Stars: ✭ 16 (-55.56%)
Mutual labels:  isomorphic
isomorphic-webapp-starter
Isomorphic webapp starter (MongoDB, Express, React, Redux, Node)
Stars: ✭ 13 (-63.89%)
Mutual labels:  isomorphic
redux-pluto
redux pluto
Stars: ✭ 75 (+108.33%)
Mutual labels:  isomorphic

babel-plugin-file-loader CI Modern Node

Works the same as Webpack's file-loader, but on server side. With 95% test coverage!

Installation

yarn add babel-plugin-file-loader

Or if you like npm:

npm install babel-plugin-file-loader --save

Then put following "file-loader" as plugin in .babelrc:

{
  "plugins": ["file-loader"]
}

This is equivalent to following default configuration:

{
  "plugins": [
    [
      "file-loader",
      {
        "name": "[hash].[ext]",
        "extensions": ["png", "jpg", "jpeg", "gif", "svg"],
        "publicPath": "/public",
        "outputPath": "/public",
        "context": "",
        "limit": 0
      }
    ]
  ]
}

How it works

More or less as follows:

  1. Processes only import and require that reference files ending with one of "extensions"
  2. Calculates actual $name of resource by substituting placeholders in "name"
  3. Copies resource into $ROOT/$outputPath/$name where $ROOT is .babelrc location.
  4. Replaces import and require in code with "$publicPath/$name" string

Example usage

import img from './file.png'
const img2 = require('./file.svg')

Puts 0dcbbaa7013869e351f.png and 8d3fe267fe578005541.svg in the /public and replaces code with:

const img = "/public/0dcbbaa7013869e351f.png"
const img2 = "/public/8d3fe267fe578005541.svg"

For real-life example go to examples.

Options

outputPath

Tells where to put static files. By default it's "/public".

This path is relative to the root of project. Setting value null prevents the plugin to copy the file.

publicPath

Tells what prefix to output in the source. By default it's "/public" as well but it can be even full url, like so: "http://cdn.example.com/foobar/"

In this case the resulting code is:

const img = "http://cdn.example.com/foobar/0dcbbaa7013869e351f.png"

name

The default is [hash].[ext] where:

Name Type Default Description
[ext] {String} file.extname The extension of the resource
[name] {String} file.basename The basename of the resource
[path] {String} file.dirname The path of the resource relative to the context
[hash] {String} md5 The hash of the content, see below for more info

The full format [hash] is: [<hashType>:hash:<digestType>:<length>], where:

Name Type Default Description
hashType {String} md5 sha1, md5, sha256, sha512
digestType {String} base64 hex, base26, base32, base36, base49, base52, base58, base62, base64
length {Number} 128 The length in chars

For example: [md5:hash:base58:8] or [hash:base36].

extensions

List of extension file-loader should look for in imports. All other imports are ignored.

context

Path to directory relative to .babelrc where application source resides. By default "", but can be e.g. "/src".

limit

Value in byte to determine if the content is base64 inlined. In that case, the file is not copy to outputPath. It replicates url-loader webpack loader behaviour.

Default is 0 which means nothing is inlined.

Contributing

Yes, please!

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].