Skip to content

Commit 55209a6

Browse files
committed
init project.
0 parents  commit 55209a6

15 files changed

+13376
-0
lines changed

.babelrc.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const babelrc = {
2+
"presets": [
3+
[
4+
"env", {
5+
"targets": {
6+
"browsers": ["last 2 versions", "ie >= 10"]
7+
}
8+
}
9+
],
10+
"react"
11+
],
12+
"plugins": [
13+
"transform-object-rest-spread",
14+
"syntax-dynamic-import",
15+
"transform-async-to-generator",
16+
"transform-class-properties",
17+
],
18+
"env": {
19+
"production": {}
20+
},
21+
}
22+
23+
// if (process.env.NODE_ENV === 'development') {
24+
// // 不要包含多余的空格字符和行结束符。
25+
// // 设置为“auto”时,对于大于500KB的输入大小,设置为"true"。
26+
// // https://babeljs.io/docs/usage/api/#options
27+
// babelrc.cacheDirectory = true;
28+
// } else {
29+
// babelrc.compact = true;
30+
// }
31+
32+
module.exports = babelrc

.bin/kkt.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
3+
const program = require('commander');
4+
const pkg = require('../package.json');
5+
const Start = require('../script/start');
6+
const Build = require('../script/build');
7+
8+
program
9+
.description('Cli tool for creating react apps.')
10+
.option('build', 'Builds the app for production to the dist folder.')
11+
.option('start', 'Runs the app in development mode.')
12+
.option('-h, --host <host>', 'The port and host.', '0.0.0.0:19870')
13+
.version(pkg.version, '-v, --version')
14+
.on('--help', function () {
15+
console.log('\n Examples:');
16+
console.log();
17+
console.log(' $ kkt start');
18+
console.log(' $ kkt build');
19+
console.log();
20+
})
21+
.parse(process.argv);
22+
23+
if (program.host) {
24+
program.host = program.host.split(':');
25+
process.env.HOST = program.host[0] || '0.0.0.0';
26+
process.env.PORT = parseInt(program.host[1]) || 19870;
27+
}
28+
// console.log('process.env:', process.env)
29+
if (program.start) {
30+
// console.log('program:', program);
31+
Start()
32+
} else if (program.build) {
33+
Build()
34+
} else {
35+
program.outputHelp();
36+
}

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[*.less]
16+
indent_style = space
17+
indent_size = 2
18+
19+
[Makefile]
20+
indent_style = tab

