├── anu-demo ├── .babelrc ├── index.html ├── package.json ├── src │ ├── index.js │ └── Loading.js └── webpack.config.js ├── .gitignore ├── .npmignore ├── README.md ├── package.json ├── LICENSE └── index.js /anu-demo/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env", 4 | "react", 5 | "stage-0" 6 | ], 7 | "plugins": [ 8 | "syntax-dynamic-import" 9 | ] 10 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject/private/ 2 | /node_modules/* 3 | /md/* 4 | /coverage/ 5 | package-lock.json 6 | node_modules/ 7 | chromedriver 8 | selenium-server-* 9 | /.vscode/* 10 | /.history/* 11 | xxx.js 12 | index.css 13 | stand.js -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /nbproject/private/ 2 | /node_modules/* 3 | /md/* 4 | /coverage/ 5 | /test/* 6 | /benchmarks/* 7 | /package-lock.json 8 | node_modules/ 9 | /index*.html 10 | /version.md 11 | karma.conf.js 12 | chromedriver 13 | selenium-server-* 14 | /.vscode/* 15 | /.history/* 16 | /xxx.js 17 | /index.css 18 | /stand.js 19 | -------------------------------------------------------------------------------- /anu-demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 |加载中{this.state.dots}
36 | } 37 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 司徒正美 4 | 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: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | 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. 22 | -------------------------------------------------------------------------------- /anu-demo/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const webpack = require('webpack') 3 | 4 | console.log('输出', path.resolve(__dirname, 'dist')) 5 | const ROOT_PATH = path.resolve(__dirname); 6 | 7 | module.exports = { 8 | entry: ['webpack-dev-server/client?http://localhost:8080', 9 | 'webpack/hot/only-dev-server', 10 | './src/index.js'], 11 | output: { 12 | filename: 'bundle.js', 13 | publicPath: "/assets/", 14 | path: path.resolve(__dirname, 'dist') 15 | }, 16 | 'mode': 'development', 17 | module: { 18 | rules: [ 19 | { 20 | test: /\.js$/, 21 | use: 'babel-loader', 22 | exclude: /node_modules|vendor|bootstrap/ 23 | } 24 | ] 25 | }, 26 | resolve: { 27 | extensions: ['.js', '.jsx'], 28 | alias: { 29 | react: 'anujs', 30 | 'react-dom': 'anujs' 31 | } 32 | }, 33 | devServer: { 34 | watchOptions: { 35 | aggregateTimeout: 300, 36 | poll: 1000 37 | }, 38 | hot: true, 39 | headers: { "X-Custom-Header": "yes" }, 40 | historyApiFallback: true, 41 | inline: true, //注意:不要写colors:true,progress:true等,webpack2.x已不支持这些 42 | }, 43 | plugins: [ 44 | new webpack.HotModuleReplacementPlugin() 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const readline = require('readline') 4 | const fs = require('fs') 5 | const path = require('path') 6 | const json = require('./package.json') 7 | const shell = require('shelljs'); 8 | 9 | let cliPath = process.cwd(), projectName, args = process.argv.slice(2); 10 | 11 | 12 | const rl = readline.createInterface({ 13 | input: process.stdin, 14 | output: process.stdout 15 | }).on('close', () => { 16 | buildProject(path.resolve(cliPath, projectName)) 17 | }) 18 | 19 | getAnswer.apply(null, args); 20 | 21 | function getAnswer(a, b) { 22 | switch (a) { 23 | case '-h': 24 | console.log(` 25 | -h 提问 26 | -v 版本号 27 | projectName --ie 输入项目名,及可选的旧式IE支持,正式建立项目 28 | `) 29 | break 30 | case '-v': 31 | console.log('当前版本是' + json.version) 32 | break 33 | default: 34 | let ie = b == '--ie'; 35 | projectName = a; 36 | if (!projectName) { 37 | rl.question('请输入项目名 ', getAnswer); 38 | } else { 39 | if (fs.existsSync(projectName)) { 40 | rl.question('当前目录下已经存在此文件或文件夹名,请改一个新名字', getAnswer) 41 | } else { 42 | rl.close() 43 | } 44 | } 45 | break 46 | } 47 | } 48 | 49 | 50 | function buildProject(pathName, supportIE) { 51 | shell.mkdir(pathName) 52 | console.log(`拷贝模板工程。。。`) 53 | shell.cp("-r", __dirname + '/anu-demo/.*', pathName) 54 | shell.cp("-r", __dirname + '/anu-demo/*', pathName) 55 | // 上面两个相当于 56 | // require('fs-extra').copySync(__dirname + '/anu-demo/', pathName) 57 | console.log(`拷贝模板工程完成。。。`) 58 | shell.cd(pathName) 59 | console.log(`执行 yarn install。。。`) 60 | if (shell.exec('yarn').code !== 0) { 61 | shell.echo('yarn 安装失败'); 62 | shell.exit(1); 63 | } 64 | if (shell.which('webpack')) { 65 | if (shell.exec('webpack').code !== 0) { 66 | shell.echo('webpack 安装失败'); 67 | shell.exit(1); 68 | } 69 | } else { 70 | shell.echo('Sorry, please **yarn webpack**'); 71 | shell.exit(1); 72 | } 73 | shell.exec('npm run start:dev') 74 | console.log("\x1b[36m%s\x1b[0m", "请在浏览器打开 http://localhost:8080") 75 | } 76 | --------------------------------------------------------------------------------