forked from ml5js/ml5-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.test.babel.js
53 lines (47 loc) · 1.7 KB
/
webpack.test.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-disable import/no-extraneous-dependencies */
// Copyright (c) 2019 ml5
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import { existsSync, mkdirSync, writeFileSync, lstatSync } from 'fs';
import { join } from 'path';
import assert from 'assert';
import merge from 'webpack-merge';
import common, {developmentPort} from './webpack.common.babel';
// this is the function to initialize manual-test folder when running `npm run start`
(function checkExperimentsFolder() {
const experimentsDir = join(__dirname, './manual-test');
const indexFile = join(experimentsDir, './index.html');
// create manual-test dir if not exist, or check if it is a readable dir.
if (!existsSync(experimentsDir)) mkdirSync(experimentsDir);
else {
assert(lstatSync(experimentsDir).isDirectory(), "./manual-test should be a readable folder.");
}
// create index.html in manual-test dir if not exist, or check if it is a readable file.
if (!existsSync(indexFile)) {
writeFileSync(indexFile, `
<!DOCTYPE html>
<html>
<head>
<title>ml5.js manual test</title>
<script src="http://localhost:${developmentPort}/ml5.js"></script>
</head>
<body>
<script>
// Your scripts would be written here
</script>
</body>
</html>`.replace(/ {6}/g, '').trimLeft());
} else {
assert(lstatSync(indexFile).isFile(), "./manual-test/index.html should be a readable file.");
}
})();
export default merge(common, {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
watchContentBase: true,
contentBase: [join(__dirname, './dist'), join(__dirname, './manual-test')]
},
plugins: []
});