add image asset handler plugin
This commit is contained in:
@@ -3,8 +3,50 @@ import commonjs from '@rollup/plugin-commonjs'
|
||||
import bundles from './build/index'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import buble from '@rollup/plugin-buble';
|
||||
import buble from '@rollup/plugin-buble'
|
||||
import json from "@rollup/plugin-json"
|
||||
import image from '@rollup/plugin-image'
|
||||
|
||||
function searchImages(dir, images) {
|
||||
const files = fs.readdirSync(dir)
|
||||
files.forEach((item, index) => {
|
||||
var fullPath = path.join(dir, item)
|
||||
const stat = fs.statSync(fullPath)
|
||||
if (stat.isDirectory()) {
|
||||
searchImages(path.join(dir, item), images)
|
||||
} else {
|
||||
if(fullPath.endsWith('.png')) {
|
||||
images.push(fullPath)
|
||||
}
|
||||
}
|
||||
})
|
||||
return images
|
||||
}
|
||||
|
||||
const allImages = []
|
||||
searchImages('src', allImages)
|
||||
|
||||
function mkdirsSync(dirname) {
|
||||
if (fs.existsSync(dirname)) {
|
||||
return true
|
||||
} else {
|
||||
if (mkdirsSync(path.dirname(dirname))) {
|
||||
fs.mkdirSync(dirname)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allImages.forEach((value) => {
|
||||
let path = __dirname + '/build/' + value
|
||||
let index = path.lastIndexOf('/')
|
||||
mkdirsSync(path.substring(0, index))
|
||||
|
||||
fs.copyFile(__dirname + '/' + value, __dirname + '/build/' + value, error => {
|
||||
console.log(error)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
function readDirs(dirPath, files) {
|
||||
if (fs.statSync(dirPath).isDirectory()) {
|
||||
@@ -51,11 +93,12 @@ export default
|
||||
resolve({ mainFields: ["jsnext"] }),
|
||||
commonjs(),
|
||||
json(),
|
||||
image(),
|
||||
],
|
||||
external: ['reflect-metadata', 'doric'],
|
||||
onwarn: function (warning) {
|
||||
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
|
||||
console.warn(warning.message);
|
||||
if (warning.code === 'THIS_IS_UNDEFINED') { return }
|
||||
console.warn(warning.message)
|
||||
}
|
||||
}
|
||||
}).concat(
|
||||
@@ -76,11 +119,12 @@ export default
|
||||
buble({
|
||||
transforms: { dangerousForOf: true }
|
||||
}),
|
||||
image(),
|
||||
],
|
||||
external: ['reflect-metadata', 'doric'],
|
||||
onwarn: function (warning) {
|
||||
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
|
||||
console.warn(warning.message);
|
||||
if (warning.code === 'THIS_IS_UNDEFINED') { return }
|
||||
console.warn(warning.message)
|
||||
}
|
||||
}
|
||||
}))
|
||||
Reference in New Issue
Block a user