-
-
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.
- Loading branch information
Showing
14 changed files
with
109 additions
and
226 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', | ||
} |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@svgr/parcel", | ||
"name": "@svgr/parcel-plugin-svgr", | ||
"description": "SVGR Parcel plugin.", | ||
"version": "4.0.0", | ||
"version": "4.0.4", | ||
"main": "lib/index.js", | ||
"repository": "[email protected]:smooth-code/svgr.git", | ||
"author": "Mario Pabon <[email protected]>", | ||
|
@@ -28,11 +28,13 @@ | |
"parcel-bundler": "^1.10.0" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.1.2", | ||
"@babel/core": "^7.1.6", | ||
"@babel/plugin-transform-react-constant-elements": "^7.0.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/preset-env": "^7.1.6", | ||
"@babel/preset-react": "^7.0.0", | ||
"@svgr/core": "^4.0.2" | ||
"@svgr/core": "^4.0.3", | ||
"@svgr/plugin-jsx": "^4.0.3", | ||
"@svgr/plugin-svgo": "^4.0.3" | ||
}, | ||
"devDependencies": { | ||
"parcel-bundler": "^1.10.3" | ||
|
File renamed without changes
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
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 |
2 changes: 1 addition & 1 deletion
2
packages/parcel/src/index.js → packages/parcel-plugin-svgr/src/index.js
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 |
---|---|---|
@@ -1,6 +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) { | ||
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.