-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: component generator & universal build #967
Changes from all commits
8c240f2
a29e3f6
38f8925
df49ed1
4e9d1ff
74c85b8
c9bec8f
547a761
de24026
627366b
46a8898
e9ed288
30fba1f
8ad2746
4a1ab60
d3810b3
4fc593f
004f6c1
4d540c5
95ac795
0987d85
8bbe418
4ada36c
81401cb
edd9128
2400fa9
bbd3c1b
0d0f4e7
852f505
a8d339b
e40604e
ef3978e
c92f95d
fa275a0
8bc431b
91d448c
cf27b33
4c9bda7
269b8a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## <%= answers.name%> | ||
<%= answers.description %> | ||
|
||
## Install | ||
|
||
``` | ||
$ npm install <%= answers.name%> --save | ||
``` | ||
|
||
## Import | ||
|
||
``` | ||
import MyComponent from '<%= answers.name%>'; | ||
``` | ||
|
||
## API说明 | ||
|
||
### Props | ||
|
||
|name|type|default|describe| | ||
|:---------------|:--------|:----|:----------| | ||
|name|String|''|describe| | ||
|
||
### Function | ||
|
||
|name|param|return|describe| | ||
|:---------------|:--------|:----|:----------| | ||
|name|Object|/|describe| | ||
|
||
## Example | ||
|
||
``` | ||
import {createElement, Component, render} from 'rax'; | ||
import View from 'rax-view'; | ||
|
||
class App extends Component { | ||
render() { | ||
return ( | ||
<View> | ||
{ /* your code */ } | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
render(<App />); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
lib | ||
dist | ||
build | ||
coverage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.swp | ||
*.log | ||
|
||
.DS_Store | ||
.idea/ | ||
package-lock.json | ||
coverage/ | ||
node_modules/ | ||
build/ | ||
dist/ | ||
lib/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
sudo: required | ||
|
||
language: node_js | ||
|
||
before_install: | ||
- npm i -g npm@6 | ||
|
||
node_js: | ||
- "8" | ||
- "11" | ||
|
||
script: | ||
- npm run lint | ||
- npm run test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {createElement, render} from 'rax'; | ||
import * as DriverDOM from 'driver-dom'; | ||
import App from '../src/index'; | ||
|
||
render(<App />, document.body, { driver: DriverDOM }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "__YourProjectName__", | ||
"version": "0.0.1", | ||
"description": "", | ||
"author": "__AuthorName__", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"start": "rax-scripts start --type 'component' -p 8000", | ||
"build": "rax-scripts build --type 'component'", | ||
"test": "rax-scripts test --type 'component'", | ||
"lint": "rax-scripts lint --type 'component'" | ||
}, | ||
"keywords": [ | ||
"Rax", | ||
"rax-component" | ||
], | ||
"engines": { | ||
"npm": ">=3.0.0" | ||
}, | ||
"dependencies": { | ||
}, | ||
"peerDependencies": { | ||
"rax": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"rax": "^1.0.0", | ||
"rax-scripts": "^1.2.0", | ||
"driver-dom": "^1.0.0", | ||
"rax-test-renderer": "^1.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1, user-scalable=no"> | ||
<title>Rax Component Demo</title> | ||
<script> | ||
(function(global){if(global.define){return}var modules={};var inGuard=false;function def(id,deps,factory){if(deps instanceof Function){factory=deps;deps=[]}modules[id]={factory:factory,deps:deps,module:{exports:{}},isInitialized:false,hasError:false,}}function req(id){if(id.indexOf("@weex-module")===0){return{}}var originId=id;var mod=modules[id];if(!mod){id=id+"/index";mod=modules[id]}if(mod&&mod.isInitialized){return mod.module.exports}return requireImpl(id,originId)}function requireImpl(id,originId){if(global.ErrorUtils&&!inGuard){inGuard=true;var returnValue;try{returnValue=requireImpl.apply(this,arguments)}catch(e){global.ErrorUtils.reportFatalError(e)}inGuard=false;return returnValue}var mod=modules[id];if(!mod){throw new Error('Requiring unknown module "'+originId+'"')}if(mod.hasError){throw new Error('Requiring module "'+originId+'" which threw an exception')}try{mod.isInitialized=true;mod.factory(req,mod.module.exports,mod.module)}catch(e){mod.hasError=true;mod.isInitialized=false;throw e}return mod.module.exports}global.define=def;global.require=req})(this||typeof global==="object"&&global||typeof window==="object"&&window); | ||
</script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-env jest */ | ||
import { createElement } from 'rax'; | ||
import renderer from 'rax-test-renderer'; | ||
import MyComponent from '../'; | ||
|
||
describe('MyComponent', () => { | ||
it('typeof MyComponent is "function"', () => { | ||
expect(typeof MyComponent).toEqual('function'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createElement } from 'rax'; | ||
|
||
const styles = { | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}, | ||
containerBody: { | ||
fontSize: 40, | ||
color: '#999' | ||
} | ||
}; | ||
|
||
export default (props) => { | ||
return ( | ||
<div style={styles.container}> | ||
<div style={styles.containerBody}>hello world</div> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lint 功能暂时都不在 scripts 里 |
||
'use strict'; | ||
const program = require('commander'); | ||
const optionsAttachToEnv = require('../src/config/optionsAttachToEnv'); | ||
|
||
program | ||
.action((cmd) => { | ||
optionsAttachToEnv(cmd); | ||
require('../src/lint')(); | ||
}); | ||
|
||
program.parse(process.argv); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
const program = require('commander'); | ||
const optionsAttachToEnv = require('../src/utils/optionsAttachToEnv'); | ||
|
||
program | ||
.action((cmd) => { | ||
optionsAttachToEnv(cmd); | ||
require('../src/jest')(); | ||
}); | ||
|
||
program.parse(process.argv); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,15 @@ | |
"@babel/preset-flow": "7.0.0", | ||
"@babel/preset-react": "7.0.0", | ||
"@babel/runtime": "^7.2.0", | ||
"eslint": "^5.10.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-react": "~7.11.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这些包不应该加到scripts里的依赖,这些是项目生成后里的依赖 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这部分之前考虑是 rax-scripts 也承担 lint 的工作,目前不考虑 lint 我先去掉 |
||
"babel-preset-rax": "^1.0.0-beta.0", | ||
"babel-jest": "^23.6.0", | ||
"babel-eslint": "10.0.1", | ||
"jest": "^23.6.0", | ||
"jest-cli": "^24.7.1", | ||
"jest-localstorage-mock": "^2.3.0", | ||
"address": "^1.0.1", | ||
"autoprefixer": "^9.4.3", | ||
"babel-core": "^7.0.0-bridge.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict'; | ||
/* eslint no-console: 0 */ | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const RaxWebpackPlugin = require('rax-webpack-plugin'); | ||
const webpackConfig = require('../webpack.config'); | ||
const pathConfig = require('../path.config'); | ||
const babelConfig = require('../babel.config'); | ||
|
||
babelConfig.presets.push([ | ||
require.resolve('@babel/preset-react'), { | ||
'pragma': 'createElement', | ||
'pragmaFrag': 'Fragment' | ||
} | ||
]); | ||
|
||
babelConfig.plugins.push( | ||
require.resolve('babel-plugin-transform-jsx-stylesheet'), | ||
require.resolve('rax-hot-loader/babel') | ||
); | ||
|
||
module.exports = { | ||
mode: webpackConfig.mode, | ||
context: webpackConfig.context, | ||
// Compile target should "web" when use hot reload | ||
target: webpackConfig.target, | ||
entry: webpackConfig.entry, | ||
output: Object.assign({ | ||
pathinfo: true, | ||
}, webpackConfig.output), | ||
|
||
resolve: webpackConfig.resolve, | ||
|
||
plugins: [ | ||
new RaxWebpackPlugin({ | ||
target: 'bundle', | ||
externalBuiltinModules: false, | ||
}), | ||
// Generates an `index.html` file with the <script> injected. | ||
new HtmlWebpackPlugin({ | ||
inject: true, | ||
template: pathConfig.appHtml, | ||
}), | ||
webpackConfig.plugins.define, | ||
webpackConfig.plugins.caseSensitivePaths, | ||
], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.tsx?$/, | ||
exclude: /(node_modules|bower_components)/, | ||
use: [ | ||
{ | ||
loader: require.resolve('ts-loader'), | ||
}, | ||
], | ||
}, | ||
{ | ||
test: /\.(js|mjs|jsx)$/, | ||
exclude: /(node_modules|bower_components)/, | ||
use: [ | ||
{ | ||
loader: require.resolve('babel-loader'), | ||
options: babelConfig, | ||
}, | ||
], | ||
}, | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
{ | ||
loader: require.resolve('stylesheet-loader'), | ||
}, | ||
], | ||
}, | ||
// load inline images using image-source-loader for Image | ||
{ | ||
test: /\.(svg|png|webp|jpe?g|gif)$/i, | ||
use: [ | ||
{ | ||
loader: require.resolve('image-source-loader'), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
/* eslint no-console: 0 */ | ||
const webpack = require('webpack'); | ||
const webpackMerge = require('webpack-merge'); | ||
const pathConfig = require('../path.config'); | ||
const webpackConfigBase = require('./webpack.config.base'); | ||
|
||
// enable source map | ||
const webpackConfigDev = webpackMerge(webpackConfigBase, { | ||
devtool: 'inline-module-source-map', | ||
entry: { | ||
index: [pathConfig.componentDemoJs], | ||
}, | ||
output: { | ||
publicPath: '/', | ||
}, | ||
plugins: [ | ||
new webpack.NoEmitOnErrorsPlugin(), | ||
], | ||
}); | ||
|
||
Object.keys(webpackConfigDev.entry).forEach((point) => { | ||
// hot reaload client. | ||
webpackConfigDev.entry[point].unshift(require.resolve('../../hmr/webpackHotDevClient.entry')); | ||
}); | ||
|
||
module.exports = webpackConfigDev; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把.idea丢到ignore里其实不是一种好的做法, ide的配置可能包含一些编码习惯, 同一个项目的编码习惯在团队中互相共享有助于保持项目代码的一致性, 不过我们现在好像都是这么做的, 只是提出一下, 可以先不改