Skip to content

Optimize build #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix error on esbuild bundle
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Nov 28, 2021
commit 3222de678371cb8ecdeb495e75bb1caff9a3c61e
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"coderoad",
"esbuild",
"flowtype",
"fsevents",
"outfile",
"packagejson",
"prismjs",
Expand Down
2 changes: 1 addition & 1 deletion src/services/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WORKSPACE_ROOT } from '../../environment'

const asyncExec = promisify(cpExec)
const asyncRemoveFile = promisify(fs.unlink)
const asyncReadFile = promisify(fs.readFile)
export const asyncReadFile = promisify(fs.readFile)
const asyncWriteFile = promisify(fs.writeFile)

interface ExecParams {
Expand Down
14 changes: 13 additions & 1 deletion src/services/webview/render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JSDOM } from 'jsdom'
import * as path from 'path'
import * as vscode from 'vscode'
import { asyncReadFile } from '../node'
import { onError } from '../telemetry'
import { CONTENT_SECURITY_POLICY_EXEMPTIONS } from '../../environment'

Expand Down Expand Up @@ -64,7 +65,18 @@ async function render(panel: vscode.WebviewPanel, rootPath: string): Promise<voi
const runTimeScript = document.createElement('script')
runTimeScript.nonce = getNonce()
nonces.push(runTimeScript.nonce)
const manifest = await import(path.join(rootPath, 'asset-manifest.json'))

// note: file cannot be imported or results in esbuild error. Easier to read it.
let manifest
try {
const manifestPath = path.join(rootPath, 'asset-manifest.json')
console.log(manifestPath)
const manifestFile = await asyncReadFile(manifestPath, 'utf8')
manifest = JSON.parse(manifestFile)
} catch (e) {
throw new Error('Failed to read manifest file')
}

runTimeScript.src = createUri(manifest.files['runtime-main.js'])
document.body.appendChild(runTimeScript)

Expand Down