-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathwebpack.config.js
More file actions
175 lines (168 loc) · 4.83 KB
/
webpack.config.js
File metadata and controls
175 lines (168 loc) · 4.83 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const { default: TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
const path = require('path');
const { ThemeLiquidDocsManager } = require('@shopify/theme-check-docs-updater');
/** @type WebpackConfig */
const baseConfig = {
context: path.resolve(__dirname),
devServer: {
port: 3000,
},
resolve: {
extensions: ['.ts', '.js'],
plugins: [new TsconfigPathsPlugin({})],
},
optimization: {
minimize: false,
},
module: {
parser: {
javascript: {
commonjsMagicComments: true,
},
},
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
projectReferences: true,
},
},
},
],
},
devtool: 'source-map',
node: {
__filename: 'eval-only', // this means that __filename will eval to the output file name
__dirname: 'eval-only', // this means that __dirname will eval to the dist folder
},
infrastructureLogging: {
level: 'log', // enables logging required for problem matchers
},
}
/** @type WebpackConfig */
const desktopConfig = {
...baseConfig,
target: 'node',
entry: {
extension: './src/node/extension.ts',
server: './src/node/server.ts',
},
output: {
path: path.resolve(__dirname, 'dist', 'node'),
filename: '[name].js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../../[resource-path]',
},
externals: {
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded
prettier: 'commonjs ./prettier',
},
plugins: [
new webpack.DefinePlugin({
// A flag that lets us do fun webpack-only shenanigans...
'process.env.WEBPACK_MODE': true,
}),
new CopyPlugin({
patterns: [
{
// The config/* yaml files need to be accessible from the VS Code
// extension. So we copy them into the dist/configs folder so that
// the __dirname eval can correctly load them. It's a bit hacky,
// buit it works :)
//
// This is also why we have __dirname as 'eval-only'.
from: path.resolve(__dirname, '../theme-check-node/configs'),
to: 'configs',
},
{
// Same deal but for the fallback docset and schema files.
from: path.resolve(__dirname, '../theme-check-docs-updater/data'),
to: 'data',
},
{
from: path.resolve(__dirname, '../../node_modules/prettier2'),
to: 'prettier',
globOptions: {
ignore: ['**/esm/**'],
},
},
],
}),
],
};
/** @type WebpackConfig */
const browserClientConfig = {
...baseConfig,
target: 'webworker',
entry: {
extension: './src/browser/extension.ts',
},
resolve: {
...baseConfig.resolve,
alias: {
prettier: path.resolve(__dirname, '../../node_modules/prettier2'),
},
},
output: {
path: path.resolve(__dirname, 'dist', 'browser'),
filename: '[name].js',
libraryTarget: 'commonjs',
devtoolModuleFilenameTemplate: '../../[resource-path]',
},
externals: {
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded
},
plugins: [
new webpack.DefinePlugin({
// A flag that lets us do fun webpack-only shenanigans...
'process.env.WEBPACK_MODE': true,
}),
],
};
const browserServerConfig = async () => {
const docsManager = new ThemeLiquidDocsManager();
const [tags, filters, objects, systemTranslations, schemas] = await Promise.all([
docsManager.tags(),
docsManager.filters(),
docsManager.objects(),
docsManager.systemTranslations(),
docsManager.schemas('theme'),
]);
return {
...baseConfig,
target: 'webworker',
entry: { server: './src/browser/server.ts', },
resolve: {
...baseConfig.resolve,
alias: {
prettier: path.resolve(__dirname, '../../node_modules/prettier2'),
},
},
output: {
path: path.resolve(__dirname, 'dist', 'browser'),
filename: '[name].js',
libraryTarget: 'var',
library: 'serverExportVar',
devtoolModuleFilenameTemplate: '../../[resource-path]',
},
plugins: [
new webpack.DefinePlugin({
// A flag that lets us do fun webpack-only shenanigans...
'process.env.WEBPACK_MODE': true,
WEBPACK_TAGS: JSON.stringify(tags),
WEBPACK_FILTERS: JSON.stringify(filters),
WEBPACK_OBJECTS: JSON.stringify(objects),
WEBPACK_SYSTEM_TRANSLATIONS: JSON.stringify(systemTranslations),
WEBPACK_SCHEMAS: JSON.stringify(schemas),
}),
],
};
};
module.exports = [desktopConfig, browserClientConfig, browserServerConfig];