Use it when image is separated from the server
.
npm install lesca-cdn-path --save
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
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 | description | options | default |
---|---|---|---|
config.mode:sting | url loader mode. |
cdn , localhost
|
'cdn' |
- maintain if necessary