diff --git a/extensions/markdown/.gitignore b/extensions/markdown/.gitignore index b3ad8e7973d..5c535300b86 100644 --- a/extensions/markdown/.gitignore +++ b/extensions/markdown/.gitignore @@ -1 +1 @@ -media/bundle.js \ No newline at end of file +media/*.js \ No newline at end of file diff --git a/extensions/markdown/media/csp.js b/extensions/markdown/preview-src/csp.ts similarity index 99% rename from extensions/markdown/media/csp.js rename to extensions/markdown/preview-src/csp.ts index 3604eb284db..a0891955ef1 100644 --- a/extensions/markdown/media/csp.js +++ b/extensions/markdown/preview-src/csp.ts @@ -3,8 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -'use strict'; - (function () { const settings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings')); const strings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-strings')); diff --git a/extensions/markdown/media/loading.js b/extensions/markdown/preview-src/loading.ts similarity index 78% rename from extensions/markdown/media/loading.js rename to extensions/markdown/preview-src/loading.ts index 233422e1414..88d1c55f589 100644 --- a/extensions/markdown/media/loading.js +++ b/extensions/markdown/preview-src/loading.ts @@ -2,27 +2,23 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// @ts-check - -'use strict'; - (function () { - const unloadedStyles = []; + const unloadedStyles: string[] = []; - const settings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings')); + const settings: any = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings')); - const onStyleLoadError = (event) => { + const onStyleLoadError = (event: any) => { const source = event.target.dataset.source; unloadedStyles.push(source); }; window.addEventListener('DOMContentLoaded', () => { - for (const link of document.getElementsByClassName('code-user-style')) { + for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf) { if (link.dataset.source) { link.onerror = onStyleLoadError; } } - }) + }); window.addEventListener('load', () => { if (!unloadedStyles.length) { @@ -37,4 +33,4 @@ } }, '*'); }); -}()); \ No newline at end of file +})(); \ No newline at end of file diff --git a/extensions/markdown/preview-src/pre.ts b/extensions/markdown/preview-src/pre.ts new file mode 100644 index 00000000000..abdd52a0a83 --- /dev/null +++ b/extensions/markdown/preview-src/pre.ts @@ -0,0 +1,7 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import './csp'; +import './loading'; \ No newline at end of file diff --git a/extensions/markdown/src/features/previewContentProvider.ts b/extensions/markdown/src/features/previewContentProvider.ts index b466d04b04f..65f07e2cb24 100644 --- a/extensions/markdown/src/features/previewContentProvider.ts +++ b/extensions/markdown/src/features/previewContentProvider.ts @@ -83,8 +83,7 @@ export class MarkdownContentProvider { ${csp} - - + ${this.getStyles(sourceUri, nonce, config)} @@ -165,7 +164,7 @@ export class MarkdownContentProvider { } private getScripts(nonce: string): string { - const scripts = [this.extensionResourcePath('bundle.js')].concat(this.extraScripts.map(resource => resource.toString())); + const scripts = [this.extensionResourcePath('index.js')].concat(this.extraScripts.map(resource => resource.toString())); return scripts .map(source => ``) .join('\n'); diff --git a/extensions/markdown/webpack.config.js b/extensions/markdown/webpack.config.js index 3eccbdadcc7..58996c3eb7d 100644 --- a/extensions/markdown/webpack.config.js +++ b/extensions/markdown/webpack.config.js @@ -5,7 +5,10 @@ const path = require('path'); module.exports = { - entry: './preview-src/index.ts', + entry: { + index: './preview-src/index.ts', + pre: './preview-src/pre.ts' + }, module: { rules: [ { @@ -20,7 +23,7 @@ module.exports = { }, devtool: 'inline-source-map', output: { - filename: 'bundle.js', + filename: '[name].js', path: path.resolve(__dirname, 'media') } }; \ No newline at end of file