lesca-cdn-path
v2.0.6
Published
relative path to absolute path
Downloads
13
Maintainers
Readme
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