xielq 4 жил өмнө
commit
2a3d4d1017

+ 20 - 0
web/LICENSE

@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2017 comyn
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 1 - 0
web/README.md

@@ -0,0 +1 @@
+#react-mobx-starter

+ 13 - 0
web/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>马哥教育React项目</title>
+</head>
+<body>
+<h1>马哥教育React项目 测试程序</h1>
+<hr>
+<div id="root"></div>
+<script src="/assets/bundle.js"></script>
+</body>
+</html>

+ 7 - 0
web/jsconfig.json

@@ -0,0 +1,7 @@
+{
+    "compilerOptions": {
+        "target": "ES6",
+        "module": "commonjs",
+        "experimentalDecorators": true
+    }
+}

+ 50 - 0
web/package.json

@@ -0,0 +1,50 @@
+{
+  "name": "web",
+  "version": "1.0.0",
+  "description": "react mobx starter",
+  "main": "index.js",
+  "scripts": {
+    "test": "jest",
+    "start": "webpack-dev-server --config webpack.config.dev.js --hot --inline",
+    "build": "webpack -p --config webpack.config.prod.js"
+  },
+  "repository": {},
+  "author": "xielq",
+  "license": "MIT",
+  "devDependencies": {
+    "babel-core": "^6.24.1",
+    "babel-jest": "^19.0.0",
+    "babel-loader": "^6.4.1",
+    "babel-plugin-transform-decorators-legacy": "^1.3.4",
+    "babel-plugin-transform-runtime": "^6.23.0",
+    "babel-preset-env": "^1.4.0",
+    "babel-preset-react": "^6.24.1",
+    "babel-preset-stage-0": "^6.24.1",
+    "css-loader": "^0.28.0",
+    "html-webpack-plugin": "^2.28.0",
+    "jest": "^19.0.2",
+    "less": "^2.7.2",
+    "less-loader": "^4.0.3",
+    "react-hot-loader": "^3.0.0-beta.6",
+    "source-map": "^0.5.6",
+    "source-map-loader": "^0.2.1",
+    "style-loader": "^0.16.1",
+    "uglify-js": "^2.8.22",
+    "webpack": "^2.4.1",
+    "webpack-dev-server": "^2.4.2"
+  },
+  "dependencies": {
+    "antd": "^2.9.1",
+    "axios": "^0.16.1",
+    "babel-polyfill": "^6.23.0",
+    "babel-runtime": "^6.23.0",
+    "mobx": "^3.1.9",
+    "mobx-react": "^4.1.8",
+    "mobx-react-devtools": "^4.2.11",
+    "prop-types": "^15.5.8",
+    "react": "^15.5.4",
+    "react-dom": "^15.5.4",
+    "react-router": "^4.1.1",
+    "react-router-dom": "^4.1.1"
+  }
+}

+ 23 - 0
web/src/App.js

@@ -0,0 +1,23 @@
+import React, { Component } from 'react';
+import { observer } from 'mobx-react';
+import DevTools from 'mobx-react-devtools';
+
+@observer
+class App extends Component {
+  render() {
+    return (
+      <div>
+        <button onClick={this.onReset}>
+          Seconds passed: {this.props.appState.timer}
+        </button>
+        <DevTools />
+      </div>
+    );
+  }
+
+  onReset = () => {
+    this.props.appState.resetTimer();
+  }
+};
+
+export default App;

+ 17 - 0
web/src/AppState.js

@@ -0,0 +1,17 @@
+import { observable } from 'mobx';
+
+class AppState {
+  @observable timer = 0;
+
+  constructor() {
+    setInterval(() => {
+      this.timer += 1;
+    }, 1000);
+  }
+
+  resetTimer() {
+    this.timer = 0;
+  }
+}
+
+export default AppState;

+ 10 - 0
web/src/index.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+<div id="root"></div>
+</body>
+</html>

+ 18 - 0
web/src/index.js

@@ -0,0 +1,18 @@
+import React from 'react';
+import { render } from 'react-dom';
+import { AppContainer } from 'react-hot-loader';
+import AppState from './AppState';
+import App from './App';
+
+const appState = new AppState();
+
+render(
+  <AppContainer>
+    <App appState={appState} />
+  </AppContainer>,
+  document.getElementById('root')
+);
+
+if (module.hot) {
+  module.hot.accept('./App', () => { render(App) })
+}

+ 66 - 0
web/webpack.config.dev.js

@@ -0,0 +1,66 @@
+/**
+ * Created by magedu on 2017/4/20.
+ */
+
+const path = require('path');
+const webpack = require('webpack');
+
+module.exports = {
+    devtool: 'source-map',
+    entry: {
+        'app': [
+            'react-hot-loader/patch',
+            './src/index'
+        ]
+    },
+    output: {
+        path: path.join(__dirname, 'dist'),
+        filename: 'bundle.js',
+        publicPath: '/assets/'
+    },
+    resolve: {
+        extensions: ['.js']
+    },
+    module: {
+        rules: [
+            {
+                test: /\.js$/,
+                exclude: /node_modules/,
+                use: [
+                    { loader: 'react-hot-loader/webpack' },
+                    { loader: 'babel-loader' }
+                ]
+            },
+            {
+                test: /\.less$/,
+                use: [
+                    { loader: "style-loader" },
+                    { loader: "css-loader" },
+                    { loader: "less-loader" }
+                ]
+            }
+        ]
+    },
+    plugins: [
+        new webpack.optimize.OccurrenceOrderPlugin(true),
+        new webpack.HotModuleReplacementPlugin(),
+        new webpack.DefinePlugin({'process.env': {NODE_ENV: JSON.stringify('development')}})
+    ],
+    devServer: {
+        compress: true,
+        port: 3000,
+        publicPath: '/assets/',
+        hot: true,
+        inline: true,
+        historyApiFallback: true,
+        stats: {
+            chunks: false
+        },
+        proxy: {
+            '/api': {
+                target: 'http://127.0.0.1:8080',
+                changeOrigin: true
+            }
+        }
+    }
+};

+ 58 - 0
web/webpack.config.prod.js

@@ -0,0 +1,58 @@
+/**
+ * Created by magedu on 2017/4/20.
+ */
+
+const path = require('path');
+const webpack = require('webpack');
+const HtmlWebpackPlugin = require('html-webpack-plugin');
+
+module.exports = {
+    devtool: 'source-map',
+    entry: {
+        'app': [
+            './src/index'
+        ]
+    },
+    output: {
+        path: path.join(__dirname, 'dist'),
+        filename: '[name]-[hash:8].js',
+        publicPath: '/assets/'
+    },
+    resolve: {
+        extensions: ['.js']
+    },
+    module: {
+        rules: [
+            {
+                test: /\.js$/,
+                exclude: /node_modules/, // 不编译第三方包
+                use: [
+                    { loader: 'react-hot-loader/webpack' },
+                    { loader: 'babel-loader' }
+                ]
+            },
+            {
+                test: /\.less$/,
+                use: [
+                    { loader: "style-loader" },
+                    { loader: "css-loader" },
+                    { loader: "less-loader" }
+                ]
+            }
+        ]
+    },
+    plugins: [
+        new webpack.optimize.OccurrenceOrderPlugin(true),
+        new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('production') } }),
+        new webpack.optimize.UglifyJsPlugin({
+            compress: {
+                warnings: false
+            },
+            sourceMap: true
+        }),
+        new HtmlWebpackPlugin({
+            template: 'src/index.html',
+            inject: true
+        })
+    ]
+};