Compare commits

...

11 Commits
RC ... master

Author SHA1 Message Date
casperlamboo 910588aaeb bumb version 2018-01-31 13:57:25 +01:00
casperlamboo 47748f4e41 add babel rc 2018-01-31 13:57:18 +01:00
casperlamboo adc83ec4c2 add url search params 2018-01-31 13:56:38 +01:00
casperlamboo 9e12026073 bumb version 2018-01-25 17:30:12 +01:00
casperlamboo 01691bc609 fix error 2018-01-25 17:29:58 +01:00
casperlamboo 5a11fafb0c fix posts 2018-01-25 17:29:51 +01:00
casperlamboo 5b7f8300bd create box data based on local ip 2018-01-25 17:27:59 +01:00
casperlamboo e874cbf012 set author 2017-11-30 18:02:39 +01:00
casperlamboo e236858f27 Merge branch 'develop' 2017-11-30 17:57:59 +01:00
casperlamboo 625198ee39 update example 2017-11-30 17:57:22 +01:00
casperlamboo c4c9f0212d update to web pack 2017-11-30 17:23:13 +01:00
23 changed files with 167108 additions and 297 deletions

25
.babelrc Normal file
View File

@ -0,0 +1,25 @@
{
"env": {
"module": {
"presets": [
["env", {
"targets": {
"node": "6",
"browsers": ["last 2 versions", "safari >= 7", "not ie < 11"]
},
"modules": false
}],
"stage-0"
]
},
"main": {
"presets": ["env", "stage-0"]
}
},
"plugins": [
"transform-class-properties",
"transform-object-rest-spread",
"transform-runtime",
"transform-es2015-classes"
]
}

12
.gitignore vendored
View File

@ -1,8 +1,4 @@
node_modules
jspm_packages/* dist
example/test.gcode lib
node_modules/* module
build.js
build.js.map

2
.npmignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
jspm_packages

View File

@ -1,28 +0,0 @@
import { Doodle3DManager } from 'src/index.js';
const doodle3DManager = new Doodle3DManager();
doodle3DManager.setAutoUpdate(true, 1000);
doodle3DManager.addEventListener('boxappeared', ({ box }) => {
box.setAutoUpdate(true, 1000);
box.addEventListener('connect', () => {
console.log('connect to box', box);
});
box.addEventListener('disconnect', () => {
console.log('disonnect to box', box);
});
box.addEventListener('update', ({ state }) => {
console.log(state);
});
});
doodle3DManager.addEventListener('boxdisappeared', ({ box }) => {
box.setAutoUpdate(false);
});
doodle3DManager.addEventListener('boxeschanged', ({ boxes }) => {
});

View File

@ -1,14 +0,0 @@
<!DOCTYPE>
<html>
<head>
<title>Doodle3D Box</title>
<script type="text/javascript" src="../jspm_packages/system.js"></script>
<script type="text/javascript" src="../jspm.config.js"></script>
</head>
<body>
<script type="text/javascript">
System.import('./app.js');
</script>
</body>
</html>

72
index.js Normal file
View File

@ -0,0 +1,72 @@
import React from 'react';
import { render } from 'react-dom';
import { Doodle3DManager } from './src/index.js';
class Box extends React.Component {
state = {
status: {}
};
componentWillMount() {
const { box } = this.props;
box.setAutoUpdate(true, 1000);
box.addEventListener('update', ({ state }) => {
this.setState({ status: state });
});
}
componentWillUnMount() {
const { box } = this.props;
box.setAutoUpdate(false);
}
render() {
return (
<div>
<p><b>name: {this.props.box.boxData.wifiboxid}</b></p>
<ul>
{Object.entries(this.state.status).map(([key, value]) => <li key={key}>{key}: {value}</li>)}
</ul>
</div>
);
};
}
class OverView extends React.Component {
state = {
boxes: []
};
componentWillMount() {
const doodle3DManager = new Doodle3DManager();
doodle3DManager.checkNonServerBoxes = false;
doodle3DManager.setAutoUpdate(true, 1000);
doodle3DManager.addEventListener('boxappeared', ({ box }) => {
this.setState({ boxes: [...this.state.boxes, <Box box={box} />] })
});
doodle3DManager.addEventListener('boxdisappeared', ({ box }) => {
this.setState({ boxes: this.state.boxes.filter(box => box.props.box.boxData.id !== box.boxData.id) })
});
this.setState({ doodle3DManager })
}
componentWillUnMount() {
const { doodle3DManager } = this.state;
if (doodle3DManager) doodle3DManager.setAutoUpdate(false);
}
render() {
const { boxes } = this.state;
return (
<div>
{boxes.map((box, i) => <span key={i}>{box}</span>)}
</div>
);
};
}
render(<OverView />, document.getElementById('app'));

View File

@ -1,51 +0,0 @@
SystemJS.config({
paths: {
"github:": "jspm_packages/github/",
"npm:": "jspm_packages/npm/",
"Doodle3D-API/": "src/"
},
browserConfig: {
"baseURL": "/"
},
devConfig: {
"map": {
"babel-runtime": "npm:babel-runtime@5.8.38",
"core-js": "npm:core-js@1.2.7",
"traceur": "github:jmcriffey/bower-traceur@0.0.90",
"traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.90",
"process": "github:jspm/nodelibs-process@0.2.0-alpha",
"fs": "github:jspm/nodelibs-fs@0.2.0-alpha",
"plugin-babel": "npm:systemjs-plugin-babel@0.0.12",
"path": "github:jspm/nodelibs-path@0.2.0-alpha"
}
},
transpiler: "plugin-babel",
babelOptions: {
"optional": [
"runtime"
],
"stage": 0
},
map: {
"babel": "npm:babel-core@5.7.4"
},
packages: {
"Doodle3D-API": {
"main": "index.js"
}
}
});
SystemJS.config({
packageConfigPaths: [
"npm:@*/*.json",
"npm:*.json",
"github:*/*.json"
],
map: {
"EventDispatcher": "github:mrdoob/eventdispatcher.js@1.0.0",
"github/fetch": "github:github/fetch@0.9.0",
"jquery": "github:components/jquery@2.2.4"
},
packages: {}
});

7364
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,57 +1,59 @@
{ {
"jspm": { "name": "@doodle3d/doodle3d-api",
"name": "Doodle3D-API", "version": "1.0.5",
"main": "index.js", "description": "Doodle3D API for communication with the Doodle3D WiFi-Box",
"directories": { "main": "lib/index.js",
"lib": "src" "module": "module/index.js",
}, "esnext": "src/index.js",
"dependencies": { "scripts": {
"EventDispatcher": "github:mrdoob/eventdispatcher.js@^1.0.0", "start": "webpack-dev-server -w",
"github/fetch": "github:github/fetch@^0.9.0", "prepare": "npm run build",
"jquery": "github:components/jquery@^2.1.4" "build": "npm run build:main && npm run build:module",
}, "build:main": "BABEL_ENV=main babel src -s -d lib",
"devDependencies": { "build:module": "BABEL_ENV=module babel src -s -d module"
"babel-runtime": "npm:babel-runtime@^5.1.13",
"core-js": "npm:core-js@^1.2.0",
"fs": "github:jspm/nodelibs-fs@^0.2.0-alpha",
"path": "github:jspm/nodelibs-path@^0.2.0-alpha",
"plugin-babel": "npm:systemjs-plugin-babel@^0.0.12",
"process": "github:jspm/nodelibs-process@^0.2.0-alpha",
"traceur": "github:jmcriffey/bower-traceur@0.0.90",
"traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.90"
},
"overrides": {
"github:components/jquery@2.2.4": {
"main": "jquery"
},
"github:jmcriffey/bower-traceur-runtime@0.0.90": {
"format": "global",
"meta": {
"traceur-runtime.js": {
"exports": "$traceurRuntime",
"format": "global"
}
}
},
"github:jmcriffey/bower-traceur@0.0.90": {
"format": "global",
"meta": {
"traceur.js": {
"exports": "traceur",
"format": "global"
}
}
},
"npm:babel-runtime@5.8.38": {
"main": false,
"dependencies": {},
"optionalDependencies": {
"core-js": "^1.2.0"
}
}
}
}, },
"dependencies": { "dependencies": {
"jspm": "^0.17.0-beta.25" "eventdispatcher.js": "0.0.2",
} "url-search-params-polyfill": "^2.0.2",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
"react": "^16.0.0",
"react-dom": "^16.0.0",
"babel-plugin-inline-import": "^2.0.6",
"babel-preset-stage-0": "^6.24.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-classes": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-cli": "6.24.1",
"babel-core": "6.24.1",
"babel-loader": "7.0.0",
"babel-plugin-add-module-exports": "0.2.1",
"babel-preset-es2015": "6.24.1",
"babel-polyfill": "^6.23.0",
"file-saver": "^1.3.3",
"html-webpack-template": "^6.0.2",
"imports-loader": "^0.7.1",
"material-ui": "^0.19.4",
"react-tap-event-plugin": "^3.0.2",
"url-loader": "^0.5.9",
"babel-plugin-transform-runtime": "^6.23.0",
"html-webpack-plugin": "^2.29.0",
"webpack": "^3.3.0",
"webpack-dev-server": "^2.5.1",
"worker-loader": "^0.8.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/casperlamboo/Doodle3D-API.git"
},
"author": "Casper Lamboo",
"license": "ISC",
"bugs": {
"url": "https://github.com/casperlamboo/Doodle3D-API/issues"
},
"homepage": "https://github.com/casperlamboo/Doodle3D-API#readme"
} }

View File

@ -1,16 +1,21 @@
import * as rest from '../rest.js'; import { parseFetch } from '../utils.js';
export default class Config { export default class Config {
constructor(api) { constructor(api) {
this.api = api; this.api = api;
} }
get(...keys) { get(...keys) {
return rest.get(`${ this.api }config/?${ keys.join('=&') }=`); return fetch(`${this.api}config/?${keys.join('=&')}=`, { method: 'GET' }).then(parseFetch);
} }
getAll() { getAll() {
return rest.get(`${ this.api }config/all`); return fetch(`${this.api}config/all`, { method: 'GET' }).then(parseFetch);
} }
set(data) { set(data) {
return rest.post(`${ this.api }config`, data); const body = new URLSearchParams();
for (const key in data) {
body.append(key, data[key]);
}
return fetch(`${this.api}config`, { method: 'POST', body }).then(parseFetch);
} }
} }

View File

@ -1,19 +1,19 @@
import * as rest from '../rest.js'; import { parseFetch } from '../utils.js';
export default class Info { export default class Info {
constructor(api) { constructor(api) {
this.api = api; this.api = api;
} }
get() { get() {
return rest.get(`${ this.api }info`); return fetch(`${this.api}info`, { method: 'GET' }).then(parseFetch);
} }
status() { status() {
return rest.get(`${ this.api }info/status`); return fetch(`${this.api}info/status`, { method: 'GET' }).then(parseFetch);
} }
downloadLogFiles() { downloadLogFiles() {
window.location = `${ this.api }info/logfiles`; window.location = `${this.api}info/logfiles`;
} }
acces() { acces() {
return rest.get(`${ this.api }info/access`); return fetch(`${this.api}info/access`, { method: 'GET' }).then(parseFetch);
} }
} }

View File

