forked from aws/aws-toolkit-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.vue.config.js
93 lines (84 loc) · 2.74 KB
/
webpack.vue.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//@ts-check
'use strict'
const path = require('path')
const glob = require('glob')
const { VueLoaderPlugin } = require('vue-loader')
const baseConfig = require('./webpack.base.config')
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/
/**
* Renames all Vue entry files to be `index`, located within the same directory.
* Example: `src/lambda/vue/index.ts` -> `dist/src/lambda/vue/index.js`
* @param {string} file
*/
const createVueBundleName = file => {
return path.relative(__dirname, file).split('.').slice(0, -1).join(path.sep)
}
/**
* Generates Vue entry points if the filename is matches `targetPattern` (default: index.ts)
* and is under a `vue` directory.
*/
const createVueEntries = (targetPattern = 'index.ts') => {
return glob
.sync(path.resolve(__dirname, 'src', '**', 'vue', '**', targetPattern))
.map(f => ({ name: createVueBundleName(f), path: f }))
.reduce((a, b) => ((a[b.name] = b.path), a), {})
}
/** @type WebpackConfig */
const vueConfig = {
...baseConfig,
name: 'vue',
target: 'web',
entry: {
...createVueEntries(),
'src/amazonq/webview/ui/amazonq-ui': './src/amazonq/webview/ui/main.ts',
},
output: {
...baseConfig.output,
libraryTarget: 'this',
},
module: {
rules: (baseConfig.module?.rules ?? []).concat(
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.css$/,
use: ['vue-style-loader', 'css-loader'],
},
{
test: /\.(png|jpg|gif|svg)$/,
use: 'file-loader',
},
// sass loaders for Mynah
{ test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] }
),
},
plugins: (baseConfig.plugins ?? []).concat(new VueLoaderPlugin()),
}
/** @type WebpackConfig */
const vueHotReload = {
...vueConfig,
name: 'vue-hmr',
devServer: {
static: {
directory: path.resolve(__dirname, 'dist'),
},
headers: {
'Access-Control-Allow-Origin': '*',
},
// This is not ideal, but since we're only running the server locally it's not too bad
// The webview debugger tries to establish a websocket with a GUID as its origin, so not much of a workaround
allowedHosts: 'all',
},
// Normally we want to exclude Vue from the bundle, but for hot reloads we need it
externals: {
vscode: 'commonjs vscode',
},
}
module.exports = process.env.npm_lifecycle_event === 'serve' ? [vueConfig, vueHotReload] : [vueConfig]