Unverified Commit 392e825b authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Use product define for flutter web and remove extra asset server (#34159)

parent d9179780
...@@ -608,6 +608,7 @@ Future<void> bootstrapDart2Js(BuildStep buildStep) async { ...@@ -608,6 +608,7 @@ Future<void> bootstrapDart2Js(BuildStep buildStep) async {
'-o', '-o',
'$jsOutputPath', '$jsOutputPath',
'--packages="$packageFile"', '--packages="$packageFile"',
'-Ddart.vm.product=true',
dartPath, dartPath,
]; ];
final Dart2JsBatchWorkerPool dart2js = await buildStep.fetchResource(dart2JsWorkerResource); final Dart2JsBatchWorkerPool dart2js = await buildStep.fetchResource(dart2JsWorkerResource);
......
...@@ -411,8 +411,7 @@ class RunCommand extends RunCommandBase { ...@@ -411,8 +411,7 @@ class RunCommand extends RunCommandBase {
// in a "hot mode". // in a "hot mode".
final bool webMode = !FlutterVersion.instance.isStable final bool webMode = !FlutterVersion.instance.isStable
&& devices.length == 1 && devices.length == 1
&& await devices.single.targetPlatform == TargetPlatform.web_javascript && await devices.single.targetPlatform == TargetPlatform.web_javascript;
&& hotMode;
ResidentRunner runner; ResidentRunner runner;
final String applicationBinaryPath = argResults['use-application-binary']; final String applicationBinaryPath = argResults['use-application-binary'];
...@@ -438,6 +437,7 @@ class RunCommand extends RunCommandBase { ...@@ -438,6 +437,7 @@ class RunCommand extends RunCommandBase {
target: targetFile, target: targetFile,
flutterProject: flutterProject, flutterProject: flutterProject,
ipv6: ipv6, ipv6: ipv6,
debuggingOptions: _createDebuggingOptions(),
); );
} else { } else {
runner = ColdRunner( runner = ColdRunner(
......
...@@ -32,15 +32,14 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -32,15 +32,14 @@ class ResidentWebRunner extends ResidentRunner {
String target, String target,
@required this.flutterProject, @required this.flutterProject,
@required bool ipv6, @required bool ipv6,
@required DebuggingOptions debuggingOptions,
}) : super( }) : super(
flutterDevices, flutterDevices,
target: target, target: target,
usesTerminalUI: true, usesTerminalUI: true,
stayResident: true, stayResident: true,
saveCompilationTrace: false, saveCompilationTrace: false,
debuggingOptions: DebuggingOptions.enabled( debuggingOptions: debuggingOptions,
const BuildInfo(BuildMode.debug, ''),
),
ipv6: ipv6, ipv6: ipv6,
); );
...@@ -134,8 +133,7 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -134,8 +133,7 @@ class ResidentWebRunner extends ResidentRunner {
if (build != 0) { if (build != 0) {
throwToolExit('Error: Failed to build asset bundle'); throwToolExit('Error: Failed to build asset bundle');
} }
await writeBundle( await writeBundle(fs.directory(getAssetBuildDirectory()), assetBundle.entries);
fs.directory(getAssetBuildDirectory()), assetBundle.entries);
// Step 2: Start an HTTP server // Step 2: Start an HTTP server
_server = WebAssetServer(flutterProject, target, ipv6); _server = WebAssetServer(flutterProject, target, ipv6);
......
...@@ -11,9 +11,7 @@ import '../base/platform.dart'; ...@@ -11,9 +11,7 @@ import '../base/platform.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../device.dart'; import '../device.dart';
import '../globals.dart';
import '../project.dart'; import '../project.dart';
import '../web/compile.dart';
import '../web/workflow.dart'; import '../web/workflow.dart';
import 'chrome.dart'; import 'chrome.dart';
...@@ -32,9 +30,6 @@ class WebApplicationPackage extends ApplicationPackage { ...@@ -32,9 +30,6 @@ class WebApplicationPackage extends ApplicationPackage {
class WebDevice extends Device { class WebDevice extends Device {
WebDevice() : super('web'); WebDevice() : super('web');
HttpServer _server;
WebApplicationPackage _package;
@override @override
bool get supportsHotReload => true; bool get supportsHotReload => true;
...@@ -120,26 +115,13 @@ class WebDevice extends Device { ...@@ -120,26 +115,13 @@ class WebDevice extends Device {
bool usesTerminalUi = true, bool usesTerminalUi = true,
bool ipv6 = false, bool ipv6 = false,
}) async { }) async {
await buildWeb( // See [ResidentWebRunner.run] in flutter_tools/lib/src/resident_web_runner.dart
package.flutterProject, // for the web initialization and server logic.
fs.path.relative(mainPath, from: package.flutterProject.directory.path),
debuggingOptions.buildInfo,
);
_package = package;
_server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
_server.listen(_basicAssetServer);
printStatus('Serving assets from http:localhost:${_server.port}');
await chromeLauncher.launch('http://localhost:${_server.port}');
return LaunchResult.succeeded(observatoryUri: null); return LaunchResult.succeeded(observatoryUri: null);
} }
// Note: we don't currently have a way to track which chrome processes
// belong to the flutter tool, so we'll err on the side of caution by
// keeping these open.
@override @override
Future<bool> stopApp(ApplicationPackage app) async { Future<bool> stopApp(ApplicationPackage app) async {
await _server?.close();
_server = null;
return true; return true;
} }
...@@ -149,39 +131,6 @@ class WebDevice extends Device { ...@@ -149,39 +131,6 @@ class WebDevice extends Device {
@override @override
Future<bool> uninstallApp(ApplicationPackage app) async => true; Future<bool> uninstallApp(ApplicationPackage app) async => true;
Future<void> _basicAssetServer(HttpRequest request) async {
if (request.method != 'GET') {
request.response.statusCode = HttpStatus.forbidden;
await request.response.close();
return;
}
// Resolve all get requests to the build/web/ or build/flutter_assets directory.
final Uri uri = request.uri;
File file;
String contentType;
if (uri.path == '/') {
file = _package.webSourcePath.childFile('index.html');
contentType = 'text/html';
} else if (uri.path == '/main.dart.js') {
file = fs.file(fs.path.join(getWebBuildDirectory(), 'main.dart.js'));
contentType = 'text/javascript';
} else {
file = fs.file(fs.path.join(getAssetBuildDirectory(), uri.path.replaceFirst('/assets/', '')));
}
if (!file.existsSync()) {
request.response.statusCode = HttpStatus.notFound;
await request.response.close();
return;
}
request.response.statusCode = HttpStatus.ok;
if (contentType != null) {
request.response.headers.add(HttpHeaders.contentTypeHeader, contentType);
}
await request.response.addStream(file.openRead());
await request.response.close();
}
@override @override
bool isSupportedForProject(FlutterProject flutterProject) { bool isSupportedForProject(FlutterProject flutterProject) {
return flutterProject.web.existsSync(); return flutterProject.web.existsSync();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment