Git Product home page Git Product logo

react-npm-boilerplate's Introduction

Boilerplate for creating React Npm packages with ES2015

The package is based on npm-base package by Kadira which is really great when you want to prepare Npm package. This one is prepared to be used as a starter point for React components which needs to be published on Npm.

It includes linting with ESLint and testing with Mocha, Enzyme and JSDOM.

Also there is of course ES6 transpilation.

Usage

  1. Clone this repo
  2. Inside cloned repo run npm install && rm -rf .git && git init and update package.json with your package name.
  3. If you want to run tests: npm test or npm run testonly or npm run test-watch. You need to write tests in __tests__ folder. You need at least Node 4 on your machine to run tests.
  4. If you want to run linting: npm test or npm run lint. Fix bugs: npm run lint-fix. You can adjust your .eslintrc config file.
  5. If you want to run transpilation to ES5 in dist folder: npm run prepublish (standard npm hook).

CSS and preprocessors

For more information check out this thread: #5

Blog post about it:

Also check out

License

MIT

react-npm-boilerplate's People

Contributors

aymericbouzy avatar juliancwirko 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-npm-boilerplate's Issues

Include .css to build

Hi. I have a React component that import a .css and I would want to know how to include that file into my dist folder, because the file is not event moved.

Also I want to know how to already import the css into my js file to avoid the error dist/styles.css Unexpected token when my module is requested.

Thank you for your help.

How to use the content of the package in my own package?

Sorry I'm a real beginner ...
I forked the package, then copied the content of the forked package to my own package (using $ cp -a react-npm-boilerplate/. react-my-custom-package/), but I guess it's not the right way to go : I cannot commit the new files.

I'm sure I will find how to do this on the internet, but I would have liked it to be part of the Readme. I will update this issue with my findings, and I will try doing a PR on the Readme for the other beginners.

Why use prepublish as an external script?

The script is only one line, so I don't really need to have one extra file just for that.
You could use directly on your package.json IMO:

{
   "prepublish": "babel --plugins 'transform-runtime' src --ignore __tests__ --out-dir ./dist"
}

npm install fails on Windows 10

npm WARN deprecated [email protected]: to-iso-string has been deprecated, use @segment/to-iso-string instead.
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

[email protected] prepublish C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid
babel --plugins 'transform-es2015-modules-umd' src --ignore tests --out-dir ./dist

ReferenceError: Unknown plugin "'transform-es2015-modules-umd'" specified in "base" at 0, attempted to resolve relative to "src"
at C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-core\lib\transformation\file\options\option-manager.js:176:17
at Array.map (native)
at Function.normalisePlugins (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-core\lib\transformation\file\options\option-manager.js:154:20)
at OptionManager.mergeOptions (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-core\lib\transformation\file\options\option-manager.js:229:36)
at OptionManager.init (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-core\lib\transformation\file\options\option-manager.js:374:12)
at File.initOptions (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-core\lib\transformation\file\index.js:216:65)
at new File (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-core\lib\transformation\file\index.js:139:24)
at Pipeline.transform (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
at transform (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-cli\lib\babel\util.js:50:22)
at Object.compile (C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\node_modules\babel-cli\lib\babel\util.js:59:12)

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\Moto\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! node v6.9.1
npm ERR! npm v3.8.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] prepublish: babel --plugins 'transform-es2015-modules-umd' src --ignore __tests__ --out-dir ./dist
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prepublish script 'babel --plugins 'transform-es2015-modules-umd' src --ignore tests --out-dir ./dist'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the react-npm-boilerplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! babel --plugins 'transform-es2015-modules-umd' src --ignore tests --out-dir ./dist
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs react-npm-boilerplate
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls react-npm-boilerplate
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Moto\Documents\Projects\Mark\material-ui-layout\material-layout\material-grid\npm-debug.log

Consider using rollup to compile the dist files

If you don't know about rollup, I highly recommend having a look into it.
It can output a much smaller distribution file than using babel directly.

I've released a simple react library and I did a lot of tests before deciding to stick with Rollup - it's a big difference, you should give it a try too. The config would be something like this:

import babel from 'rollup-plugin-babel';
import replace from 'rollup-plugin-replace';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';

export default {
  moduleName: 'NameOfYourModuleForAMD',
  entry: './src/index.js',
  dest: './dist/index.js',
  format: 'umd',
  plugins: [babel(), commonjs()],
  globals: {
    react: 'React' // because you don't want to include React on the bundled js
  }
};

Plus you have the benefit of having a UMD package.

And just one smaller thing, I would add "react" as a peerDependency so people can choose the React version they want to use.

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.