lesca-cdn-path

2.0.6 • Public • Published

NPM React React React React React NPM

Why use it.

Use it when image is separated from the server.

Installation

npm install lesca-cdn-path --save

Usage

As a Node module: install in entry js.

import { install } from 'lesca-cdn-path';

install('https://cdn.hostname.com/files/');

setup mode

import { config } from 'lesca-cdn-path';

// ? test at 'localhost'?;
config.mode = 'localhost'; // default is 'cdn'

In the compnenet

  • use require
import { path } from 'lesca-cdn-path';

const component = () => <img src={path(require('./img/image.jpg'))} />;
// http://localhost:8080/img/image.jpg => https://cdn.hostname.com/files/img/image.jpg
  • use import
import { path } from 'lesca-cdn-path';
import Image from './img/image.jpg';

const component = () => <img src={path(Image)} />;
// http://localhost:8080/img/image.jpg => https://cdn.hostname.com/files/img/image.jpg

Development

Methods

method description return
.install(cdn-path:string) set the base path was generated by the CDN void
.path(local-path:string) localhost url path cdn-path

Properties

Properties description options default
config.mode:sting url loader mode. cdn, localhost 'cdn'

Features

  • maintain if necessary

Package Sidebar

Install

npm i lesca-cdn-path

Weekly Downloads

1

Version

2.0.6

License

MIT

Unpacked Size

223 kB

Total Files

13

Last publish

Collaborators

  • jameshsu1125