.eslintrc.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const eslintrc = {
2+
"parser": "babel-eslint",
3+
"extends": "airbnb",
4+
"env": {
5+
"browser": true,
6+
"node": true,
7+
"es6": true,
8+
"mocha": true,
9+
"jest": true,
10+
"jasmine": true
11+
},
12+
"plugins": [
13+
"react",
14+
"import"
15+
],
16+
"parserOptions": {
17+
parser: 'babel-eslint',
18+
},
19+
"rules": {
20+
"linebreak-style": 0,
21+
"func-names": 0,
22+
"sort-imports": 0,
23+
"arrow-body-style": 0,
24+
"prefer-destructuring": 0,
25+
"max-len": 0,
26+
"consistent-return": 0,
27+
"comma-dangle": [
28+
"error",
29+
"always-multiline"
30+
],
31+
"function-paren-newline": 0,
32+
"class-methods-use-this": 0,
33+
"react/sort-comp": 0,
34+
"react/prop-types": 0,
35+
"react/jsx-first-prop-new-line": 0,
36+
"react/require-extension": 0,
37+
"react/jsx-filename-extension": [
38+
1,
39+
{
40+
"extensions": [
41+
".js",
42+
".jsx"
43+
]
44+
}
45+
],
46+
"import/extensions": 0,
47+
"import/no-unresolved": 0,
48+
"import/no-extraneous-dependencies": 0,
49+
"import/prefer-default-export": 0,
50+
"jsx-a11y/no-static-element-interactions": 0,
51+
"jsx-a11y/anchor-has-content": 0,
52+
"jsx-a11y/click-events-have-key-events": 0,
53+
"jsx-a11y/anchor-is-valid": 0,
54+
"jsx-a11y/label-has-for": 0,
55+
"jsx-a11y/no-noninteractive-element-interactions": 0,
56+
"jsx-a11y/mouse-events-have-key-events": 0,
57+
"react/no-danger": 0,
58+
"react/jsx-no-bind": 0,
59+
"react/forbid-prop-types": 0,
60+
"react/require-default-props": 0,
61+
"react/no-did-mount-set-state": 0,
62+
"react/no-array-index-key": 0,
63+
"react/no-find-dom-node": 0,
64+
"react/no-unused-state": 0,
65+
"react/no-unused-prop-types": 0,
66+
"react/default-props-match-prop-types": 0,
67+
"react/jsx-curly-spacing": 0,
68+
"react/no-render-return-value": 0,
69+
"object-curly-newline": 0,
70+
"no-param-reassign": 0,
71+
"no-return-assign": 0,
72+
"no-redeclare": 0,
73+
"no-restricted-globals": 0,
74+
"no-restricted-syntax": 0,
75+
"no-underscore-dangle": 0,
76+
"no-unused-expressions": 0
77+
}
78+
}
79+
80+
if (process.env.NODE_ENV === 'development') {
81+
Object.assign(eslintrc.rules,
82+
{
83+
'no-console': 0,
84+
'no-unused-vars': 0,
85+
});
86+
}
87+
88+
module.exports = eslintrc

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
npm-debug.log*

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kkt
2+
---
3+
4+
Cli tool for creating react apps.

conf/path.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const PATH = require('path');
2+
const FS = require('fs');
3+
4+
// 确保在项目文件夹中的任何符号都解决了:
5+
const appDirectory = FS.realpathSync(process.cwd());
6+
const toolDirectory = FS.realpathSync(__dirname);
7+
// Markdown 所在目录
8+
const resolveApp = relativePath => PATH.resolve(appDirectory, relativePath);
9+
// rdoc 工具所在目录
10+
const resolveTool = relativePath => PATH.resolve(toolDirectory, relativePath);
11+
12+
module.exports = {
13+
appBuildDist: resolveApp('dist'),
14+
appPublicPath: '/',
15+
appIndex: resolveApp('src/index.js'),
16+
defaultHTMLPath: resolveApp('public/index.html'),
17+
};

conf/webpack.config.dev.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const autoprefixer = require('autoprefixer');
2+
const webpack = require('webpack');
3+
const PATH = require('path');
4+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
const CreateSpareWebpackPlugin = require('create-spare-webpack-plugin');
6+
const FriendlyErrorsWebpackPlugin = require('@nuxtjs/friendly-errors-webpack-plugin');
7+
const config = require('./webpack.config');
8+
const paths = require('./path');
9+
10+
module.exports = function () {
11+
config.mode = 'development';
12+
config.entry = [
13+
require.resolve('webpack-hot-dev-clients/webpackHotDevClient'),
14+
paths.appIndex,
15+
];
16+
config.module.rules = config.module.rules.map((item) => {
17+
// if (item.oneOf) {
18+
// const loaders = [];
19+
// loaders.push();
20+
// item.oneOf = loaders.concat(item.oneOf);
21+
// }
22+
return item;
23+
});
24+
25+
26+
config.plugins = config.plugins.concat([
27+
// new webpack.HotModuleReplacementPlugin(),
28+
new HtmlWebpackPlugin({
29+
inject: true,
30+
// favicon: paths.defaultFaviconPath,
31+
template: paths.defaultHTMLPath,
32+
}),
33+
// new webpack.DefinePlugin({
34+
// VERSION: JSON.stringify(pkg.version),
35+
// }),
36+
// 将模块名称添加到工厂功能,以便它们显示在浏览器分析器中。
37+
// 当接收到热更新信号时,在浏览器console控制台打印更多可读性高的模块名称等信息
38+
new webpack.NamedModulesPlugin(),
39+
new FriendlyErrorsWebpackPlugin({
40+
clearConsole: true,
41+
}),
42+
]);
43+
44+
return config;
45+
};

