-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added serve task as well as some interfaces for safer maintainability
- Loading branch information
1 parent
6c1c956
commit 60fb36a
Showing
7 changed files
with
88 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,60 @@ | ||
import {webpackCommonConfig, webpackOutputOptions} from '../models/webpack-build-config.ts'; | ||
import {webpackCommonConfig, webpackOutputOptions, IWebpackDevServerConfigurationOptions} from '../models/webpack-build-config.ts'; | ||
import {IServeTaskOptions} from '../commands/serve'; | ||
|
||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
|
||
webpackCommonConfig.entry.main.unshift("webpack-dev-server/client?http://localhost:8080/"); | ||
|
||
const Task = require('ember-cli/lib/models/task'); | ||
const webpack = require('webpack'); | ||
const WebpackDevServer = require('webpack-dev-server'); | ||
const webpackCompiler = webpack(webpackCommonConfig); | ||
const ProgressPlugin = require('webpack/lib/ProgressPlugin'); | ||
|
||
const server = new WebpackDevServer(webpackCompiler); | ||
|
||
|
||
let lastHash = null; | ||
|
||
module.exports = Task.extend({ | ||
run: (commandOptions: IServeTaskOptions) => { | ||
|
||
webpackCommonConfig.entry.main.unshift(`webpack-dev-server/client?http://localhost:${commandOptions.port}/`); | ||
const webpackCompiler = webpack(webpackCommonConfig); | ||
|
||
webpackCompiler.apply(new ProgressPlugin({ | ||
profile: true, | ||
colors: true | ||
})); | ||
|
||
const webpackDevServerConfiguration: IWebpackDevServerConfigurationOptions = { | ||
contentBase: path.resolve(process.cwd(), './src'), | ||
historyApiFallback: true, | ||
stats: { colors: true }, | ||
inline: true | ||
}; | ||
|
||
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration); | ||
const serveMessage:string = chalk.green(`\n*\n*\n NG Live Development Server is running on http://localhost:${commandOptions.port}.\n*\n*`); | ||
|
||
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); | ||
}); | ||
}) | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
server.listen(8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters