compileAsync static method

Future compileAsync(
  1. File sourceFile, {
  2. Directory? outDir,
  3. File? outFile,
  4. bool minify = false,
  5. bool csp = false,
  6. bool enableExperimentalMirrors = false,
  7. String? categories,
  8. List<String> extraArgs = const [],
})

Invoke a dart2js compile with the given sourceFile as input.

Implementation

static Future compileAsync(File sourceFile,
    {Directory? outDir,
    File? outFile,
    bool minify = false,
    bool csp = false,
    bool enableExperimentalMirrors = false,
    String? categories,
    List<String> extraArgs = const []}) {
  if (outFile == null) {
    outDir ??= sourceFile.parent;
    outFile = joinFile(outDir, ['${fileName(sourceFile)}.js']);
  } else {
    outDir = outFile.parent;
  }

  if (!outDir.existsSync()) outDir.createSync(recursive: true);

  return runlib
      .runAsync(sdkBin('dart'),
          arguments: _buildArgs(
              minify: minify,
              csp: csp,
              enableExperimentalMirrors: enableExperimentalMirrors,
              categories: categories,
              extraArgs: extraArgs,
              outFile: outFile,
              sourceFile: sourceFile))
      .then((_) => null);
}