-
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
1,925 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
watchPathIgnorePatterns: ['__fixtures__', '__fixtures__build__'], | ||
rootDir: 'packages', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/ | ||
.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# @svgr/parcel-plugin-svgr | ||
|
||
Parcel plugin for SVGR. | ||
|
||
``` | ||
npm install @svgr/parcel-plugin-svgr | ||
``` | ||
|
||
## Usage | ||
|
||
In your code: | ||
|
||
```js | ||
import Star from './star.svg' | ||
|
||
const App = () => ( | ||
<div> | ||
<Star /> | ||
</div> | ||
) | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@svgr/parcel-plugin-svgr", | ||
"description": "SVGR Parcel plugin.", | ||
"version": "4.0.4", | ||
"main": "lib/index.js", | ||
"repository": "[email protected]:smooth-code/svgr.git", | ||
"author": "Mario Pabon <[email protected]>", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [ | ||
"svgr", | ||
"svg", | ||
"react", | ||
"parcel", | ||
"parcel-plugin" | ||
], | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"prebuild": "rm -rf lib/", | ||
"build": "babel --config-file ../../babel.config.js -d lib --ignore \"**/*.test.js\" src", | ||
"prepublishOnly": "yarn run build" | ||
}, | ||
"peerDependencies": { | ||
"parcel-bundler": "^1.10.0" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.1.6", | ||
"@babel/plugin-transform-react-constant-elements": "^7.0.0", | ||
"@babel/preset-env": "^7.1.6", | ||
"@babel/preset-react": "^7.0.0", | ||
"@svgr/core": "^4.0.3", | ||
"@svgr/plugin-jsx": "^4.0.3", | ||
"@svgr/plugin-svgo": "^4.0.3" | ||
}, | ||
"devDependencies": { | ||
"parcel-bundler": "^1.10.3" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions
59
packages/parcel-plugin-svgr/src/__snapshots__/index.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`parcel plugin should convert file 1`] = ` | ||
Array [ | ||
Object { | ||
"js": "\\"use strict\\"; | ||
Object.defineProperty(exports, \\"__esModule\\", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _react = _interopRequireDefault(require(\\"react\\")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var _ref = | ||
/*#__PURE__*/ | ||
_react.default.createElement(\\"g\\", { | ||
stroke: \\"#063855\\", | ||
strokeWidth: 2, | ||
fill: \\"none\\", | ||
fillRule: \\"evenodd\\", | ||
strokeLinecap: \\"square\\" | ||
}, _react.default.createElement(\\"path\\", { | ||
d: \\"M51 37L37 51M51 51L37 37\\" | ||
})); | ||
var SvgIcon = function SvgIcon(props) { | ||
return _react.default.createElement(\\"svg\\", _extends({ | ||
width: 88, | ||
height: 88 | ||
}, props), _ref); | ||
}; | ||
var _default = SvgIcon; | ||
exports.default = _default;", | ||
"map": undefined, | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Asset } from 'parcel-bundler' | ||
import { transformAsync, createConfigItem } from '@babel/core' | ||
import svgo from '@svgr/plugin-svgo' | ||
import jsx from '@svgr/plugin-jsx' | ||
import convert from '@svgr/core' | ||
import presetReact from '@babel/preset-react' | ||
import presetEnv from '@babel/preset-env' | ||
import pluginTransformReactConstantElements from '@babel/plugin-transform-react-constant-elements' | ||
|
||
const babelOptions = { | ||
babelrc: false, | ||
configFile: false, | ||
presets: [ | ||
createConfigItem(presetReact, { type: 'preset' }), | ||
createConfigItem([presetEnv, { modules: false }], { type: 'preset' }), | ||
], | ||
plugins: [createConfigItem(pluginTransformReactConstantElements)], | ||
} | ||
|
||
class ReactSVGAsset extends Asset { | ||
type = 'js' | ||
|
||
async parse(contents) { | ||
const code = await convert( | ||
contents, | ||
{}, | ||
{ | ||
caller: { | ||
name: '@svgr/parcel', | ||
defaultPlugins: [svgo, jsx], | ||
}, | ||
filePath: this.name, | ||
}, | ||
) | ||
|
||
const { code: babelCode } = await transformAsync(code, babelOptions) | ||
|
||
return babelCode | ||
} | ||
|
||
async generate() { | ||
return [{ type: 'js', value: this.ast }] | ||
} | ||
} | ||
|
||
module.exports = ReactSVGAsset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Parcel requires that plugins be exported with `module.exports`. | ||
// It won't be able to load the plugin if it is exported with "export default plugin" and then transpiled. | ||
module.exports = function svgrParcelPlugin(bundler) { | ||
// Parcel requires that the asset be passed in as a module path. | ||
bundler.addAssetType('svg', require.resolve('./asset')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Bundler from 'parcel-bundler' | ||
import path from 'path' | ||
import plugin from '.' | ||
|
||
const getCode = bundle => | ||
Array.from(bundle.assets) | ||
.filter(asset => asset.id === 'icon.svg') | ||
.map(asset => asset.generated) | ||
|
||
describe('parcel plugin', () => { | ||
it('should convert file', async () => { | ||
const bundler = new Bundler(path.join(__dirname, '__fixtures__/icon.svg'), { | ||
outDir: path.join(__dirname, '../../../__fixtures_build__/parcel'), | ||
cache: false, | ||
detailedReport: false, | ||
hmr: false, | ||
logLevel: 0, | ||
target: 'node', | ||
watch: false, | ||
}) | ||
|
||
plugin(bundler) | ||
|
||
const bundle = await bundler.bundle() | ||
const code = getCode(bundle) | ||
expect(code).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
144dbe3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://svgr-eymazptvzc.now.sh to the following alias.