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', {
'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
},
]
})
-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))
--- /dev/null
+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()
+ ]
+}
.DS_Store
.idea
.importjs.js
-public
-site/
-bleed/
-docs/
-obsolete/
test/
-src/index.js
node_modules/
.vscode/
coverage/
-fonts/
spec/es5TestBundle.js
.env
+dist
+++ /dev/null
-{
- "name": "svg.js",
- "homepage": "https://svgdotjs.github.io/",
- "authors": [
- "Wout Fierens <wout@mick-wout.com>",
- "Ulrich-Matthias Schäfer <ulima.ums@googlemail.com>",
- "Jon Ege Ronnenberg <jon.ronnenberg+svgjs@gmail.com>"
- ],
- "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"
- ]
-}
"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",
"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",
"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",
+++ /dev/null
-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()
- ]
-}
})
})
- 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')
})
const { any, createSpy, objectContaining } = jasmine
import {
- makeNode,
+ create,
makeInstance,
nodeOrNew,
register,
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')
})
})
it('calls adopt when passed a node', () => {
- makeInstance(makeNode('rect'))
+ makeInstance(create('rect'))
expect(adoptSpy).toHaveBeenCalledWith(any(Node))
expect(adoptSpy).toHaveBeenCalledWith(objectContaining({nodeName: 'rect'}))
eid,
extend,
makeInstance,
- makeNode,
+ create,
register
} from '../utils/adopter.js'
import { find } from '../modules/core/selector.js'
}
element (nodeName) {
- return this.put(new Dom(makeNode(nodeName)))
+ return this.put(new Dom(create(nodeName)))
}
// Get first child
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)
}
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,
}
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