start.js
2.5 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* React Starter Kit (http://www.reactstarterkit.com/)
*
* Copyright © 2014-2015 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
import browserSync from 'browser-sync';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfigs from './webpack.config.production';
import run from './run';
import path from 'path';
import copyIndex from './copy-index';
global.WATCH = true;
const webpackConfig = webpackConfigs[0]; // Client-side bundle configuration
const bundler = webpack(webpackConfig);
/**
* Launches a development web server with "live reload" functionality -
* synchronizing URLs, interactions and code changes across multiple devices.
*/
async function start() {
//await run(require('./build'));
copyIndex();
await run(require('./serve'));
await new Promise(resolve => {
browserSync({
port:3005,
proxy: {
target: 'localhost:3000',
// baseDir: "../build/public/",
middleware: [
webpackDevMiddleware(bundler, {
// IMPORTANT: dev middleware can't access config, so we should
// provide publicPath by ourselves
publicPath: webpackConfig.output.publicPath,
// Pretty colored output
stats: webpackConfig.stats,
// For other settings see
// http://webpack.github.io/docs/webpack-dev-middleware.html
}),
// bundler should be the same as above
webpackHotMiddleware(bundler),
],
// proxyRes: [
// function (res, req) {
// res.headers["Access-Control-Allow-Origin"] = "*";
// res.headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept";
// res.headers["Access-Control-Allow-Methods"] = "PUT,POST,GET,DELETE,OPTIONS";
// }
// ]
},
// no need to watch '*.js' here, webpack will take care of it for us,
// including full page reloads if HMR won't work
files: [
'../build/public/img/*.*',
'../build/public/fonts/*.*',
'../build/public/**/*.css',
'../build/public/js/**/*.*',
'../build/public/**/*.html',
'../build/content/**/*.*',
'../build/templates/**/*.*'
]
},resolve);
})
}
export default start;