Skip to content

Commit 1d068d8

Browse files
committed
React installed inside Django's frontend app
1 parent cce15ed commit 1d068d8

File tree

8 files changed

+5601
-0
lines changed

8 files changed

+5601
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env", "@babel/preset-react"]
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, { Component} from "react";
2+
3+
class App extends Component{
4+
render(){
5+
return(
6+
<div className="site">
7+
<h1>Ahhh after 10,000 years I'm free. Time to conquer the Earth!</h1>
8+
</div>
9+
);
10+
}
11+
}
12+
13+
export default App;

djsr/frontend/src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react'
2+
import {render} from 'react-dom'
3+
import App from './components/App';
4+
5+
render(<App />, document.getElementById('root'));

djsr/frontend/static/frontend/public/main.js

Lines changed: 256 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

djsr/frontend/templates/frontend/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<div id="root" class="content">
1212
This will be the base template.
1313
</div>
14+
<script type="text/javascript" src="{% static 'frontend/public/main.js' %}"></script>
1415
</body>
1516
</html>

package-lock.json

Lines changed: 5267 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "django-jwt-react",
3+
"version": "1.0.0",
4+
"description": "To learn how to merge React and Django",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "webpack --config webpack.config.js",
8+
"test": "test"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"@babel/core": "^7.4.5",
14+
"@babel/preset-env": "^7.4.5",
15+
"@babel/preset-react": "^7.0.0",
16+
"babel-loader": "^8.0.6",
17+
"webpack": "^4.35.0",
18+
"webpack-cli": "^3.3.4"
19+
},
20+
"dependencies": {
21+
"react": "^16.8.6",
22+
"react-dom": "^16.8.6"
23+
}
24+
}

webpack.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
mode: "development",
5+
entry: path.resolve(__dirname, 'djsr/frontend/src/index.js'),
6+
output: {
7+
// options related to how webpack emits results
8+
9+
// where compiled files go
10+
path: path.resolve(__dirname, "djsr/frontend/static/frontend/public/"),
11+
12+
// 127.0.0.1/static/frontend/public/ where files are served from
13+
publicPath: "/static/frontend/public/",
14+
filename: 'main.js', // the same one we import in index.html
15+
},
16+
module: {
17+
// configuration regarding modules
18+
rules: [
19+
{
20+
// regex test for js and jsx files
21+
test: /\.(js|jsx)?$/,
22+
// don't look in the node_modules/ folder
23+
exclude: /node_modules/,
24+
// for matching files, use the babel-loader
25+
use: {
26+
loader: "babel-loader",
27+
options: {presets: ["@babel/env"]}
28+
},
29+
}
30+
],
31+
},
32+
};

0 commit comments

Comments
 (0)