From: Ulrich-Matthias Schäfer Date: Sat, 1 Dec 2018 12:32:23 +0000 (+0100) Subject: dont generate esm bundle anymore and link to src/main.js directly. Move bower to... X-Git-Tag: 3.0.0~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=637039fbde6a68f18f89ce8677f6b8ca667ba689;p=svg.js.git dont generate esm bundle anymore and link to src/main.js directly. Move bower to its own repo rename makeNode back to create --- diff --git a/.config/rollup.config.js b/.config/rollup.config.js index 32096e5..c056776 100644 --- a/.config/rollup.config.js +++ b/.config/rollup.config.js @@ -21,13 +21,13 @@ const headerLong = `/*! const headerShort = `/*! ${pkg.name} v${pkg.version} ${pkg.license}*/;` -const getBabelConfig = (esm, targets = { esmodules: true }, corejs = false) => babel({ +const getBabelConfig = (targets, corejs = false) => babel({ include: 'src/**', runtimeHelpers: true, babelrc: false, presets: [['@babel/preset-env', { modules: false, - targets: esm ? targets : pkg.browserslist, + targets: targets || pkg.browserslist, useBuiltIns: 'usage' }]], plugins: [['@babel/plugin-transform-runtime', { @@ -70,21 +70,29 @@ const classes = [ 'Use' ] -const config = esm => ({ - input: esm ? './src/main.js' : './src/svg.js', +const config = (node, min) => ({ + input: node ? './src/main.js' : './src/svg.js', output: { - file: esm ? './dist/svg.js' : './dist/svg.min.js', + file: node ? './dist/svg.node.js' + : min ? './dist/svg.min.js' + : './dist/svg.js', + format: node ? 'cjs' : 'iife', name: 'SVG', - sourcemap: 'external', - format: esm ? 'esm' : 'iife', - banner: esm ? headerLong : headerShort + sourcemap: true, + banner: headerLong, + // remove Object.freeze + freeze: false + }, + treeshake: { + // property getter have no sideeffects + propertyReadSideEffects: false }, plugins: [ - resolve({ browser: true }), + resolve({ browser: !node }), commonjs(), - getBabelConfig(esm), + getBabelConfig(node && 'maintained node versions'), filesize(), - esm ? {} : uglify({ + !min ? {} : uglify({ mangle: { reserved: classes }, @@ -95,23 +103,7 @@ const config = esm => ({ ] }) -const nodeConfig = () => ({ - input: './src/main.js', - output: { - file: './dist/svg.node.js', - name: 'SVG', - sourcemap: 'external', - format: 'cjs', - banner: headerLong - }, - plugins: [ - resolve(), - commonjs(), - getBabelConfig(true, 'maintained node versions'), - filesize() - ] -}) - -const modes = [true, false] +// [node, minified] +const modes = [[false], [false, true], [true]] -export default modes.map(config).concat(nodeConfig()) +export default modes.map(m => config(...m)) diff --git a/.config/rollup.tests.js b/.config/rollup.tests.js new file mode 100644 index 0000000..518be94 --- /dev/null +++ b/.config/rollup.tests.js @@ -0,0 +1,29 @@ +import babel from 'rollup-plugin-babel' +import multiEntry from 'rollup-plugin-multi-entry' + +export default { + input: ['spec/setupBrowser.js', 'spec/spec/types/*.js', 'spec/spec/utils/*.js'], + output: { + file: 'spec/es5TestBundle.js', + name: 'SVGTests', + sourceMap: true, + format: 'iife' + }, + plugins: [ + babel({ + include: 'src/**', + runtimeHelpers: true, + babelrc: false, + presets: [['@babel/preset-env', { + modules: false + }]] + // plugins: [["@babel/plugin-transform-runtime", { + // corejs: false, + // helpers: true, + // regenerator: true, + // useESModules: true + // }]] + }), + multiEntry() + ] +} diff --git a/.gitignore b/.gitignore index 2b1e47e..8a91f66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,10 @@ .DS_Store .idea .importjs.js -public -site/ -bleed/ -docs/ -obsolete/ test/ -src/index.js node_modules/ .vscode/ coverage/ -fonts/ spec/es5TestBundle.js .env +dist diff --git a/bower.json b/bower.json deleted file mode 100644 index 83a41a3..0000000 --- a/bower.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "svg.js", - "homepage": "https://svgdotjs.github.io/", - "authors": [ - "Wout Fierens ", - "Ulrich-Matthias Schäfer ", - "Jon Ege Ronnenberg " - ], - "description": "A lightweight library for manipulating and animating SVG", - "main": "dist/svg.min.js", - "keywords": [ - "svg", "vector", "graphics" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "spec/", - "src/", - "gulpfile.js" - ] -} diff --git a/package.json b/package.json index 8fc5e37..1ac0436 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "unpkg": "dist/svg.min.js", "jsdelivr": "dist/svg.min.js", "browser": "dist/svg.min.js", - "module": "dist/svg.js", + "module": "src/main.js", "maintainers": [ { "name": "Wout Fierens", @@ -53,7 +53,7 @@ "scripts": { "build": "npm run fix && npm run rollup", "build:polyfills": "npx rollup -c .config/rollup.polyfills.js", - "build:tests": "npx rollup -c rollup.tests.js", + "build:tests": "npx rollup -c .config/rollup.tests.js", "fix": "npx eslint ./src --fix", "lint": "eslint ./src", "rollup": "rollup -c .config/rollup.config.js", @@ -62,8 +62,11 @@ "test:ci": "karma start .config/karma.conf.saucelabs.js", "test:svgdom": "node -r esm ./spec/runSVGDomTest.js || true", "test:es6": "npx karma start .config/karma.es6.js --single-run", + "bower:copy": "cp ../svg.js/LICENSE ../svg.js/README.md ../svg.js/dist/svg.js ../svg.js/dist/svg.min.js ../svg.js/dist/polyfills.js ../svg.js/dist/polyfillsIE.js .", + "bower:tag": "git add -- LICENSE README.md svg.js svg.min.js && git commit -m \"${npm_package_version}\" && git tag -am \"${npm_package_version}\" v${npm_package_version} && git push && git push --tags", + "zip": "zip -j dist/svg.js.zip -- LICENSE README.md API.md CHANGELOG.md dist/svg.js.js dist/svg.min.js dist/polyfills.js dist/polyfillsIE.js", "prepublishOnly": "npm run build && npm run build:polyfills && npm test", - "postPublish": "echo Please upload a zip to the github release containing the dist, license and changelog" + "postpublish": "git push && git push --tags && cd ../svg.js-bower && git pull && npm run bower:copy && npm run bower:tag && cd ../svg.js && npm run zip" }, "devDependencies": { "@babel/core": "^7.1.2", diff --git a/rollup.tests.js b/rollup.tests.js deleted file mode 100644 index 655654b..0000000 --- a/rollup.tests.js +++ /dev/null @@ -1,29 +0,0 @@ -import babel from 'rollup-plugin-babel' -import multiEntry from 'rollup-plugin-multi-entry' - -export default { - input: ['spec/setupBrowser.js', 'spec/spec/types/*.js', 'spec/spec/utils/*.js'], - output: { - file: 'spec/es5TestBundle.js', - name: 'SVGTests', - sourceMap: true, - format: 'iife' - }, - plugins: [ - babel({ - include: 'src/**', - runtimeHelpers: true, - babelrc: false, - presets: [["@babel/preset-env", { - modules: false, - }]], - // plugins: [["@babel/plugin-transform-runtime", { - // corejs: false, - // helpers: true, - // regenerator: true, - // useESModules: true - // }]] - }), - multiEntry() - ] -} diff --git a/spec/spec/svg.js b/spec/spec/svg.js index 57db8e0..41fce3d 100644 --- a/spec/spec/svg.js +++ b/spec/spec/svg.js @@ -80,9 +80,9 @@ describe('SVG', function() { }) }) - describe('makeNode()', function() { + describe('create()', function() { it('creates an element with given node name and return it', function() { - var element = SVG.makeNode('rect') + var element = SVG.create('rect') expect(element.nodeName).toBe('rect') }) diff --git a/spec/spec/utils/adopter.js b/spec/spec/utils/adopter.js index 8087731..006b599 100644 --- a/spec/spec/utils/adopter.js +++ b/spec/spec/utils/adopter.js @@ -1,7 +1,7 @@ const { any, createSpy, objectContaining } = jasmine import { - makeNode, + create, makeInstance, nodeOrNew, register, @@ -26,9 +26,9 @@ describe('Adopter.js', () => { Node = globals.window.Node }) - describe('makeNode()', () => { + describe('create()', () => { it('creates a node of the specified type', () => { - let rect = makeNode('rect') + let rect = create('rect') expect(rect).toEqual(any(Node)) expect(rect.nodeName).toBe('rect') }) @@ -79,7 +79,7 @@ describe('Adopter.js', () => { }) it('calls adopt when passed a node', () => { - makeInstance(makeNode('rect')) + makeInstance(create('rect')) expect(adoptSpy).toHaveBeenCalledWith(any(Node)) expect(adoptSpy).toHaveBeenCalledWith(objectContaining({nodeName: 'rect'})) diff --git a/src/elements/Dom.js b/src/elements/Dom.js index f6e72c9..fa4ed08 100644 --- a/src/elements/Dom.js +++ b/src/elements/Dom.js @@ -4,7 +4,7 @@ import { eid, extend, makeInstance, - makeNode, + create, register } from '../utils/adopter.js' import { find } from '../modules/core/selector.js' @@ -90,7 +90,7 @@ export default class Dom extends EventTarget { } element (nodeName) { - return this.put(new Dom(makeNode(nodeName))) + return this.put(new Dom(create(nodeName))) } // Get first child diff --git a/src/utils/adopter.js b/src/utils/adopter.js index a826607..4f50ca0 100644 --- a/src/utils/adopter.js +++ b/src/utils/adopter.js @@ -8,7 +8,7 @@ const elements = {} export const root = '___SYMBOL___ROOT___' // Method for element creation -export function makeNode (name) { +export function create (name) { // create element return globals.document.createElementNS(ns, name) } @@ -28,7 +28,7 @@ export function makeInstance (element) { return adopter(globals.document.querySelector(element)) } - var node = makeNode('svg') + var node = create('svg') node.innerHTML = element // We can use firstChild here because we know, @@ -39,7 +39,7 @@ export function makeInstance (element) { } export function nodeOrNew (name, node) { - return node instanceof globals.window.Node ? node : makeNode(name) + return node instanceof globals.window.Node ? node : create(name) } // Adopt existing svg elements