Comments (11)
it's a convenience thing. It allows you to write a require
statement for a directory instead of specific file.
without package.json
:
import Layout from 'src/components/Layout/Layout.js'
// var Layout = require('src/components/Layout/Layout.js');
with package.json
containing main
keyword:
import Layout from 'src/components/Layout'
// var Layout = require('src/components/Layout');
Alternatively, one could rename Layout.js
to index.js
. Then require-statement resolution would work without package.json
as well.
from react-firebase-starter.
One of the use cases where package.json
can be very helpful, is when you need to create an isomorphic component, having different implementations for Node.js and Browser environments:
{
"name": "MyComponent",
"version": "0.0.0",
"private": true,
"main": "./MyComponent.browser.js",
"node": "./MyComponent.node.js"
}
from react-firebase-starter.
When I put package.json
inside component's folder, I got Support for the experimental syntax 'jsx' isn't currently enabled
error, without package.json
everything works perfectly, anyone knows how I can fix this?
btw I don't use any of kriasoft's kits.
from react-firebase-starter.
Interesting. Thank you
from react-firebase-starter.
Its conflict with https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it (import/no-extraneous-dependencies)
from react-firebase-starter.
@alexesDev thanks for heads up! Fixed.
from react-firebase-starter.
@jayzelenkov I'm going to use package.json for every component in my app (so far I've been using index.js but I find package.json more natural for it) and I encounter this post. Now I'm wondering why you defined in the package.json also 3 other properties besides "main". Are you using:
"name": "Layout",
"version": "0.0.0",
"private": true,
these for anything?
from react-firebase-starter.
@krzywiecki just to make it a valid package.json
file, otherise the editor would highlight it. But, it seems like using index.js
re-exporting public APIs of the component is a more widely adopted approach:
// components/Toolbar/Toolbar.js
export function Toolbar(props) { ... }
// components/Toolbar/index.js
export { Toolbar as default } from './Toolbar';
from react-firebase-starter.
@koistya thanks for the answer. Actually my editor is not complaining so I'll stick with "main" property only up until I find a use case for some other prop.
Yeah, it's true that index.js is commonly used for exporting public API of a component but I think it's better to use package.json for it as:
- having javascript file tend to tempt to put more things there
- way of exporting can be different (some people do
export Toolbar from './Toolbar';
someexport default from './Toolbar'
)
I want to have consistency and also force to export only one thing from a module, that's why I decide to go with package.json
instead of index.js
from react-firebase-starter.
Yeah, that's a perfect example and I believe there might be more use cases.
from react-firebase-starter.
@koistya
Hi guys, sorry for off-topic.
How I can build my project in such a way? Package.json per component in the dist folder
https://ibb.co/mR51tM9
from react-firebase-starter.
Related Issues (20)
- An in-range update of @firebase/auth is breaking the build 🚨 HOT 2
- An in-range update of dotenv is breaking the build 🚨 HOT 1
- An in-range update of moment-timezone is breaking the build 🚨 HOT 1
- An in-range update of react is breaking the build 🚨 HOT 1
- An in-range update of eslint-config-prettier is breaking the build 🚨 HOT 1
- An in-range update of firebase-admin is breaking the build 🚨 HOT 1
- Migrate from JSS styles to Emotion
- Admin Access HOT 2
- error [email protected]: The engine "node" is incompatible with this module. Expected version "10". Got "12.13.0" HOT 2
- Subscriptions example
- Can't get CustomerChat working
- Cannot read property 'tap' of undefined with Typescript added
- [Feature Request] Scalars
- How to run react-firebase-starter in different GCP region
- [Question] What's the usual cost for maintaining this setup on gcloud+firebase? HOT 1
- How to pagination users or stories? HOT 1
- If I need a pure front-end frame, how can I refit it(react-firebase-starter) ?
- Issues with postgres connectivity running in dev mode HOT 1
- http://localhost:3000/login?error=connect%20ECONNREFUSED%20127.0.0.1%3A5432 HOT 1
- Is this repo still maintained ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-firebase-starter.