Skip to content

Commit d10f529

Browse files
browser: Initial structure for browser support
- In the VS Code Launch panel we can run the extension in a browser context - It will run the code with src/extensionWeb.ts being the entrypoint - Webpack is configured to bundle the browser code Signed-off-by: Nikolas Komonen <[email protected]>
1 parent 9583022 commit d10f529

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

.vscode/launch.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@
145145
"program": "${workspaceFolder}/scripts/lint/testLint.ts",
146146
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
147147
"preLaunchTask": "${defaultBuildTask}"
148+
},
149+
{
150+
"name": "Run Web Extension ",
151+
"type": "pwa-extensionHost",
152+
"debugWebWorkerHost": true,
153+
"request": "launch",
154+
"args": ["--extensionDevelopmentPath=${workspaceFolder}", "--extensionDevelopmentKind=web"],
155+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
156+
"preLaunchTask": "${defaultBuildTask}"
148157
}
149158
],
150159
"compounds": [

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"onCommand:aws.codeWhisperer.accept"
5353
],
5454
"main": "./dist/src/main",
55+
"browser": "./dist/src/extensionWeb",
5556
"contributes": {
5657
"configuration": {
5758
"type": "object",

src/extensionWeb.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as vscode from 'vscode'
7+
8+
export async function activate(context: vscode.ExtensionContext) {
9+
vscode.window.showInformationMessage(
10+
'AWS Toolkit: Browser Mode Under Development. No features are currently provided',
11+
{ modal: true }
12+
)
13+
}
14+
15+
export async function deactivate() {}

webpack.config.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8'))
1919
const packageId = `${packageJson.publisher}.${packageJson.name}`
2020
const { VueLoaderPlugin } = require('vue-loader')
2121

22-
/**@type {import('webpack').Configuration}*/
22+
//@ts-check
23+
/** @typedef {import('webpack').Configuration} WebpackConfig **/
24+
25+
/** @type WebpackConfig */
2326
const baseConfig = {
2427
name: 'main',
2528
target: 'node',
@@ -91,6 +94,21 @@ const baseConfig = {
9194
},
9295
}
9396

97+
/** @type WebpackConfig */
98+
const webConfig = {
99+
...baseConfig,
100+
name: 'web',
101+
target: 'webworker',
102+
entry: {
103+
'src/extensionWeb': './src/extensionWeb.ts',
104+
},
105+
plugins: baseConfig.plugins?.concat(
106+
new webpack.optimize.LimitChunkCountPlugin({
107+
maxChunks: 1, // disable chunks by default since web extensions must be a single bundle
108+
})
109+
),
110+
}
111+
94112
/**
95113
* Renames all Vue entry files to be `index`, located within the same directory.
96114
* Example: `src/lambda/vue/index.ts` -> `dist/src/lambda/vue/index.js`
@@ -111,6 +129,7 @@ const createVueEntries = (targetPattern = 'index.ts') => {
111129
.reduce((a, b) => ((a[b.name] = b.path), a), {})
112130
}
113131

132+
/** @type WebpackConfig */
114133
const vueConfig = {
115134
...baseConfig,
116135
name: 'vue',
@@ -135,6 +154,7 @@ const vueConfig = {
135154
plugins: baseConfig.plugins.concat(new VueLoaderPlugin()),
136155
}
137156

157+
/** @type WebpackConfig */
138158
const vueHotReload = {
139159
...vueConfig,
140160
name: 'vue-hmr',
@@ -153,4 +173,6 @@ const vueHotReload = {
153173
}
154174

155175
module.exports =
156-
process.env.npm_lifecycle_event === 'serve' ? [baseConfig, vueConfig, vueHotReload] : [baseConfig, vueConfig]
176+
process.env.npm_lifecycle_event === 'serve'
177+
? [baseConfig, webConfig, vueConfig, vueHotReload]
178+
: [baseConfig, webConfig, vueConfig]

0 commit comments

Comments
 (0)