Skip to content

Commit 69028bf

Browse files
author
Ken Berkeley
committed
bak
1 parent a803265 commit 69028bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+10871
-416
lines changed

.babelrc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"presets": ["es2015", "react", "stage-0"],
3-
"plugins": [
4-
"transform-runtime",
5-
"transform-decorators-legacy"
6-
],
2+
"presets": [
3+
["env", { "modules": false }],
4+
"stage-2"
5+
],
6+
"plugins": ["transform-runtime"],
77
"comments": false
88
}

.eslintignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
dist/**
2-
node_modules/**
31
src/assets/**
42
static/**
3+
node_modules/**

.eslintrc

Lines changed: 20 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -1,193 +1,26 @@
1+
// http://eslint.org/docs/user-guide/configuring
12
{
2-
"parser": "babel-eslint",
3-
"env": {
4-
"browser": true,
5-
"node": true,
6-
"jquery": true
3+
root: true,
4+
parser: 'babel-eslint',
5+
parserOptions: {
6+
sourceType: 'module',
7+
ecmaFeatures: {
8+
jsx: true
9+
}
710
},
8-
"plugins": [
9-
"react"
10-
],
11-
"globals": {
12-
"__DEV__": true,
13-
"__PROD__": true,
14-
"__COMPONENT_DEVTOOLS__": false,
15-
"__WHY_DID_YOU_UPDATE__": false
11+
env: {
12+
browser: true,
1613
},
17-
"ecmaFeatures": {
18-
"jsx": true,
19-
"arrowFunctions": true,
20-
"destructuring": true,
21-
"classes": true,
22-
"defaultParams": true,
23-
"blockBindings": true,
24-
"modules": true,
25-
"objectLiteralComputedProperties": true,
26-
"objectLiteralShorthandMethods": true,
27-
"objectLiteralShorthandProperties": true,
28-
"restParams": true,
29-
"spread": true,
30-
"forOf": true,
31-
"generators": true,
32-
"templateStrings": true,
33-
"superInFunctions": true,
34-
"experimentalObjectRestSpread": true
14+
globals: {
15+
__DEV__: false,
16+
__PROD__: false
3517
},
36-
"rules": {
37-
"accessor-pairs": 2,
38-
"array-bracket-spacing": 0,
39-
"block-scoped-var": 0,
40-
"brace-style": [0, "allman", { "allowSingleLine": true }],
41-
"camelcase": 1,
42-
"comma-dangle": [2, "never"],
43-
"comma-spacing": [2, { "before": false, "after": true }],
44-
"comma-style": [2, "last"],
45-
"complexity": 0,
46-
"computed-property-spacing": 0,
47-
"consistent-return": 0,
48-
"consistent-this": 0,
49-
"constructor-super": 2,
50-
"curly": [0, "multi-line"],
51-
"default-case": 0,
52-
"dot-location": [2, "property"],
53-
"dot-notation": 0,
54-
"eol-last": 2,
55-
"eqeqeq": 0,
56-
"func-names": 0,
57-
"func-style": 0,
58-
"generator-star-spacing": [2, { "before": true, "after": true }],
59-
"guard-for-in": 0,
60-
"handle-callback-err": [2, "^(err|error)$" ],
61-
"indent": 0,
62-
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
63-
"linebreak-style": 0,
64-
"lines-around-comment": 0,
65-
"max-nested-callbacks": 0,
66-
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
67-
"new-parens": 2,
68-
"newline-after-var": 0,
69-
"no-alert": 0,
70-
"no-array-constructor": 2,
71-
"no-caller": 2,
72-
"no-catch-shadow": 0,
73-
"no-cond-assign": 2,
74-
"no-console": 0,
75-
"no-constant-condition": 0,
76-
"no-continue": 0,
77-
"no-control-regex": 2,
78-
"no-debugger": 2,
79-
"no-delete-var": 2,
80-
"no-div-regex": 0,
81-
"no-dupe-args": 2,
82-
"no-dupe-keys": 2,
83-
"no-duplicate-case": 2,
84-
"no-else-return": 0,
85-
"no-empty": 0,
86-
"no-empty-character-class": 2,
87-
"no-empty-label": 2,
88-
"no-eq-null": 0,
89-
"no-eval": 2,
90-
"no-ex-assign": 2,
91-
"no-extend-native": 2,
92-
"no-extra-bind": 2,
93-
"no-extra-boolean-cast": 2,
94-
"no-extra-parens": 0,
95-
"no-extra-semi": 0,
96-
"no-fallthrough": 2,
97-
"no-floating-decimal": 2,
98-
"no-func-assign": 2,
99-
"no-implied-eval": 2,
100-
"no-inline-comments": 0,
101-
"no-inner-declarations": [2, "functions"],
102-
"no-invalid-regexp": 2,
103-
"no-irregular-whitespace": 2,
104-
"no-iterator": 2,
105-
"no-label-var": 2,
106-
"no-labels": 2,
107-
"no-lone-blocks": 2,
108-
"no-lonely-if": 0,
109-
"no-loop-func": 0,
110-
"no-mixed-requires": 0,
111-
"no-mixed-spaces-and-tabs": 2,
112-
"no-multi-spaces": 2,
113-
"no-multi-str": 2,
114-
"no-multiple-empty-lines": [0, { "max": 1 }],
115-
"no-native-reassign": 2,
116-
"no-negated-in-lhs": 2,
117-
"no-nested-ternary": 0,
118-
"no-new": 2,
119-
"no-new-func": 0,
120-
"no-new-object": 2,
121-
"no-new-require": 2,
122-
"no-new-wrappers": 2,
123-
"no-obj-calls": 2,
124-
"no-octal": 2,
125-
"no-octal-escape": 2,
126-
"no-param-reassign": 0,
127-
"no-path-concat": 0,
128-
"no-process-env": 0,
129-
"no-process-exit": 0,
130-
"no-proto": 0,
131-
"no-redeclare": 2,
132-
"no-regex-spaces": 2,
133-
"no-restricted-modules": 0,
134-
"no-return-assign": 2,
135-
"no-script-url": 0,
136-
"no-self-compare": 2,
137-
"no-sequences": 2,
138-
"no-shadow": 0,
139-
"no-shadow-restricted-names": 2,
140-
"no-spaced-func": 2,
141-
"no-sparse-arrays": 2,
142-
"no-sync": 0,
143-
"no-ternary": 0,
144-
"no-this-before-super": 2,
145-
"no-throw-literal": 2,
146-
"no-trailing-spaces": 0,
147-
"no-undef": 2,
148-
"no-undef-init": 2,
149-
"no-undefined": 0,
150-
"no-underscore-dangle": 0,
151-
"no-unexpected-multiline": 2,
152-
"no-unneeded-ternary": 2,
153-
"no-unreachable": 2,
154-
"no-unused-expressions": 0,
155-
"no-unused-vars": [2, { "vars": "all", "varsIgnorePattern": "React", "args": "none" }],
156-
"no-use-before-define": 0,
157-
"no-var": 0,
158-
"no-void": 0,
159-
"no-warning-comments": 0,
160-
"no-with": 2,
161-
"object-curly-spacing": 0,
162-
"object-shorthand": 0,
163-
"one-var": [2, { "initialized": "never" }],
164-
"operator-assignment": 0,
165-
"operator-linebreak": 0,
166-
"padded-blocks": 0,
167-
"prefer-const": 0,
168-
"quote-props": 0,
169-
"quotes": [2, "single", "avoid-escape"],
170-
"radix": 2,
171-
"react/jsx-uses-react": 2,
172-
"react/jsx-uses-vars": 2,
173-
"semi": [2, "never"],
174-
"semi-spacing": 0,
175-
"sort-vars": 0,
176-
"space-after-keywords": [2, "always"],
177-
"space-before-blocks": [2, "always"],
178-
"space-before-function-paren": 0,
179-
"space-in-parens": [2, "never"],
180-
"space-infix-ops": 2,
181-
"space-return-throw-case": 2,
182-
"space-unary-ops": [2, { "words": true, "nonwords": false }],
183-
"spaced-comment": [2, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!"] }],
184-
"strict": 0,
185-
"use-isnan": 2,
186-
"valid-jsdoc": 0,
187-
"valid-typeof": 2,
188-
"vars-on-top": 0,
189-
"wrap-iife": [2, "any"],
190-
"wrap-regex": 0,
191-
"yoda": [2, "never"]
18+
extends: 'standard',
19+
plugins: [
20+
'react'
21+
],
22+
'rules': {
23+
'arrow-parens': 0, // allow paren-less arrow functions
24+
'generator-star-spacing': 0 // allow async-await
19225
}
19326
}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.DS_Store
22
*.log
33
coverage
4-
dist
54
node_modules

.postcssrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# https://github.com/michael-ciniawsky/postcss-load-config
2+
{
3+
"plugins": {
4+
"autoprefixer": {} # to edit target browsers: use "browserlist" field in package.json
5+
}
6+
}

build/config/ENV.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var env = (process.env.NODE_ENV || 'development').trim();
2+
console.log('[Current environment]', env);
3+
4+
module.exports = {
5+
__ENV__: env,
6+
__DEV__: env === 'development',
7+
__PROD__: env === 'production'
8+
};

build/config/PATHS.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var path = require('path');
2+
3+
/**
4+
* 便捷求取路径原型函数
5+
* @param {String} target
6+
* @return {String} path to target
7+
*/
8+
String.prototype.join = function (target) {
9+
return path.join(this.toString(), target);
10+
};
11+
12+
var ROOT = path.resolve(__dirname, '../..');
13+
14+
module.exports = {
15+
ROOT: ROOT, // 项目根目录
16+
BUILD: ROOT.join('build'), // 构建工具配置目录
17+
DIST: ROOT.join('dist'), // build 后输出目录
18+
MOCK: ROOT.join('mock'), // Mock Server 目录
19+
SRC: ROOT.join('src'), // 源码目录
20+
STATIC: ROOT.join('static') // 高度静态资源目录
21+
};

