From 853db4ef0e9da4952e8189e3f86fb62e6c506693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Sun, 22 Mar 2020 08:57:46 +0100 Subject: [PATCH] fix(parcel-plugin): support "parcel" and "parcel-bundler" Closes #410 --- packages/parcel-plugin-svgr/package.json | 3 --- packages/parcel-plugin-svgr/src/asset.js | 13 ++++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/parcel-plugin-svgr/package.json b/packages/parcel-plugin-svgr/package.json index 12d6733b..2d08cfb2 100644 --- a/packages/parcel-plugin-svgr/package.json +++ b/packages/parcel-plugin-svgr/package.json @@ -29,9 +29,6 @@ "build": "babel --config-file ../../babel.config.js -d lib --ignore \"**/*.test.js\" src", "prepublishOnly": "yarn run build" }, - "peerDependencies": { - "parcel": "^1.10.0" - }, "dependencies": { "@babel/core": "^7.7.5", "@babel/plugin-transform-react-constant-elements": "^7.7.4", diff --git a/packages/parcel-plugin-svgr/src/asset.js b/packages/parcel-plugin-svgr/src/asset.js index 081af60c..0a4617bd 100644 --- a/packages/parcel-plugin-svgr/src/asset.js +++ b/packages/parcel-plugin-svgr/src/asset.js @@ -1,4 +1,3 @@ -import { Asset } from 'parcel' import { transformAsync, createConfigItem } from '@babel/core' import svgo from '@svgr/plugin-svgo' import jsx from '@svgr/plugin-jsx' @@ -7,6 +6,18 @@ import presetReact from '@babel/preset-react' import presetEnv from '@babel/preset-env' import pluginTransformReactConstantElements from '@babel/plugin-transform-react-constant-elements' +/* eslint-disable global-require, import/no-unresolved */ +function requireParcel() { + try { + return require('parcel') + } catch (error) { + return require('parcel-bundler') + } +} +/* eslint-enable global-require, import/no-unresolved */ + +const { Asset } = requireParcel() + const babelOptions = { babelrc: false, configFile: false,