Browse Source

feat: publish npm package

yhhu 5 years ago
parent
commit
93c727dd87
13 changed files with 167 additions and 27 deletions
  1. 1 1
      .gitignore
  2. 4 0
      README.md
  3. 0 16
      dist/index.html
  4. 38 0
      example/app.js
  5. 0 0
      lib/images/icon-calendar.svg
  6. 0 0
      lib/images/icon-close.svg
  7. 25 0
      lib/index.js
  8. 15 7
      package.json
  9. 2 1
      src/app.js
  10. 13 1
      webpack.config.js
  11. 50 0
      webpack/webpack.config.npm.js
  12. 4 1
      webpack/webpack.config.prod.js
  13. 15 0
      yarn.lock

+ 1 - 1
.gitignore

@@ -62,4 +62,4 @@ output
 *.dSYM
 
 ## release
-dist/
+dist/

+ 4 - 0
README.md

@@ -32,6 +32,7 @@ $ git checkout v1.0.0
 
 ```javascript
 // datepicker
+import DatePicker from 'rt-datepicker'
 
 <DatePicker onSelectDate={day => console.log(day)} />
 
@@ -74,6 +75,9 @@ const disabledDate = current => (
 />
 
 // monthpicker
+import DatePicker from 'rt-datepicker'
+const { MonthPicker } = DatePicker
+
 <MonthPicker
   disable
   inline

+ 0 - 16
dist/index.html

@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-	<meta charset="UTF-8">
-	<title>Datepicker</title>
-	
-		<link href="main.4622b6314fea50e76437.css" rel="stylesheet">
-	
-</head>
-<body>
-	<div id="container" class="container"></div>
-	
-		<script src="main-bundle-4622b631.js"></script>
-	
-</body>
-</html>

+ 38 - 0
example/app.js

@@ -0,0 +1,38 @@
+
+import React from 'react'
+import ReactDOM from 'react-dom'
+// import DatePicker from './index'
+import DatePicker from '../lib'
+import '../src/styles/index.css'
+
+const { MonthPicker } = DatePicker
+
+// const disabledDate = current => (
+// start & end
+// ['2018-01-02', current]
+
+// end
+// [current]
+// )
+
+const App = () => (
+  <React.Fragment>
+    <p>日历模式</p>
+    <DatePicker
+      inline
+      // disabledDate={current => disabledDate(current)}
+      defaultDate="2018-01-31"
+      placeholder="please choose date"
+      onSelectDate={day => console.log(day)}
+    />
+    <p>月份选择模式</p>
+    <MonthPicker
+      inline
+      placeholder="Select month"
+      year="2018"
+      month="01"
+      onSelectMonth={month => console.log(month)}
+    />
+  </React.Fragment>
+)
+ReactDOM.render(<App />, document.getElementById('container'))

dist/images/icon-calendar-2_np6.svg → lib/images/icon-calendar.svg


dist/images/icon-close-3ouHO.svg → lib/images/icon-close.svg


File diff suppressed because it is too large
+ 25 - 0
lib/index.js


+ 15 - 7
package.json

@@ -1,21 +1,28 @@
 {
-  "name": "datepicker",
-  "version": "2.0.0",
-  "description": "datepicker",
-  "main": "src/index.js",
+  "name": "rt-datepicker",
+  "version": "2.0.3",
+  "description": "simple datepicker",
+  "keywords": [
+    "datepicker",
+    "monthpicker",
+    "ryn"
+  ],
+  "main": "lib/index.js",
   "scripts": {
     "start:dev": "NODE_ENV=dev webpack-dev-server",
     "build": "rm -rf ./dist && npx webpack",
-    "lint": "eslint --ext .js src"
+    "lint": "eslint --ext .js src",
+    "npm": "NODE_ENV=npm npx webpack && npm publish ."
   },
   "repository": "https://github.com/Rynxiao/datepicker.git",
   "author": "ryn",
-  "license": "ISC",
+  "license": "MIT",
   "dependencies": {
     "classnames": "^2.2.6",
     "prop-types": "^15.6.2",
     "react": "^16.5.2",
-    "react-dom": "^16.5.2"
+    "react-dom": "^16.5.2",
+    "rt-datepicker": "^2.0.3"
   },
   "devDependencies": {
     "autoprefixer": "^9.1.5",
@@ -25,6 +32,7 @@
     "babel-preset-env": "^1.7.0",
     "babel-preset-react": "^6.24.1",
     "babel-preset-stage-0": "^6.24.1",
+    "clean-webpack-plugin": "^0.1.19",
     "css-loader": "^1.0.0",
     "cssnano": "^4.1.4",
     "eslint": "^5.6.0",

+ 2 - 1
src/app.js

@@ -1,7 +1,8 @@
 
 import React from 'react'
 import ReactDOM from 'react-dom'
-import DatePicker from './index'
+// import DatePicker from './index'
+import DatePicker from 'rt-datepicker'
 import './styles/index.css'
 
 const { MonthPicker } = DatePicker

+ 13 - 1
webpack.config.js

@@ -1,4 +1,16 @@
 const devConfig = require('./webpack/webpack.config.dev')
 const prodConfig = require('./webpack/webpack.config.prod')
+const npmConfig = require('./webpack/webpack.config.npm')
 
-module.exports = process.env.NODE_ENV === 'dev' ? devConfig : prodConfig
+const env = process.env.NODE_ENV
+let config = devConfig
+
+if (env === 'dev') {
+  config = prodConfig
+}
+
+if (env === 'npm') {
+  config = npmConfig
+}
+
+module.exports = config

+ 50 - 0
webpack/webpack.config.npm.js

@@ -0,0 +1,50 @@
+const path = require('path')
+const CleanWebpackPlugin = require('clean-webpack-plugin')
+
+module.exports = {
+  mode: 'production',
+  entry: {
+    index: './src/index.js',
+  },
+  output: {
+    path: path.resolve(__dirname, '../lib'),
+    filename: '[name].js',
+    libraryTarget: 'commonjs2',
+  },
+  module: {
+    rules: [
+      {
+        test: /\.js$/,
+        loader: 'babel-loader',
+        exclude: /node_modules/,
+      },
+      {
+        test: /\.css$/,
+        use: [
+          'style-loader',
+          {
+            loader: 'css-loader',
+            options: {
+              modules: true,
+              camelCase: true,
+              localIdentName: '[name]__[local]--[hash:base64:5]',
+            },
+          },
+          'postcss-loader',
+        ],
+      },
+      {
+        test: /\.(jpe?g|png|svg|bmp)$/,
+        loader: 'file-loader',
+        options: {
+          outputPath: 'images/',
+          publicPath: '/lib/images/',
+          name: '[name].[ext]',
+        },
+      },
+    ],
+  },
+  plugins: [
+    new CleanWebpackPlugin(['lib']),
+  ],
+}

+ 4 - 1
webpack/webpack.config.prod.js

@@ -6,7 +6,10 @@ const projectPath = path.resolve(__dirname, '../')
 
 module.exports = {
   mode: 'production',
-  entry: './src/app.js',
+  entry: {
+    index: './src/app.js',
+    vendor: ['react', 'react-dom', 'prop-types', 'classnames'],
+  },
   output: {
     path: path.resolve(__dirname, '../dist'),
     filename: '[name]-bundle-[hash:8].js',

+ 15 - 0
yarn.lock

@@ -1564,6 +1564,12 @@ clean-css@4.2.x:
   dependencies:
     source-map "~0.6.0"
 
+clean-webpack-plugin@^0.1.19:
+  version "0.1.19"
+  resolved "https://registry.yarnpkg.com/clean-webpack-plugin/-/clean-webpack-plugin-0.1.19.tgz#ceda8bb96b00fe168e9b080272960d20fdcadd6d"
+  dependencies:
+    rimraf "^2.6.1"
+
 cli-cursor@^2.1.0:
   version "2.1.0"
   resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
@@ -5341,6 +5347,15 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
     hash-base "^3.0.0"
     inherits "^2.0.1"
 
+rt-datepicker@^2.0.3:
+  version "2.0.3"
+  resolved "https://registry.yarnpkg.com/rt-datepicker/-/rt-datepicker-2.0.3.tgz#76586f1ce8cacecf6bf41d79b858e6451c287f98"
+  dependencies:
+    classnames "^2.2.6"
+    prop-types "^15.6.2"
+    react "^16.5.2"
+    react-dom "^16.5.2"
+
 run-async@^2.2.0:
   version "2.3.0"
   resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"