Git Product home page Git Product logo

babel-plugin-react-generate-property's People

Contributors

rogeriocsilva avatar shawnxusy avatar yhnavein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

babel-plugin-react-generate-property's Issues

How to use in webpack config?

Trying to use in webpack but not seeing any effect - does this look corrrect?

"use strict";

/* eslint-disable no-unused-vars */
module.exports = (config, webpack) => {

	config.module.rules.push({
		test: /\.(?:js|jsx|tsx|cjs)$/,
		include: [
			/node_modules\/@strapi\/admin\/admin\/src\/components/,
			/node_modules\/@strapi\/admin\/admin\/src\/content-manager\/components/,
			/node_modules\/@strapi\/design-system\/dist/
		],
		use: {
			loader: require.resolve("babel-loader"),
			options: {
				cacheDirectory: false,
				cacheCompression: false,
				compact: false,
				presets: [
					require.resolve("@babel/preset-env"),
					require.resolve("@babel/preset-react")
				],
				plugins: [
					[
						"babel-plugin-react-generate-property",
						{
							"customProperty": "data-dev",
							"dirLevel": 4,
							"slashChar": "\\",
							"addModuleClassNames": true,
							"prefix": "myPrefix",
							"firstChildOnly": false
						}
					]
				]
			}
		}
	});

	return config;
};

Option for specifying separator character

Great plugin, thanks!

A nice improvement would be an option for specifying the separator character 🙏. I think it might be common for others to not want to use the hardcoded _.

Adding index for identical path (relevant for reusable components and styled-components)

Hey @shawnxusy i tried to utilise this project and encountered some issue we are using design system pattern and we reuse our react components that written with styled-components which means that we have one Button component in our bank with different properties so the problem is when we have couple of Buttons on same view the they have same generated attribute so it is hard for automation tests to select button that we need.
To illustrate the issue
we have Button component that comes from some library and we have couple different variant of buttons on same page
so we will the plugin will add same attribute based on the absolute path of this button so all the buttons will have something like data-id="src/componentsLibrary/differentComponents/button" even through inside the view all the buttons will have different callbacks and strings the will have same data-id so in addition to the issue i will open pull-request with fix for this along with some other minor changes

added property overwrites existing property in code

Hi, thanks for the plugin.
I checked the source code and I think it is useful that the plugin checks if a JSX property exists. If so, plugin doesn't add the property with generated value. That however doesn't work with spreaded props.

<div {...props} />

becomes

<div {...props}  xyzProp="XYZ"/>

and that effectively overwrites xyzProp contained in props

My current patched solution is to change .push to .unshift in https://github.com/shawnxusy/babel-plugin-react-generate-property/blob/master/src/index.js#L123
Hence the example above becomes

<div xyzProp="XYZ" {...props}  />

I'm fine with creating a PR. Let me know if you want me to create one with some specifics like if there should be a new option etc.

Add root filter path option

Hey @shawnxusy thanks for this useful library!

Our library has various depths of paths, for example you have:
src/App.tsx
or
src/libs/mylib/components/component1/Component1.tsx

Problem with the dirLevel path is that it strips the directory, so you get:
src_app for src/App.tsx
and
component1_component1 for src/libs/mylib/components/component1/Component1.tsx

When you nest components deeper in your file hierarchy you start missing some information.

Would it be an idea to add an option something like stripDirs which takes off the first x amount of directories?

Update npm version 1.0.5 -> 1.1.0

Hi.
Thanks for what you doing.
Please, update npm version to the latest.
I wish to use new configs like ‘addModuleClassnames’ and ‘ignoreNodeNames’

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.