@@ -5,6 +5,84 @@ import * as path from 'path'
55import getNonce from './utils/nonce'
66import onReceive from './onReceive'
77
8+ const webpackScript = `!(function (l) {
9+ function e(e) {
10+ for (var r, t, n = e[0], o = e[1], u = e[2], f = 0, i = []; f < n.length; f++)
11+ (t = n[f]), p[t] && i.push(p[t][0]), (p[t] = 0)
12+ for (r in o) Object.prototype.hasOwnProperty.call(o, r) && (l[r] = o[r])
13+ for (s && s(e); i.length;) i.shift()()
14+ return c.push.apply(c, u || []), a()
15+ }
16+ function a() {
17+ for (var e, r = 0; r < c.length; r++) {
18+ for (var t = c[r], n = !0, o = 1; o < t.length; o++) {
19+ var u = t[o]
20+ 0 !== p[u] && (n = !1)
21+ }
22+ n && (c.splice(r--, 1), (e = f((f.s = t[0]))))
23+ }
24+ return e
25+ }
26+ var t = {},
27+ p = { 1: 0 },
28+ c = []
29+ function f(e) {
30+ if (t[e]) return t[e].exports
31+ var r = (t[e] = { i: e, l: !1, exports: {} })
32+ return l[e].call(r.exports, r, r.exports, f), (r.l = !0), r.exports
33+ }
34+ ; (f.m = l),
35+ (f.c = t),
36+ (f.d = function (e, r, t) {
37+ f.o(e, r) || Object.defineProperty(e, r, { enumerable: !0, get: t })
38+ }),
39+ (f.r = function (e) {
40+ 'undefined' != typeof Symbol &&
41+ Symbol.toStringTag &&
42+ Object.defineProperty(e, Symbol.toStringTag, { value: 'Module' }),
43+ Object.defineProperty(e, '__esModule', { value: !0 })
44+ }),
45+ (f.t = function (r, e) {
46+ if ((1 & e && (r = f(r)), 8 & e)) return r
47+ if (4 & e && 'object' == typeof r && r && r.__esModule) return r
48+ var t = Object.create(null)
49+ if (
50+ (f.r(t), Object.defineProperty(t, 'default', { enumerable: !0, value: r }), 2 & e && 'string' != typeof r)
51+ )
52+ for (var n in r)
53+ f.d(
54+ t,
55+ n,
56+ function (e) {
57+ return r[e]
58+ }.bind(null, n),
59+ )
60+ return t
61+ }),
62+ (f.n = function (e) {
63+ var r =
64+ e && e.__esModule
65+ ? function () {
66+ return e.default
67+ }
68+ : function () {
69+ return e
70+ }
71+ return f.d(r, 'a', r), r
72+ }),
73+ (f.o = function (e, r) {
74+ return Object.prototype.hasOwnProperty.call(e, r)
75+ }),
76+ (f.p = './')
77+ console.log('load window.wepbackJsonp')
78+ var r = (window.webpackJsonp = window.webpackJsonp || []),
79+ n = r.push.bind(r)
80+ ; (r.push = e), (r = r.slice())
81+ for (var o = 0; o < r.length; o++) e(r[o])
82+ var s = n
83+ a()
84+ })([])`
85+
886/**
987 * Manages React webview panels
1088 */
@@ -19,7 +97,7 @@ class ReactPanel {
1997private _disposables :vscode . Disposable [ ] = [ ]
2098
2199public static async createOrShow ( extensionPath :string ) :Promise < void > {
22- const hasActiveEditor = vscode . window . activeTextEditor
100+ // const hasActiveEditor = vscode.window.activeTextEditor
23101
24102// if (!hasActiveEditor) {
25103// throw new Error('Should have an open file on launch')
@@ -29,6 +107,7 @@ class ReactPanel {
29107// If we already have a panel, show it.
30108// Otherwise, create a new panel.
31109if ( ReactPanel . currentPanel ) {
110+ console . log ( '--- HAS CURRENT PANEL ---' )
32111ReactPanel . currentPanel . _panel . reveal ( column )
33112} else {
34113ReactPanel . currentPanel = new ReactPanel ( extensionPath , column )
@@ -89,39 +168,51 @@ class ReactPanel {
89168}
90169
91170private _getHtmlForWebview ( ) :string {
171+
92172// eslint-disable-next-line
93173const manifest = require ( path . join ( this . _extensionPath , 'build' , 'asset-manifest.json' ) )
94- const mainScript = manifest [ 'main.js' ]
95- const mainStyle = manifest [ 'main.css' ]
174+ const mainScript = manifest . files [ 'main.js' ]
175+ // grab first chunk
176+ const chunk = Object . keys ( manifest . files ) . filter ( f => f . match ( / ^ s t a t i c \/ j s \/ .+ \. j s $ / ) ) [ 0 ]
177+ const chunkScript = manifest . files [ chunk ]
178+ const mainStyle = manifest . files [ 'main.css' ]
96179
97180const scriptPathOnDisk = vscode . Uri . file ( path . join ( this . _extensionPath , 'build' , mainScript ) )
98181const scriptUri = scriptPathOnDisk . with ( { scheme :'vscode-resource' } )
182+ const chunkPathOnDisk = vscode . Uri . file ( path . join ( this . _extensionPath , 'build' , chunkScript ) )
183+ const chunkUri = chunkPathOnDisk . with ( { scheme :'vscode-resource' } )
99184const stylePathOnDisk = vscode . Uri . file ( path . join ( this . _extensionPath , 'build' , mainStyle ) )
100185const styleUri = stylePathOnDisk . with ( { scheme :'vscode-resource' } )
101186
102187// Use a nonce to whitelist which scripts can be run
103188const nonce = getNonce ( )
189+ const nonce2 = getNonce ( )
190+ const nonce3 = getNonce ( )
104191
105- return `<!DOCTYPE html>
192+ const output = `<!DOCTYPE html>
106193<html lang="en">
107194<head>
108195<meta charset="utf-8">
109196<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
110- <meta name="theme-color" content="#000000">
111- <title>React App</title>
197+ <meta name="theme-color" content="#000000">
198+ <title>React App</title>
199+ <link rel="manifest" href="./manifest.json" />
112200<link rel="stylesheet" type="text/css" href="${ styleUri } ">
113- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${ nonce } '; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
114- <base href="${ vscode . Uri . file ( path . join ( this . _extensionPath , 'build' ) ) . with ( { scheme :'vscode-resource' } ) } /">
115- <style></style>
201+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${ nonce } ' 'nonce- ${ nonce2 } ' 'nonce- ${ nonce3 } '; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
202+ <base href="${ vscode . Uri . file ( path . join ( this . _extensionPath , 'build' ) ) . with ( { scheme :'vscode-resource' } ) } /">
203+ <style></style>
116204</head>
117205
118206<body>
119207<noscript>You need to enable JavaScript to run this app.</noscript>
120- <div id="root">Loading...</div>
121-
122- <script nonce="${ nonce } " src="${ scriptUri } "></script>
208+ <div id="root">Loading...</div>
209+ <script nonce=${ nonce } >${ webpackScript } </script>
210+ <script nonce=${ nonce2 } src="${ chunkUri } "></script>
211+ <script nonce="${ nonce3 } " src="${ scriptUri } "></script>
123212</body>
124- </html>`
213+ </html>`
214+ console . log ( output )
215+ return output
125216}
126217}
127218