์ ๋ชฉ ๊ทธ๋๋ก.
์์ ์ ์๋ชป
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 ?
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
์ด ์์ ์์ ํ๊ฒฝ ๊ตฌ์ฑ์ด ์๋ฃ๋๊ณ ๋ชจ๋ธ, ๋ผ์ฐํฐ ๋ฑ์ ์ถ๊ฐํ ์ ์์ต๋๋ค.
๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋ค์์คํ์ด์ค๋ฅผ ์ ์ํด์ผ ํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
create-react-app ์ ์ฌ์ฉํ์ฌ dva ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ
create-react-app์ ์ค์นํ๊ณ ์ฑ์ ๋ง๋ญ๋๋ค.
ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ๋ฅผ ์ ๋ ฅํฉ๋๋ค.
dva๋ฅผ ์ค์นํฉ๋๋ค.
src/index.js
ํธ์ง:์์ฉ ํ๋ก๊ทธ๋จ์ ์์ํฉ๋๋ค.
์ด ์์ ์์ ํ๊ฒฝ ๊ตฌ์ฑ์ด ์๋ฃ๋๊ณ ๋ชจ๋ธ, ๋ผ์ฐํฐ ๋ฑ์ ์ถ๊ฐํ ์ ์์ต๋๋ค.