Dva: 不用dora怎么配开发环境

Created on 30 Aug 2016  ·  4Comments  ·  Source: dvajs/dva

如题。

Most helpful comment

使用 create-react-app 开发 dva 应用

安装 create-react-app,并创建应用。

$ npm install create-react-app -g
$ create-react-app myapp

进入项目目录。

$ cd myapp

安装 dva 。

$ npm install dva --save

编辑 src/index.js,替换为:

import React from 'react';
import dva from 'dva';
import App from './App';
import './index.css';

const app = dva();
app.router(() => <App />);
app.start('#root');

启动应用。

$ npm start

到这里,环境配置就完成了,然后你可以添加 model, router 等。

All 4 comments

自己搭的 报错

browser.js?add8:40    Uncaught Invariant Violation: app.model: namespace should be defined
// .babelrc
{
  "presets": ["react", "es2015","stage-1"],
  "plugins": [
    ["transform-runtime", {
      "polyfill": false,
      "regenerator": true
    }]
  ]
}
var webpack = require('webpack');
module.exports = {
  entry:  __dirname + "/src/index.js",
  output: {
    path: __dirname + "/dist",
    filename: "index.js"
  },
  devtool: 'eval-source-map',
  devServer: {
    contentBase: "./src",
    colors: true,
    historyApiFallback: true,
    inline: true,
    // hot: true
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: "json"
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel',
      },
      {
        test: /\.(css|less)$/,
        loader: 'style!css?modules'
      }
    ]
  }
}

使用 create-react-app 开发 dva 应用

安装 create-react-app,并创建应用。

$ npm install create-react-app -g
$ create-react-app myapp

进入项目目录。

$ cd myapp

安装 dva 。

$ npm install dva --save

编辑 src/index.js,替换为:

import React from 'react';
import dva from 'dva';
import App from './App';
import './index.css';

const app = dva();
app.router(() => <App />);
app.start('#root');

启动应用。

$ npm start

到这里,环境配置就完成了,然后你可以添加 model, router 等。

我也是同样的问题 namespace should be defined

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hanxiansen picture hanxiansen  ·  3Comments

BenAnn picture BenAnn  ·  3Comments

ljjsimon picture ljjsimon  ·  3Comments

seamys picture seamys  ·  4Comments

mclouvem picture mclouvem  ·  4Comments