Skip to content

Instantly share code, notes, and snippets.

@aliustaoglu
Created November 12, 2017 08:13
Show Gist options
  • Save aliustaoglu/9a6ed6005796dc9b602308e22e1de4e8 to your computer and use it in GitHub Desktop.
Save aliustaoglu/9a6ed6005796dc9b602308e22e1de4e8 to your computer and use it in GitHub Desktop.
Create NPM module
{
"presets": ["env"],
"plugins": [
"transform-object-rest-spread",
"transform-react-jsx"
]
}
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class MyReactModule extends Component {
componentDidMount() {
}
render() {
return (
<div>
MY REACT COMPONENT
</div>
);
}
}
MyReactModule.defaultProps = {
}
MyReactModule.PropTypes = {
}
export default MyReactModule;
{
"name": "my-npm-module",
"version": "0.0.1",
"description": "Simple React component",
"main": "build/index.js",
"dependencies": {
},
"devDependencies": {
"prop-types": "^15.6.0",
"react": "^15.5.4",
"webpack": "^2.6.1",
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.5.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack --watch",
"build": "webpack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aliustaoglu/create-npm-module.git"
},
"keywords": [
"react"
],
"author": "Cuneyt Aliustaoglu",
"license": "ISC",
"bugs": {
"url": "https://github.com/aliustaoglu/create-npm-module/issues"
},
"homepage": "https://github.com/aliustaoglu/create-npm-module#readme"
}
var path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'index.js',
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
exclude: /(node_modules|bower_components|build)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
}
]
},
externals: {
'react': 'commonjs react'
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment