Skip to content

Commit ce9a640

Browse files
committed
chore: change project structure
1 parent 4d44289 commit ce9a640

File tree

6 files changed

+55
-95
lines changed

6 files changed

+55
-95
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
dist/
12
node_modules/

index.es.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "gulp-inline-source-html",
33
"version": "1.0.2",
44
"description": "Inlines flagged js, css, and img sources in html with inline-source",
5-
"main": "index.js",
6-
"module": "index.es.js",
5+
"main": "dist/index.js",
6+
"module": "dist/index.es.js",
77
"directories": {
88
"test": "test"
99
},

rollup.config.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ const commonjs = require('@rollup/plugin-commonjs')
22
const pkg = require('./package.json')
33

44
export default {
5-
input: 'index.js',
5+
input: 'src/index.js',
66
plugins: [commonjs()],
77
external: Object.keys(pkg.dependencies),
8-
output: {
9-
file: pkg.module,
10-
format: 'es'
11-
}
8+
output: [
9+
{
10+
file: pkg.main,
11+
format: 'cjs',
12+
exports: 'auto'
13+
},
14+
{
15+
file: pkg.module,
16+
format: 'es'
17+
}
18+
]
1219
}

src/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict'
2+
3+
const { inlineSource } = require('inline-source')
4+
const through = require('through2')
5+
const PluginError = require('plugin-error')
6+
7+
const PLUGIN_NAME = 'gulp-inline-source-html'
8+
9+
/**
10+
* inline-source wrapper
11+
* @param {Object} [options] - https://github.com/popeindustries/inline-source#usage
12+
*/
13+
const gulpInlineSourceHtml = (pluginOptions = {}) => {
14+
return through.obj((file, _, callback) => {
15+
if (file.isNull()) {
16+
return callback(null, file)
17+
}
18+
19+
if (file.isStream()) {
20+
return callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'))
21+
}
22+
23+
const defaultOptions = { rootpath: file.base }
24+
const options = { ...defaultOptions, ...pluginOptions }
25+
;(async () => {
26+
try {
27+
const newFileContents = await inlineSource(
28+
String(file.contents),
29+
options
30+
)
31+
file.contents = Buffer.from(newFileContents)
32+
callback(null, file)
33+
} catch (err) {
34+
callback(new PluginError(PLUGIN_NAME, err))
35+
}
36+
})()
37+
})
38+
}
39+
40+
module.exports = gulpInlineSourceHtml

0 commit comments

Comments
 (0)