Skip to content

Commit

Permalink
feat: add basic react app in examples/apps
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorVelarde committed Sep 1, 2020
1 parent fd97855 commit ea8e280
Show file tree
Hide file tree
Showing 9 changed files with 8,972 additions and 213 deletions.
4 changes: 4 additions & 0 deletions examples/apps/react-basic/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["transform-class-properties"]
}
6 changes: 6 additions & 0 deletions examples/apps/react-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A previous link is required to test current status

- `npm link` in the parent project
- `npm link @carto/web-sdk` in this app

Then, to run the project `npm install` and `npm run start`
8,562 changes: 8,562 additions & 0 deletions examples/apps/react-basic/package-lock.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions examples/apps/react-basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "react-basic",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --open --mode development",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@carto/web-sdk": "^1.0.0-alpha.2",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@babel/core": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"babel-loader": "^8.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"html-loader": "^1.3.0",
"html-webpack-plugin": "^4.4.1",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
}
}
21 changes: 21 additions & 0 deletions examples/apps/react-basic/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body,
#app,
#map {
width: 100vw;
height: 100vh;
box-sizing: border-box;
margin: 0;
}
</style>
</head>
<body>
<div id="app"></div>
</body>
</html>
25 changes: 25 additions & 0 deletions examples/apps/react-basic/src/Map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { auth, viz } from '@carto/web-sdk';

class Map extends React.Component {
map = null;

componentDidMount() {
auth.setDefaultCredentials({ username: 'public' });
// this.map = viz.createMap();
this.map = viz.createMap({
basemap: 'darkmatter',
view: { zoom: 4, longitude: 3, latitude: 40, pitch: 0, bearing: 0 },
container: 'map'
});

const ports = new viz.Layer('world_ports');
ports.addTo(this.map);
}

render() {
return <div id="map">Map</div>;
}
}

export default Map;
5 changes: 5 additions & 0 deletions examples/apps/react-basic/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Map from './Map';

ReactDOM.render(<Map />, document.getElementById('app'));
38 changes: 38 additions & 0 deletions examples/apps/react-basic/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader'
}
]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: './public/index.html',
filename: './index.html'
})
]
};
Loading

0 comments on commit ea8e280

Please sign in to comment.