React-starter-kit: component package.json

Created on 2 Mar 2015  路  6Comments  路  Source: kriasoft/react-starter-kit

@koistya what is the purpose of these package.json files?
should we actually define component level dependencies in there?

question

Most helpful comment

Without it you would need to reference .js files directly:

import MyComponent from '../MyComponent/MyComponent.js';

vs.

import MyComponent from '../MyComponent';

There are some other use cases, for example you can describe your CSS inside package.json and use that info to create localized CSS bundles, stuff like that.

All 6 comments

You can read the CommonJS spec (http://wiki.commonjs.org/wiki/Packages/1.1#Minimal_Example_Package_Descriptor_File)

@wizraopeize no kidding. I know what the files are. but how are they useful?
a minimal descriptor doesn't do much for the components. correct me if I'm wrong.

A CommonJS package is a cohesive wrapping of a collection of modules, code and other assets into a single form, A CommonJS package can independently use in other project. so It needs a descriptor file to provide the name, the version and so on.

You are going through definitions. Reuse is not enabled by having a package.json file and you do not need to define each React component as a package. If you really want to do it right, you would have to have a separate repo to house these components. That way other project can require it as an external dependency.

For internal dependencies, ex. the HomePage component, there is no need. and doesn't make sense to me.

Without it you would need to reference .js files directly:

import MyComponent from '../MyComponent/MyComponent.js';

vs.

import MyComponent from '../MyComponent';

There are some other use cases, for example you can describe your CSS inside package.json and use that info to create localized CSS bundles, stuff like that.

@koistya that's awesome! wasn't aware of that.

Was this page helpful?
0 / 5 - 0 ratings