build/config/PORTS.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
BROWSER_SYNC: 9090, // BrowserSync 调试服务器
3+
DEV_SERVER: 9000, // Express + Webpack 热替换开发服务器,且提供静态资源支持
4+
MOCK_SERVER: 9999 // RESTful API Mock 服务器
5+
};

build/config/style-rules.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var extract = require('extract-text-webpack-plugin').extract,
2+
ENV = require('./ENV');
3+
4+
// postcss-loader 配置见 .postcssrc
5+
var basicLoaders = ['css-loader', 'postcss-loader'];
6+
var LOADERS = {
7+
css: basicLoaders,
8+
less: basicLoaders.concat('less-loader'),
9+
sass: basicLoaders.concat('sass-loader?indentedSyntax=true'),
10+
scss: basicLoaders.concat('sass-loader')
11+
};
12+
13+
function ruleGen(ext) {
14+
var useLoaders = LOADERS[ext];
15+
16+
// 开发环境下直接内嵌 CSS 以支持热替换
17+
if (ENV.__DEV__) return ['style-loader'].concat(useLoaders);
18+
// 生产环境下分离出 CSS 文件
19+
return extract({ use: useLoaders, fallback: 'style-loader' });
20+
}
21+
22+
function styleRulesGen() {
23+
return Object.keys(LOADERS).forEach(function (ext) {
24+
return {
25+
test: new RegExp('\\.' + ext + '$'),
26+
loader: ruleGen(ext)
27+
};
28+
});
29+
}
30+
31+
module.exports = styleRulesGen();

build/dev.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
var express = require('express'),
22
webpack = require('webpack'),
3-
// favicon = require('express-favicon'),
3+
PATHS = require('./config/PATHS'),
4+
PORTS = require('./config/PORTS'),
45
config = require('./webpack.dev.conf'),
6+
proxy = require('http-proxy-middleware'),
57
app = express();
68

79
var compiler = webpack(config);
810

9-
// for highly stable resources
10-
app.use('/static', express.static(config.commonPath.staticDir));
11+
// 提供静态资源服务
12+
app.use('/static', express.static(PATHS.STATIC));
1113

12-
// app.use(favicon(path.join(__dirname, '../favicon.ico')));
14+
// Mock server
15+
app.use('/api', proxy({
16+
target: 'http://127.0.0.1:' + PORTS.MOCK_SERVER,
17+
changeOrigin: true,
18+
pathRewrite: {
19+
// 重写 URL:[Dev Server]/api/xxx <=> [Mock Server]/xxx
20+
'^/api': '/'
21+
}
22+
}));
1323

1424
// handle fallback for HTML5 history API
1525
app.use(require('connect-history-api-fallback')());
@@ -24,6 +34,4 @@ app.use(require('webpack-dev-middleware')(compiler, {
2434
// compilation error display
2535
app.use(require('webpack-hot-middleware')(compiler));
2636

27-
app.listen(9000, '127.0.0.1', function(err) {
28-
err && console.log(err);
29-
});
37+
app.listen(PORTS.DEV_SERVER);

0 commit comments

Comments
 (0)