Skip to content

Commit d691352

Browse files
committed
init
1 parent f0257dd commit d691352

Some content is hidden

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

44 files changed

+6316
-14
lines changed

.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets":[
3+
"es2015",
4+
"stage-0",
5+
"react"
6+
],
7+
"plugins":[
8+
"transform-runtime",
9+
"react-hot-loader/babel"
10+
]
11+
}

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*.{js,css}]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_style = space
9+
indent_size = 2

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/*
2+
build/*

.eslintrc.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const eslintrc = {
2+
"extends": "airbnb",
3+
"env": {
4+
"browser": true
5+
},
6+
"settings": {
7+
"import/resolver": {
8+
"webpack": {
9+
"config": "build/webpack-config"
10+
}
11+
}
12+
},
13+
"globals": {
14+
"__DEV__": false,
15+
"__TEST__": false,
16+
"__PROD__": false,
17+
"__COVERAGE__": false,
18+
"window": false
19+
},
20+
"parser": "babel-eslint",
21+
"rules": {
22+
"comma-dangle": [2, "never"],
23+
"react/jsx-filename-extension": [1, {
24+
"extensions": [".js", ".jsx"]
25+
}],
26+
"react/forbid-prop-types": [0],
27+
"no-param-reassign": [0],
28+
"no-console": [0],
29+
"import/no-extraneous-dependencies": [2, {
30+
"devDependencies": ["**/build/**/**", "**/tests/**/**","**/bin/**"]
31+
}],
32+
"global-require": [0]
33+
}
34+
}
35+
36+
module.exports = eslintrc;

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
npm-debug.log
15+
node_modules

LICENSE

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2016 magic-FE
3+
Copyright (c) 2016 L。
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
1111

1212
The above copyright notice and this permission notice shall be included in all
1313
copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#react-redux-boilerplate
2+
react+redux+react-hot-loader+react-router(async) and so on...
3+
4+
react-router3 will console a warning , you can see[#249](https://github.com/gaearon/react-hot-loader/issues/249) . don't worry!
5+
6+
about test, I will write. please wait a moment!
7+
8+
## Usage
9+
10+
```bash
11+
$ git clone https://github.com/likun7981/react-redux-bolierplate
12+
$ yarn install(or npm install)
13+
$ npm start
14+
```
15+
## License
16+
17+
(The MIT License)
18+
19+
Permission is hereby granted, free of charge, to any person obtaining
20+
a copy of this software and associated documentation files (the
21+
'Software'), to deal in the Software without restriction, including
22+
without limitation the rights to use, copy, modify, merge, publish,
23+
distribute, sublicense, and/or sell copies of the Software, and to
24+
permit persons to whom the Software is furnished to do so, subject to
25+
the following conditions:
26+
27+
The above copyright notice and this permission notice shall be
28+
included in all copies or substantial portions of the Software.
29+
30+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
31+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
34+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
35+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
36+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bin/www.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const debug = require('debug')('app:bin:www');
2+
const ip = require('internal-ip');
3+
const server = require('../build/server');
4+
5+
const port = process.env.PORT || 3000;
6+
const host = ip.v4();
7+
8+
server.listen(port, (err) => {
9+
if (err) throw err;
10+
debug(`Server is now running at :
11+
=====================================
12+
Local: http://${host}:${port}.
13+
External: http://localhost:${port}.
14+
=====================================`);
15+
});

build/base-config/environment.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const argv = require('yargs').argv;
2+
3+
const NODE_ENV = process.env.NODE_ENV || 'development';
4+
5+
module.exports = {
6+
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
7+
__DEV__: NODE_ENV === 'development',
8+
__PROD__: NODE_ENV === 'production',
9+
__TEST__: NODE_ENV === 'test',
10+
__COVERAGE__: !argv.watch && NODE_ENV === 'test'
11+
};

build/base-config/path.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path');
2+
3+
const ROOT_PATH = path.resolve(__dirname, '../..');
4+
5+
function base() {
6+
const args = [ROOT_PATH].concat([].slice.call(arguments));
7+
return path.resolve.apply(path, args);
8+
}
9+
10+
module.exports = {
11+
root: base,
12+
src: base.bind(null, 'src'),
13+
dist: base.bind(null, 'dist'),
14+
server: base.bind(null, 'server')
15+
};

build/server.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const express = require('express');
2+
const debug = require('debug')('app:server');
3+
const webpack = require('webpack');
4+
5+
const env = require('./base-config/environment');
6+
const paths = require('./base-config/path');
7+
8+
const webpackConfig = require('./webpack-config');
9+
const app = express();
10+
11+
// This rewrites all routes requests to the root /index.html file
12+
app.use(require('connect-history-api-fallback')())
13+
14+
// Apply gzip compression
15+
app.use(require('compression')())
16+
17+
// ------------------------------------
18+
// Apply Webpack HMR Middleware
19+
// ------------------------------------
20+
if (env.__DEV__) {
21+
const compiler = webpack(webpackConfig)
22+
debug('Enable webpack dev and HMR middleware(开启开发环境插件 webpack-dev 和 HRM 中间件)')
23+
app.use(require('webpack-dev-middleware')(compiler, {
24+
publicPath: webpackConfig.output.publicPath,
25+
contentBase: paths.src(),
26+
lazy: false,
27+
// historyApiFallback: true,
28+
stats: {
29+
chunkModules: false,
30+
colors: true,
31+
chunks: false
32+
}
33+
}))
34+
app.use(require('webpack-hot-middleware')(compiler))
35+
36+
// Serve static assets from ~/src/static since Webpack is unaware of
37+
// these files. This middleware doesn't need to be enabled outside
38+
// of development since this directory will be copied into ~/dist
39+
// when the application is compiled.
40+
app.use(express.static(paths.src('static')))
41+
} else {
42+
debug(
43+
'Server is being run outside of live development mode, meaning it will ' +
44+
'only serve the compiled application bundle in ~/dist. Generally you ' +
45+
'do not need an application server for this and can instead use a web ' +
46+
'server such as nginx to serve your static files. See the "deployment" ' +
47+
'section in the README for more information on deployment strategies.'
48+
)
49+
// Serving ~/dist by default. Ideally these files should be served by
50+
// the web server and not the app server, but this helps to demo the
51+
// server in production.
52+
app.use(express.static(paths.dist()))
53+
}
54+
55+
module.exports = app;

build/webpack-config/alias.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = paths => ({
2+
REDUCER_TOOL: paths.src('store/reducerTool'),
3+
FETCH: paths.src('fetch'),
4+
COMPONENTS: paths.src('components'),
5+
CONTAINERS: paths.src('containers'),
6+
STYLES: paths.src('static/styles'),
7+
REDUCERS: paths.src('reducers'),
8+
LAYOUTS: paths.src('layouts')
9+
});

build/webpack-config/base.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const debug = require('debug')('app:webpack:base');
2+
const env = require('../base-config/environment');
3+
4+
const __DEV__ = env.__DEV__;
5+
6+
const pkg = require('../../package.json');
7+
8+
module.exports = (paths) => {
9+
const App = [paths.src('main.js')];
10+
const Vendors = [
11+
'react',
12+
'react-redux',
13+
'react-router',
14+
'redux',
15+
'react-dom'
16+
].filter((dep) => {
17+
if (pkg.dependencies[dep]) return true;
18+
return debug(
19+
`Package "${dep}" was not found as an npm dependency in package.json; ` +
20+
`it won't be included in the webpack vendor bundle.
21+
Consider removing it from \`Vendors\` in this file`
22+
);
23+
});
24+
if (__DEV__) {
25+
App.unshift('webpack-hot-middleware/client');
26+
App.unshift('react-hot-loader/patch');
27+
}
28+
return {
29+
context: paths.root(),
30+
entry_vendors: Vendors,
31+
entry_app: App,
32+
devtool: __DEV__ ? 'eval' : 'cheap-source-map',
33+
output: {
34+
filename: '[name].[hash:8].js',
35+
path: paths.dist(),
36+
publicPath: '/'
37+
}
38+
};
39+
};

build/webpack-config/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const debug = require('debug')('app:webpack:index');
2+
const paths = require('../base-config/path');
3+
4+
const alias = require('./alias')(paths);
5+
const base = require('./base')(paths);
6+
const loaders = require('./loaders')();
7+
const plugins = require('./plugins')(paths);
8+
9+
debug('Creating configuration.(创建配置)');
10+
module.exports = {
11+
entry: {
12+
app: base.entry_app,
13+
vendors: base.entry_vendors
14+
},
15+
output: base.output,
16+
resolve: {
17+
extensions: ['.js', '.jsx', '.json'],
18+
alias
19+
},
20+
devtool: base.devtool,
21+
module: {
22+
loaders
23+
},
24+
performance: { hints: false },
25+
devServer: base.devServer,
26+
plugins
27+
};

build/webpack-config/loaders.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const debug = require('debug')('app:webpack:loaders');
2+
const env = require('../base-config/environment');
3+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
5+
const __DEV__ = env.__DEV__; // eslint-disable-line
6+
module.exports = () => {
7+
const loaders = [{
8+
test: /\.(js|jsx)$/,
9+
exclude: /node_modules/,
10+
loader: 'babel-loader'
11+
}, {
12+
test: /\.json$/,
13+
loader: 'json-loader'
14+
}, {
15+
test: /\.css$/,
16+
loaders: ['style-loader', 'css-loader']
17+
}, {
18+
test: /\.less$/,
19+
loaders: ['style-loader', 'css-loader', 'less-loader']
20+
}, {
21+
test: /\.woff(\?.*)?$/,
22+
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff'
23+
}, {
24+
test: /\.woff2(\?.*)?$/,
25+
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff2'
26+
}, {
27+
test: /\.otf(\?.*)?$/,
28+
loader: 'file-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=font/opentype'
29+
}, {
30+
test: /\.ttf(\?.*)?$/,
31+
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/octet-stream'
32+
}, {
33+
test: /\.eot(\?.*)?$/,
34+
loader: 'file-loader?prefix=fonts/&name=[path][name].[ext]'
35+
}, {
36+
test: /\.svg(\?.*)?$/,
37+
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=image/svg+xml'
38+
}, {
39+
test: /\.(png|jpg)$/,
40+
loader: 'url-loader?limit=8192'
41+
}];
42+
if (!__DEV__) {
43+
debug('Apply ExtractTextPlugin to CSS loaders.(非开发环境应用ExtractTextPluginLoaders到css loaders)');
44+
loaders.filter(loader => loader.loaders && loader.loaders.find(name => /css/.test(name.split('?')[0]))).forEach((loader) => {
45+
const first = loader.loaders[0];
46+
const rest = loader.loaders.slice(1);
47+
loader.loader = ExtractTextPlugin.extract(first, rest.join('!'));
48+
delete loader.loaders;
49+
});
50+
}
51+
return loaders;
52+
};

0 commit comments

Comments
 (0)