mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
73 lines
2.1 KiB
Dart
73 lines
2.1 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
|
|
import '../base/common.dart';
|
|
import '../build_info.dart';
|
|
import '../features.dart';
|
|
import '../project.dart';
|
|
import '../runner/flutter_command.dart'
|
|
show DevelopmentArtifact, FlutterCommandResult;
|
|
import '../web/compile.dart';
|
|
import 'build.dart';
|
|
|
|
class BuildWebCommand extends BuildSubCommand {
|
|
BuildWebCommand() {
|
|
addTreeShakeIconsFlag();
|
|
usesTargetOption();
|
|
usesPubOption();
|
|
addBuildModeFlags(excludeDebug: true);
|
|
usesDartDefineOption();
|
|
argParser.addFlag('web-initialize-platform',
|
|
defaultsTo: true,
|
|
negatable: true,
|
|
hide: true,
|
|
help: 'Whether to automatically invoke webOnlyInitializePlatform.',
|
|
);
|
|
argParser.addFlag('csp',
|
|
defaultsTo: false,
|
|
negatable: false,
|
|
help: 'Disable dynamic generation of code in the generated output. '
|
|
'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).'
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
|
|
const <DevelopmentArtifact>{
|
|
DevelopmentArtifact.web,
|
|
};
|
|
|
|
@override
|
|
final String name = 'web';
|
|
|
|
@override
|
|
bool get hidden => !featureFlags.isWebEnabled;
|
|
|
|
@override
|
|
final String description = 'build a web application bundle.';
|
|
|
|
@override
|
|
Future<FlutterCommandResult> runCommand() async {
|
|
if (!featureFlags.isWebEnabled) {
|
|
throwToolExit('"build web" is not currently supported.');
|
|
}
|
|
final FlutterProject flutterProject = FlutterProject.current();
|
|
final String target = stringArg('target');
|
|
final BuildInfo buildInfo = getBuildInfo();
|
|
if (buildInfo.isDebug) {
|
|
throwToolExit('debug builds cannot be built directly for the web. Try using "flutter run"');
|
|
}
|
|
await buildWeb(
|
|
flutterProject,
|
|
target,
|
|
buildInfo,
|
|
boolArg('web-initialize-platform'),
|
|
boolArg('csp'),
|
|
);
|
|
return FlutterCommandResult.success();
|
|
}
|
|
}
|