Repository navigation
Expand file tree
/
Copy pathserve-webpack.ts
More file actions
68 lines (49 loc) · 2.22 KB
/
Copy pathserve-webpack.ts
File metadata and controls
68 lines (49 loc) · 2.22 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
import {webpackDevServerOutputOptions} from '../models/';
import {NgCliWebpackConfig} from '../models/webpack-config';
import {ServeTaskOptions} from '../commands/serve';
import { CliConfig } from '../models/config';
const path = require('path');
const chalk = require('chalk');
const Task = require('ember-cli/lib/models/task');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
let lastHash = null;
module.exports = Task.extend({
run: function(commandOptions: ServeTaskOptions) {
let webpackCompiler: any;
var config: NgCliWebpackConfig = new NgCliWebpackConfig(this.project, commandOptions.environment).config;
// This allows for live reload of page when changes are made to repo.
// https://webpack.github.io/docs/webpack-dev-server.html#inline-mode
config.entry.main.unshift(`webpack-dev-server/client?http://localhost:${commandOptions.port}/`);
webpackCompiler = webpack(config);
webpackCompiler.apply(new ProgressPlugin({
profile: true,
colors: true
}));
const webpackDevServerConfiguration: IWebpackDevServerConfigurationOptions = {
contentBase: path.resolve(this.project.root, `./${CliConfig.fromProject().defaults.sourceDir}`),
historyApiFallback: true,
stats: webpackDevServerOutputOptions,
inline: true,
hot: true
};
const serveMessage:string = chalk.green(`\n*\n*\n NG Live Development Server is running on http://localhost:${commandOptions.port}.\n*\n*`);
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
return new Promise((resolve, reject) => {
server.listen(commandOptions.port, "localhost", function(err, stats) {
if(err) {
lastHash = null;
console.error(err.stack || err);
if(err.details) console.error(err.details);
reject(err.details);
}
if(stats && stats.hash && stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(webpackOutputOptions) + "\n" + serveMessage + "\n");
}
process.stdout.write(serveMessage);
});
})
}
});