rollup-plugin-visualizer
Advanced tools
Comparing version 1.1.1 to 2.0.0
{ | ||
"name": "rollup-plugin-visualizer", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"main": "plugin.js", | ||
@@ -16,9 +16,12 @@ "author": "Denis Bardadym <bardadymchik@gmail.com>", | ||
"scripts": { | ||
"build": "rollup -c rollup.config.js -o ./lib/pluginmain.js", | ||
"build:dev": "rollup -c rollup.config-dev.js -o ./lib/pluginmain.js", | ||
"prepare": "npm run build" | ||
"lint": "eslint .", | ||
"build": "cp ./src/*.css ./lib/ && rollup -c rollup.config.js -i ./src/script-sunburst.js -o ./lib/main-sunburst.js && rollup -c rollup.config.js -i ./src/script-treemap.js -o ./lib/main-treemap.js", | ||
"build:dev": "cp ./src/*.css ./lib/ && rollup -c rollup.config-dev.js -i ./src/script-sunburst.js -o ./lib/main-sunburst.js && rollup -c rollup.config-dev.js -i ./src/script-treemap.js -o ./lib/main-treemap.js", | ||
"prepare": "yarn run build", | ||
"test": "echo \"Error: no test specified\" && exit 0" | ||
}, | ||
"dependencies": { | ||
"d3-collection": "^1.0.7", | ||
"mkdirp": "^0.5.1", | ||
"opn": "^5.4.0", | ||
"open": "^6.3.0", | ||
"source-map": "^0.7.3", | ||
@@ -33,3 +36,3 @@ "typeface-oswald": "0.0.54" | ||
"d3-hierarchy": "^1.1.8", | ||
"d3-scale": "^2.2.2", | ||
"d3-scale": "^3.0.0", | ||
"d3-selection": "^1.4.0", | ||
@@ -39,5 +42,5 @@ "d3-shape": "^1.3.4", | ||
"prettier": "^1.16.4", | ||
"rollup": "^1.2.2", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"rollup": "^1.14.0", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.1", | ||
"rollup-plugin-uglify": "^6.0.2" | ||
@@ -44,0 +47,0 @@ }, |
"use strict"; | ||
const fs = require("fs"); | ||
const fs = require("fs").promises; | ||
const path = require("path"); | ||
const mkdirp = require("mkdirp"); | ||
const util = require("util"); | ||
const opn = require("opn"); | ||
const SourceMapConsumer = require("source-map").SourceMapConsumer; | ||
const opn = require("open"); | ||
const { SourceMapConsumer } = require("source-map"); | ||
const writeFileAsync = util.promisify(fs.writeFile); | ||
const mkdirpAsync = util.promisify(mkdirp); | ||
const buildHtml = require("./build-html"); | ||
const readFont = (type = "woff", weight = 700) => { | ||
const fonts = path.join(require.resolve("typeface-oswald"), "../files/"); | ||
return fs.readFileSync(path.join(fonts, `./oswald-latin-${weight}.${type}`)); | ||
}; | ||
const cssString = fs.readFileSync(path.join(__dirname, "lib", "./style.css"), "utf8"); | ||
const jsString = fs.readFileSync(path.join(__dirname, "lib", "./pluginmain.js"), "utf8"); | ||
const fontWeight = 500; | ||
const fontface = buildFontface("Oswald", fontWeight, { | ||
woff: readFont("woff", fontWeight).toString("base64"), | ||
woff2: readFont("woff2", fontWeight).toString("base64") | ||
}); | ||
const PLUGIN_PREFIX = "\u0000"; | ||
@@ -36,2 +20,4 @@ | ||
const template = opts.template || "sunburst"; //'sunburst' | ||
return { | ||
@@ -53,3 +39,3 @@ async generateBundle(outputOptions, outputBundle) { | ||
} | ||
const html = buildHtml(title, roots, filename); | ||
const html = await buildHtml(title, roots, template); | ||
await writeFile(filename, html); | ||
@@ -63,3 +49,3 @@ if (open) { | ||
function buildTree(bundle, useSourceMap) { | ||
const buildTree = (bundle, useSourceMap) => { | ||
const root = { | ||
@@ -69,4 +55,4 @@ name: "root", | ||
}; | ||
Object.keys(bundle.modules).forEach(id => { | ||
const module = bundle.modules[id]; | ||
for (const [id, module] of Object.entries(bundle.modules)) { | ||
const name = id; | ||
@@ -83,42 +69,9 @@ const m = { | ||
} | ||
}); | ||
} | ||
return root; | ||
} | ||
}; | ||
function buildHtml(title, root) { | ||
return `<!doctype html> | ||
<title>${title}</title> | ||
<meta charset="utf-8"> | ||
<style>${cssString}\n${fontface}</style> | ||
<div> | ||
<div> | ||
<h1>${title}</h1> | ||
<div id="charts"> | ||
</div> | ||
</div> | ||
</div> | ||
<script>window.nodesData = ${JSON.stringify(root)};</script> | ||
<script charset="UTF-8"> | ||
${jsString} | ||
</script> | ||
`; | ||
} | ||
function buildFontface(name, weight, { woff2, woff }) { | ||
return ` | ||
@font-face { | ||
font-family: '${name}'; | ||
font-display: swap; | ||
font-style: normal; | ||
font-weight: ${weight}; | ||
src: | ||
url(data:font/woff2;charset=utf-8;base64,${woff2}) format('woff2'), | ||
url(data:application/font-woff;charset=utf-8;base64,${woff}) format('woff'); | ||
}`; | ||
} | ||
async function writeFile(filename, contents) { | ||
await mkdirpAsync(path.dirname(filename)); | ||
return await writeFileAsync(filename, contents); | ||
await fs.mkdir(path.dirname(filename), { recursive: true }); | ||
return await fs.writeFile(filename, contents); | ||
} | ||
@@ -125,0 +78,0 @@ |
# Rollup Plugin Visualizer | ||
[![NPM Version](https://img.shields.io/npm/v/rollup-plugin-visualizer.svg)](https://npmjs.org/package/rollup-plugin-visualizer) | ||
[![NPM Version](https://img.shields.io/npm/v/rollup-plugin-visualizer.svg)](https://npmjs.org/package/rollup-plugin-visualizer) [![Travis CI build status](https://img.shields.io/travis/com/btd/rollup-plugin-visualizer.svg)](https://travis-ci.com/btd/rollup-plugin-visualizer) | ||
@@ -68,4 +68,9 @@ Visualize and analyze your Rollup bundle to see which modules are taking up space. | ||
## Diagram template | ||
Currently this plugin can generate 'sunburst' and 'treemap' style diagrams. | ||
Use `template` options with one of `sunburst` (default) or `treemap`. | ||
## Acknowledgements | ||
Initially this plugin was based on [webpack-visualizer](http://chrisbateman.github.io/webpack-visualizer/), but in the end used only styles and layout. Thanks to the tons of people around internet for great examples of d3 usage. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179935
8
5285
76
6
2
1
+ Addedd3-collection@^1.0.7
+ Addedopen@^6.3.0
+ Addedd3-collection@1.0.7(transitive)
+ Addedopen@6.4.0(transitive)
- Removedopn@^5.4.0
- Removedopn@5.5.0(transitive)