Skip to content
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

Merged
merged 39 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8c240f2
feat: component generator & universal build
yacheng Mar 5, 2019
a29e3f6
fix: lint
yacheng Mar 5, 2019
38f8925
feat: component dev
yacheng Mar 6, 2019
df49ed1
feat: use English Doc
yacheng Mar 6, 2019
4e9d1ff
feat: rax-scripts lint
yacheng Mar 6, 2019
74c85b8
fix: component generator
yacheng Mar 6, 2019
c9bec8f
feat: use component babel.config
yacheng Mar 6, 2019
547a761
feat: add add-module-exports plugin
yacheng Mar 6, 2019
de24026
fix: webpack.config.base
yacheng Mar 6, 2019
627366b
feat: remove _eslintrc.js
yacheng Mar 6, 2019
46a8898
feat: lint
yacheng Mar 6, 2019
e9ed288
feat: use _npmignore & add 'rax-scripts lint'
yacheng Mar 6, 2019
30fba1f
fix: test
yacheng Mar 6, 2019
8ad2746
Merge branch 'master' into feat-universal-build
yacheng Mar 18, 2019
4a1ab60
feat: merge master
yacheng Mar 18, 2019
d3810b3
feat: merge master
yacheng Apr 16, 2019
4fc593f
fix: remove lint for rax-scripts
yacheng Apr 17, 2019
004f6c1
fix: package.json
yacheng Apr 17, 2019
4d540c5
fix: lint
yacheng Apr 17, 2019
95ac795
feat: rax-cli component generator update
yacheng Apr 17, 2019
0987d85
feat: add component readme
yacheng Apr 23, 2019
8bbe418
feat: use @babel/preset-react
yacheng Apr 23, 2019
4ada36c
feat: run demo
yacheng Apr 23, 2019
81401cb
feat: run demo
yacheng Apr 23, 2019
edd9128
feat: rename path name
yacheng Apr 23, 2019
2400fa9
feat: 更新组件模版
yacheng Apr 24, 2019
bbd3c1b
feat: readme update
yacheng Apr 24, 2019
0d0f4e7
feat: add Fragment
yacheng Apr 24, 2019
852f505
fix: readme error
yacheng Apr 24, 2019
a8d339b
feat: test 命令和 lint 命令收拢回 rax-scripts
yacheng Apr 24, 2019
e40604e
fix: name
yacheng Apr 24, 2019
ef3978e
feat: add scripts type
yacheng Apr 24, 2019
c92f95d
feat: remove babel-plugin-add-module-exports
yacheng Apr 24, 2019
fa275a0
feat: component 类型判断优化
yacheng Apr 24, 2019
8bc431b
feat: rename test.js
yacheng Apr 25, 2019
91d448c
docs: fix filename
yuanyan Apr 25, 2019
cf27b33
feat: 命名优化
yacheng Apr 25, 2019
4c9bda7
Merge branch 'feat-universal-build' of https://github.com/alibaba/rax…
yacheng Apr 25, 2019
269b8a7
chore: update script desc
yuanyan Apr 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/rax-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,21 @@ $ rax init <ProjectName> [--verbose]
└── page2.json
```

* Componen Project
```
.
├── package.json
├── .gitignore
├── .eslintignore
├── .travis.yml
├── public
│ └── index.html
├── demo
│ └── index.js
└── src
├── __tests__
│ └── index.js
├── index.d.ts
└── index.js
```

4 changes: 4 additions & 0 deletions packages/rax-cli/bin/rax.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ function askProjectInformaction(name, verbose) {
{
name: 'MiniApp',
value: 'miniapp'
},
{
name: 'Component',
value: 'component'
}
],
default: 'webapp'
Expand Down
47 changes: 47 additions & 0 deletions packages/rax-cli/src/generator/component/README.md
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 />);
```
5 changes: 5 additions & 0 deletions packages/rax-cli/src/generator/component/_eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
lib
dist
build
coverage
11 changes: 11 additions & 0 deletions packages/rax-cli/src/generator/component/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.swp
*.log

.DS_Store
.idea/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把.idea丢到ignore里其实不是一种好的做法, ide的配置可能包含一些编码习惯, 同一个项目的编码习惯在团队中互相共享有助于保持项目代码的一致性, 不过我们现在好像都是这么做的, 只是提出一下, 可以先不改

package-lock.json
coverage/
node_modules/
build/
dist/
lib/
14 changes: 14 additions & 0 deletions packages/rax-cli/src/generator/component/_travis.yml
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
5 changes: 5 additions & 0 deletions packages/rax-cli/src/generator/component/demo/index.js
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 });
31 changes: 31 additions & 0 deletions packages/rax-cli/src/generator/component/package.json
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"
}
}
13 changes: 13 additions & 0 deletions packages/rax-cli/src/generator/component/public/index.html
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>
10 changes: 10 additions & 0 deletions packages/rax-cli/src/generator/component/src/__tests__/index.js
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');
});
});
Empty file.
21 changes: 21 additions & 0 deletions packages/rax-cli/src/generator/component/src/index.js
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>
);
};
12 changes: 12 additions & 0 deletions packages/rax-scripts/bin/rax-scripts-lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
12 changes: 12 additions & 0 deletions packages/rax-scripts/bin/rax-scripts-test.js
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);
2 changes: 2 additions & 0 deletions packages/rax-scripts/bin/rax-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ program
.usage('<command> [options]')
.command('build', 'Build project in production mode')
.command('start', 'Start a web server in development mode (hot-reload and inline-module-source-map is enable default)')
.command('lint', 'Lint for source (only support component now)')
.command('test', 'Testing use jest(only support component now)')
.parse(process.argv);
9 changes: 9 additions & 0 deletions packages/rax-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些包不应该加到scripts里的依赖,这些是项目生成后里的依赖

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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",
Expand Down
3 changes: 2 additions & 1 deletion packages/rax-scripts/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function buildCompiler(config) {
}

const MINIAPP = 'miniapp';
const COMPONENT = 'component';
const webpackConfigMap = {
webapp: './config/webapp/webpack.config.prod',
weexapp: './config/weexapp/webpack.config.prod',
Expand All @@ -44,7 +45,7 @@ module.exports = function build(type = 'webapp') {

if (type === MINIAPP) {
jsx2mp(pathConfig.appDirectory, pathConfig.appDist, false);
} else if (appPackage.keywords && appPackage.keywords.indexOf('rax-component')) { // build component
} else if (type === COMPONENT) { // build component
var webpackConfigComponentDistProd = require(webpackConfigMap.component);
componentCompiler(appPackage.name);
rimraf(pathConfig.appDist, function(err) {
Expand Down
86 changes: 86 additions & 0 deletions packages/rax-scripts/src/config/component/webpack.config.base.js
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'),
},
],
},
],
},
};
28 changes: 28 additions & 0 deletions packages/rax-scripts/src/config/component/webpack.config.dev.js
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;
Loading