Skip to content

Commit

Permalink
Merge pull request #5 from r0skar/master
Browse files Browse the repository at this point in the history
Replace deprecated `onwrite` hook with `writeBundle`
  • Loading branch information
haifeng2013 authored May 17, 2019
2 parents 64d9ce2 + e3d2261 commit 1c1706f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"eslint": "^5.0.1",
"jasmine": "^3.1.0",
"rollup": "^0.62.0",
"rollup": "^1.1.0",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.0.0"
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import buble from 'rollup-plugin-buble';
const pkg = require('./package.json');

export default {
entry: 'src/index.js',
targets: [
{ format: 'cjs', dest: pkg['main'] },
{ format: 'es', dest: pkg['module'] }
input: 'src/index.js',
output: [
{ format: 'cjs', file: pkg['main'] },
{ format: 'es', file: pkg['module'] }
],
external: ['fs', 'path', 'crypto'],
plugins: [
Expand Down
14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ export default (opt = {}) => {

return {
name: 'html',
onwrite(config, data) {
writeBundle(config, data) {
const isHTML = /^.*<html>.*<\/html>$/.test(template);
const $ = cheerio.load(isHTML?template:readFileSync(template).toString());
const head = $('head');
const body = $('body');
const { file, sourcemap } = config;
let entryConfig = {};
Object.values(config).forEach((c) => {
if (c.isEntry) entryConfig = c
})
const { fileName, sourcemap } = entryConfig
const fileList = [];
// relative('./', file) will not be equal to file when file is a absolute path
const destPath = relative('./', file);
const destPath = relative('./', fileName);
const destDir = dest || destPath.slice(0, destPath.indexOf(pathSeperator));
const destFile = `${destDir}/${filename || basename(template)}`;

Expand Down Expand Up @@ -86,9 +90,9 @@ export default (opt = {}) => {
}

let src = isURL(file) ? file : relative(destDir, file);

if (node.timestamp) {
src += '?t=' + (new Date()).getTime();
src += '?t=' + (new Date()).getTime();
}

if (type === 'js') {
Expand Down

0 comments on commit 1c1706f

Please sign in to comment.