From 1cd206e3119f0bcf77e3d3c54b09ccb9d850d6be Mon Sep 17 00:00:00 2001 From: Ryan Irilli Date: Tue, 9 Oct 2018 09:46:20 -0700 Subject: [PATCH] feat(core): Add rollup-plugin-svg --- package-lock.json | 11 ++++++++++- packages/pectin-core/lib/getPlugins.js | 3 +++ packages/pectin-core/package.json | 3 ++- .../test/__snapshots__/pectin-core.test.js.snap | 12 ++++++++++-- packages/pectin-core/test/pectin-core.test.js | 6 +++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index da44a34..f3f1cf4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1002,7 +1002,8 @@ "rollup-plugin-json": "^3.0.0", "rollup-plugin-main-entry": "file:packages/rollup-plugin-main-entry", "rollup-plugin-node-resolve": "^3.3.0", - "rollup-plugin-subpath-externals": "file:packages/rollup-plugin-subpath-externals" + "rollup-plugin-subpath-externals": "file:packages/rollup-plugin-subpath-externals", + "rollup-plugin-svg": "^1.0.1" } }, "@types/estree": { @@ -8726,6 +8727,14 @@ } } }, + "rollup-plugin-svg": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-svg/-/rollup-plugin-svg-1.0.1.tgz", + "integrity": "sha1-neQ5Q87+rLndsJs+qN253mVS7eE=", + "requires": { + "rollup-pluginutils": "^1.3.1" + } + }, "rollup-pluginutils": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz", diff --git a/packages/pectin-core/lib/getPlugins.js b/packages/pectin-core/lib/getPlugins.js index ced4128..264b834 100644 --- a/packages/pectin-core/lib/getPlugins.js +++ b/packages/pectin-core/lib/getPlugins.js @@ -6,6 +6,7 @@ const json = require('rollup-plugin-json'); const nodeResolve = require('rollup-plugin-node-resolve'); const mainEntry = require('rollup-plugin-main-entry'); const subpathExternals = require('rollup-plugin-subpath-externals'); +const svg = require('rollup-plugin-svg'); const babelrc = require('@pectin/babelrc'); module.exports = async function getPlugins(pkg) { @@ -28,5 +29,7 @@ module.exports = async function getPlugins(pkg) { babel(rc), // https://github.com/rollup/rollup-plugin-commonjs#usage commonjs(), + // https://github.com/antony/rollup-plugin-svg + svg(), ]; }; diff --git a/packages/pectin-core/package.json b/packages/pectin-core/package.json index 6759d91..78085b9 100644 --- a/packages/pectin-core/package.json +++ b/packages/pectin-core/package.json @@ -41,6 +41,7 @@ "rollup-plugin-json": "^3.0.0", "rollup-plugin-main-entry": "file:../rollup-plugin-main-entry", "rollup-plugin-node-resolve": "^3.3.0", - "rollup-plugin-subpath-externals": "file:../rollup-plugin-subpath-externals" + "rollup-plugin-subpath-externals": "file:../rollup-plugin-subpath-externals", + "rollup-plugin-svg": "^1.0.1" } } diff --git a/packages/pectin-core/test/__snapshots__/pectin-core.test.js.snap b/packages/pectin-core/test/__snapshots__/pectin-core.test.js.snap index de204c9..b5ec79f 100644 --- a/packages/pectin-core/test/__snapshots__/pectin-core.test.js.snap +++ b/packages/pectin-core/test/__snapshots__/pectin-core.test.js.snap @@ -3,14 +3,22 @@ exports[`pectin-core integration: cjs 1`] = ` "'use strict'; -function foo() {} +var svgTest = 'data:image/svg+xml;base64,dGVzdDs='; + +function foo() { + return svgTest; +} module.exports = foo; " `; exports[`pectin-core integration: esm 1`] = ` -"function foo() {} +"var svgTest = 'data:image/svg+xml;base64,dGVzdDs='; + +function foo() { + return svgTest; +} export default foo; " diff --git a/packages/pectin-core/test/pectin-core.test.js b/packages/pectin-core/test/pectin-core.test.js index 414cba3..81f265a 100644 --- a/packages/pectin-core/test/pectin-core.test.js +++ b/packages/pectin-core/test/pectin-core.test.js @@ -60,6 +60,7 @@ describe('pectin-core', () => { expect.objectContaining({ name: 'json' }), expect.objectContaining({ name: 'babel' }), expect.objectContaining({ name: 'commonjs' }), + expect.objectContaining({ name: 'svg' }), ], }); }); @@ -175,7 +176,10 @@ describe('pectin-core', () => { }, }), src: Dir({ - 'index.js': File('export default function foo() {};'), + 'test.svg': File(`test`), + 'index.js': File( + `import svgTest from './test.svg'; export default function foo() { return svgTest; };` + ), }), }); const pkgPath = path.join(cwd, 'package.json');