@ -1,39 +1,50 @@
import * as rest from '../rest.js'; import { parseFetch } from '../utils.js';
export default class Network { export default class Network {
constructor(api) { constructor(api) {
this.api = api; this.api = api;
} }
scan() { scan() {
return rest.get(`${ this.api }network/scan`); return fecth(`${this.api}network/scan`, { method: 'GET' }).then(parseFetch);
} }
known() { known() {
return rest.get(`${ this.api }network/known`); return fecth(`${this.api}network/known`, { method: 'GET' }).then(parseFetch);
} }
status() { status() {
return rest.get(`${ this.api }network/status`); return fecth(`${this.api}network/status`, { method: 'GET' }).then(parseFetch);
} }
assosiate(ssid, phrase, recreate = false) { assosiate(ssid, phrase, recreate = false) {
return rest.post(`${ this.api }network/associate`, { ssid, phrase, recreate }); const body = new URLSearchParams();
body.append('ssid', ssid);
body.append('phrase', phrase);
body.append('recreate', recreate);
return fetch(`${this.api}network/associate`, { method: 'POST', body }).then(parseFetch);
} }
disassociate() { disassociate() {
//not tested //not tested
return rest.post(`${ this.api }network/disassociate`, {}); const body = new URLSearchParams();
return fetch(`${this.api}network/disassociate`, { method: 'POST', body }).then(parseFetch);
} }
openAccesPoint() { openAccesPoint() {
//not tested //not tested
return rest.post(`${ this.api }network/openap`, {}); const body = new URLSearchParams();
return fetch(`${this.api}network/openap`, { method: 'POST', body }).then(parseFetch);
} }
remove(ssid) { remove(ssid) {
return rest.post(`${ this.api }network/remove`, { ssid }); const body = new URLSearchParams();
body.append('ssid', ssid);
return fetch(`${this.api}network/remove`, { method: 'POST', body }).then(parseFetch);
} }
signin() { signin() {
return rest.get(`${ this.api }network/signin`); return fecth(`${this.api}network/signin`, { method: 'GET' }).then(parseFetch);
} }
async alive() { async alive() {
try { try {
await rest.get(`${ this.api }network/alive`); await fetch(`${this.api}network/alive`, { method: 'GET' }).then(parseFetch);
return true; return true;
} catch(error) { } catch(error) {
return false; return false;

View File

@ -1,40 +1,56 @@
import * as rest from '../rest.js'; import { parseFetch, sleep } from '../utils.js';
export default class Printer { export default class Printer {
constructor(api) { constructor(api) {
this.api = api; this.api = api;
} }
temperature() { temperature() {
return rest.get(`${ this.api }printer/temperature`); return fetch(`${this.api}printer/temperature`, { method: 'GET' }).then(parseFetch);
} }
progress() { progress() {
return rest.get(`${ this.api }printer/progress`); return fetch(`${this.api}printer/progress`, { method: 'GET' }).then(parseFetch);
} }
state() { state() {
return rest.get(`${ this.api }printer/state`); return fetch(`${this.api}printer/state`, { method: 'GET' }).then(parseFetch);
} }
listAll() { listAll() {
return rest.get(`${ this.api }printer/listall`); return fetch(`${this.api}printer/listall`, { method: 'GET' }).then(parseFetch);
} }
heatup() { heatup() {
return rest.post(`${ this.api }printer/heatup`, {}); const body = new URLSearchParams();
return fetch(`${this.api}printer/heatup`, { method: 'POST', body }).then(parseFetch);
}
fetch(id, startCode = 'g28', endCode = 'g28') {
const body = new URLSearchParams();
body.append('id', id);
body.append('start_code', startCode);
body.append('end_code', endCode);
return fetch(`${this.api}printer/fetch`, { method: 'POST', body }).then(parseFetch);
} }
print(gcode = '', first = false, start = false, last) { print(gcode = '', first = false, start = false, last) {
return rest.post(`${ this.api }printer/print`, { gcode, first, start, last }); const body = new URLSearchParams();
body.append('gcode', gcode);
body.append('first', first);
body.append('start', start);
body.append('last', last);
return fetch(`${this.api}printer/print`, { method: 'POST', body }).then(parseFetch);
} }
stop(gcode = '') { stop(gcode = '') {
return rest.post(`${ this.api }printer/stop`, { gcode }); const body = new URLSearchParams();
body.append('gcode', gcode);
return fetch(`${this.api}printer/stop`, { method: 'POST', body }).then(parseFetch);
} }
async _sendBatch(gcode, start, index) { async _sendBatch(gcode, start, index) {
try { try {
const response = await this.print(gcode, start, start); const response = await this.print(gcode, start, start);
console.log(`batch sent: ${index}`);
console.log(`batch sent: ${ index }`);
} catch(error) { } catch(error) {
console.log(`failed sending batch: ${ index }`); console.log(`failed sending batch: ${index}`);
await sleep(1000); await sleep(1000);
await this._sendBatch(gcode, index); await this._sendBatch(gcode, index);
} }
} }

View File

@ -1,19 +1,24 @@
import * as rest from '../rest.js'; import { parseFetch } from '../utils.js';
export default class Sketch { export default class Sketch {
constructor(api) { constructor(api) {
this.api = api; this.api = api;
} }
getSketch(id) { getSketch(id) {
return rest.get(`${ this.api }sketch/?id=${ id }`); return fetch(`${this.api}sketch/?id=${id}`, { method: 'GET' }).then(parseFetch);
} }
set(data = '') { set(data = '') {
return rest.post(`${ this.api }sketch`, { data }); const body = new URLSearchParams();
body.append('data', data);
return fetch(`${this.api}sketch`, { method: 'POST', body }).then(parseFetch);
} }
status() { status() {
return rest.get(`${ this.api }sketch/status`); return fetch(`${this.api}sketch/status`, { method: 'GET' }).then(parseFetch);
} }
clear() { clear() {
return rest.post(`${ this.api }sketch/clear`); const body = new URLSearchParams();
return fetch(`${this.api}sketch/clear`, { method: 'POST', body }).then(parseFetch);
} }
} }

View File

@ -1,10 +1,10 @@
import * as rest from '../rest.js'; import { parseFetch } from '../utils.js';
export default class System { export default class System {
constructor(api) { constructor(api) {
this.api = api; this.api = api;
} }
versions() { versions() {
return rest.get(`${ this.api }system/fwversions`); return fetch(`${this.api}system/fwversions`, { method: 'GET' }).then(parseFetch);
} }
} }

View File

@ -1,22 +1,28 @@
import * as rest from '../rest.js'; import { parseFetch } from '../utils.js';
export default class Update { export default class Update {
constructor(api) { constructor(api) {
this.api = api; this.api = api;
} }
status() { status() {
return rest.get(`${ this.api }update/status`); return fetch(`${this.api}update/status`, { method: 'GET' }).then(parseFetch);
} }
download() { download() {
//not tested //not tested
return rest.post(`${ this.api }update/download`, {}); const body = new URLSearchParams();
return fetch(`${this.api}update/download`, { method: 'POST', body }).then(parseFetch);
} }
install() { install() {
//not tested //not tested
return rest.post(`${ this.api }update/install`, {}); const body = new URLSearchParams();
return fetch(`${this.api}update/install`, { method: 'POST', body }).then(parseFetch);
} }
clear() { clear() {
//not tested //not tested
return rest.post(`${ this.api }update/clear`, {}); const body = new URLSearchParams();
return fetch(`${this.api}update/clear`, { method: 'POST', body }).then(parseFetch);
} }
} }

View File

@ -1,4 +1,4 @@
import EventDispatcher from 'EventDispatcher'; import EventDispatcher from 'eventdispatcher.js';
import { sleep } from './utils.js'; import { sleep } from './utils.js';
import ConfigAPI from './api/config.js'; import ConfigAPI from './api/config.js';
import InfoAPI from './api/info.js'; import InfoAPI from './api/info.js';
@ -9,12 +9,12 @@ import SystemAPI from './api/system.js';
import UpdateAPI from './api/update.js'; import UpdateAPI from './api/update.js';
export default class Doodle3DBox extends EventDispatcher { export default class Doodle3DBox extends EventDispatcher {
constructor(boxData) { constructor(localip) {
super(); super();
this.boxData = boxData; this.localip = localip;
this.api = `http://${ boxData.localip }/d3dapi/`; this.api = `http://${localip}/d3dapi/`;
this.alive = false; this.alive = false;
this.autoUpdate = false; this.autoUpdate = false;
@ -54,7 +54,7 @@ export default class Doodle3DBox extends EventDispatcher {
async sendGCode(gcode) { async sendGCode(gcode) {
const printerState = await this.printer.state(); const printerState = await this.printer.state();
if (printerState.state !== 'idle') { if (printerState.state !== 'idle') {
throw `Cannot print, print state is ${ printerState.state }`; throw `Cannot print, print state is ${printerState.state}`;
} }
if (!gcode.endsWith('\n')) { if (!gcode.endsWith('\n')) {

View File

@ -1,7 +1,5 @@
import * as rest from './rest.js'; import EventDispatcher from 'eventdispatcher.js';
import Doodle3DBox from './doodle3dbox.js'; import { sleep, parseFetch } from './utils.js';
import EventDispatcher from 'EventDispatcher';
import { sleep } from './utils.js';
export default class Doodle3DManager extends EventDispatcher { export default class Doodle3DManager extends EventDispatcher {
constructor() { constructor() {
@ -41,23 +39,22 @@ export default class Doodle3DManager extends EventDispatcher {
async _checkNew() { async _checkNew() {
let boxes = []; let boxes = [];
try { try {
boxes = await rest.get(`${ this.api }list.php`); boxes = await fetch(`${this.api}list.php`, { method: 'GET' }).then(parseFetch);
} catch(error) { } catch(error) {
console.warn('fail connecting to Doodle3D server'); console.warn('fail connecting to Doodle3D server');
} }
if (this.checkNonServerBoxes) boxes = boxes.concat(this.nonServerBoxes); if (this.checkNonServerBoxes) boxes = boxes.concat(this.nonServerBoxes);
const knownIPsClient = this.boxes.map(box => box.boxData.localip); const knownIPsClient = this.boxes.map(box => box.localip);
const knownIPsServer = boxes.map(box => box.localip); const knownIPsServer = boxes.map(box => box.localip);
const newBoxes = boxes.filter(box => knownIPsClient.indexOf(box.localip) === -1); const newBoxes = boxes.filter(box => knownIPsClient.indexOf(box.localip) === -1);
const removedBoxes = this.boxes.filter(box => knownIPsServer.indexOf(box.boxData.localip) === -1); const removedBoxes = this.boxes.filter(box => knownIPsServer.indexOf(box.localip) === -1);
let changed = false; let changed = false;
for (const boxData of newBoxes) { for (const boxData of newBoxes) {
const box = new Doodle3DBox(boxData); this._addBox(boxData);
this._addBox(box);
changed = true; changed = true;
} }

View File

@ -1,3 +1,6 @@
import 'url-search-params-polyfill';
import 'whatwg-fetch';
import Doodle3DManager from './doodle3dmanager.js'; import Doodle3DManager from './doodle3dmanager.js';
import Doodle3DBox from './doodle3dbox.js'; import Doodle3DBox from './doodle3dbox.js';

View File

@ -1,84 +0,0 @@
import $ from 'jquery';
const GET_TIMEOUT = 5000;
const POST_TIMEOUT = 10000;
export function get(url) {
return send(url, 'GET');
}
export function post(url, data) {
return send(url, 'POST', data);
}
function send(url, type, data) {
const timeout = (type === 'GET') ? GET_TIMEOUT : POST_TIMEOUT;
return new Promise((resolve, reject) => {
$.ajax({
url, type, data, timeout, dataType: 'json',
success: (response) => {
if (response.status === 'success') {
resolve(response.data);
}
else {
reject(response.msg);
}
}
}).fail(reject);
});
}
/*
import 'github/fetch';
export function get (url) {
return new Promise((resolve, reject) => {
fetch(url).then((response) => {
return response.json();
}).then((json) => {
if (json.status === 'success') {
resolve(json.data);
}
else {
reject(json.msg);
}
}).catch(reject);
});
}
export function post (url, data) {
return new Promise((resolve, reject) => {
fetch(url, {
method: 'post',
enctype: 'x-www-form-urlencoded',
headers: {
'Accept': 'application/json'
},
body: JSON.stringify(data)
}).then((response) => {
return response.json();
}).then((json) => {
if (json.status === 'success') {
resolve(json.data);
}
else {
reject(json.msg);
}
}).catch(reject);
});
}
*/

View File

@ -3,3 +3,10 @@ export function sleep(time) {
setTimeout(resolve, time); setTimeout(resolve, time);
}); });
} }
export function parseFetch(response) {
return response.json().then(({ status, data, msg }) => {
if (status !== 'success') throw new Error(msg);
return data;
});
}

159423
test.gcode Normal file

File diff suppressed because it is too large Load Diff

54
webpack.config.js Normal file
View File

@ -0,0 +1,54 @@
const path = require('path');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const HTMLWebpackPlugin = require('html-webpack-plugin');
const babelLoader = {
loader: 'babel-loader',
options: {
presets: [
require('babel-preset-env'),
require('babel-preset-react')
],
plugins: [
require('babel-plugin-transform-object-rest-spread'),
require('babel-plugin-transform-class-properties'),
require('babel-plugin-transform-runtime')
],
babelrc: false
}
};
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: babelLoader
}, { // make THREE global available to three.js examples
test: /three\/examples\/.+\.js/,
use: 'imports-loader?THREE=three'
}, {
test: /\.worker\.js$/,
use: ['worker-loader', babelLoader]
}
]
},
plugins: [
new HTMLWebpackPlugin({
title: 'Doodle3D API - Simple example',
template: require('html-webpack-template'),
inject: false,
appMountId: 'app'
}),
],
devtool: "source-map",
devServer: {
contentBase: 'dist'
}
};