conf/webpack.config.js

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const autoprefixer = require('autoprefixer');
2+
const PATH = require('path');
3+
const paths = require('./path');
4+
5+
module.exports = {
6+
entry: {},
7+
output: {
8+
path: paths.appBuildDist,
9+
publicPath: paths.appPublicPath,
10+
filename: 'js/[name].[hash:8].js',
11+
chunkFilename: 'js/[name].[hash:8].js',
12+
},
13+
module: {
14+
rules: [
15+
{
16+
test: /\.(js|jsx|mjs)$/,
17+
exclude: [/node_modules/],
18+
enforce: 'pre',
19+
use: [
20+
// TODO:禁用require.ensure也不是一种标准的语言特征。
21+
// 我们等待https://github.com/facebookincubator/create-react-app/issues/2176。
22+
// { parser: { requireEnsure: false } },
23+
{
24+
// 首先运行linter。
25+
// 在Babel处理js之前做这一点很重要。
26+
options: {
27+
eslintPath: require.resolve('eslint'),
28+
configFile: require.resolve('../.eslintrc.js'),
29+
},
30+
loader: require.resolve('eslint-loader'),
31+
},
32+
],
33+
},
34+
{
35+
// “oneOf”将遍历所有以下加载程序,直到一个符合要求。
36+
// 当没有加载器匹配时,它将返回到加载程序列表末尾的“file”加载器。
37+
oneOf: [
38+
{
39+
// Process JS with Babel.
40+
test: /\.(js|jsx|mjs)$/,
41+
use: [
42+
{
43+
loader: require.resolve('babel-loader'),
44+
options: require('../.babelrc'), // eslint-disable-line
45+
},
46+
],
47+
},
48+
{
49+
test: /\.(css|less)$/,
50+
use: [
51+
require.resolve('style-loader'),
52+
{
53+
loader: require.resolve('css-loader'),
54+
options: {
55+
modules: true,
56+
localIdentName: '[name]-[hash:base64:5]',
57+
importLoaders: 1,
58+
},
59+
},
60+
{
61+
loader: require.resolve('postcss-loader'),
62+
options: {
63+
// Necessary for external CSS imports to work
64+
// https://github.com/facebookincubator/create-react-app/issues/2677
65+
ident: 'postcss',
66+
plugins: () => [
67+
require('postcss-flexbugs-fixes'), // eslint-disable-line
68+
autoprefixer({
69+
browsers: [
70+
'>1%',
71+
'last 4 versions',
72+
'Firefox ESR',
73+
'not ie < 9', // React doesn't support IE8 anyway
74+
],
75+
flexbox: 'no-2009',
76+
}),
77+
],
78+
},
79+
},
80+
require.resolve('less-loader'),
81+
],
82+
},
83+
// “file-loader”确保这些资源由WebpackDevServer服务。
84+
// 当您导入资源时,您将获得(虚拟)文件名。
85+
// 在生产中,它们将被复制到`build`文件夹。
86+
// 此加载程序不使用“test”,因此它将捕获所有模块
87+
{
88+
// 排除`js`文件以保持“css”加载器工作,因为它注入它的运行时,否则将通过“文件”加载器处理。
89+
// 还可以排除“html”和“json”扩展名,以便它们被webpacks内部加载器处理。
90+
exclude: [/\.js$/, /\.html$/, /\.json$/],
91+
loader: require.resolve('file-loader'),
92+
options: {
93+
name: 'static/[name].[hash:8].[ext]',
94+
},
95+
},
96+
],
97+
},
98+
],
99+
},
100+
plugins: [],
101+
node: {
102+
dgram: 'empty',
103+
fs: 'empty',
104+
net: 'empty',
105+
tls: 'empty',
106+
child_process: 'empty',
107+
},
108+
};

0 commit comments

Comments
 (0)