-
Notifications
You must be signed in to change notification settings - Fork 370
/
webpack.config.npm.js
207 lines (185 loc) · 6.96 KB
/
webpack.config.npm.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* Licensed to Cloudera, Inc. under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Cloudera, Inc. licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const fs = require('fs');
const { VueLoaderPlugin } = require('vue-loader');
const DIST_DIR = path.join(__dirname, 'npm_dist');
const JS_ROOT = path.join(__dirname, '/desktop/core/src/desktop/js');
const WRAPPER_DIR = `${__dirname}/tools/vue3-webcomponent-wrapper`;
const defaultConfig = Object.assign({}, require('./webpack.config'), {
mode: 'production',
optimization: {
minimize: true
},
plugins: []
});
const rootFiles = new Set();
fs.readdirSync(JS_ROOT).forEach(file => {
rootFiles.add(file.replace(/\..+$/, ''));
});
const relatives = ['./'];
let current = '';
for (let i = 1; i < 50; i++) {
current += '../';
relatives.push(current);
}
const copySourceConfig = {
mode: 'production',
entry: {
pjson: './package.json'
},
output: {
path: `${DIST_DIR}`
},
optimization: {
minimize: false,
usedExports: true
},
plugins: [
new CleanWebpackPlugin({ cleanOnceBeforeBuildPatterns: [DIST_DIR] }),
new CopyWebpackPlugin({
patterns: [
{ from: './NPM-README.md', to: `${DIST_DIR}/README.md` },
{
from: './package.json',
to: `${DIST_DIR}/package.json`,
transform: content => {
// Remove local dependencies (currently only cuix) since it is not needed
// and cannot be accessed by the npm registry.
const contentStr = content.toString();
const contentObj = JSON.parse(contentStr);
// Iterate over the dependencies and remove local references
Object.keys(contentObj.dependencies || {}).forEach(key => {
const value = contentObj.dependencies[key];
if (value.startsWith('file:')) {
delete contentObj.dependencies[key];
}
});
return JSON.stringify(contentObj, null, 2);
}
},
{
from: JS_ROOT,
to: `${DIST_DIR}`,
transform: (content, absoluteFrom) => {
// This turns all absolute imports to relative (except for npm dependencies) and solves module
// resolution issues when the Hue source files are used directly from another project.
if (/\.(jsx?|tsx?|vue)$/.test(absoluteFrom)) {
const depth = absoluteFrom.slice(JS_ROOT.length + 1).split('/').length - 1;
return content
.toString()
.replace(
/(import\s(?:[\S\s]+?\sfrom\s[^'"]*)?['"])([^.][^'"/]*)([/])/gi,
(all, pre, module, post) =>
`${pre}${rootFiles.has(module) ? relatives[depth] : ''}${module}${post}`
);
}
return content;
}
}
]
})
]
};
const webComponentsConfig = Object.assign({}, defaultConfig, {
entry: {
ErDiagram: [`${JS_ROOT}/components/er-diagram/webcomp.ts`],
QueryEditorWebComponents: [`${JS_ROOT}/webComponents/QueryEditorComponents.ts`],
SqlScratchpadWebComponent: [`${JS_ROOT}/webComponents/SqlScratchpad.ts`]
},
output: {
path: `${DIST_DIR}/lib/components`,
library: '[name]',
libraryExport: 'default',
libraryTarget: 'umd'
},
plugins: [
new VueLoaderPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: `${JS_ROOT}/webComponents/QueryEditorComponents.d.ts`,
to: `${DIST_DIR}/lib/components`
},
{
from: `${JS_ROOT}/webComponents/SqlScratchpad.d.ts`,
to: `${DIST_DIR}/lib/components`
}
]
})
]
});
const parserConfig = Object.assign({}, defaultConfig, {
entry: {
calciteAutocompleteParser: [`${JS_ROOT}/parse/sql/calcite/calciteAutocompleteParser.js`],
calciteSyntaxParser: [`${JS_ROOT}/parse/sql/calcite/calciteSyntaxParser.js`],
flinkAutocompleteParser: [`${JS_ROOT}/parse/sql/flink/flinkAutocompleteParser.js`],
flinkSyntaxParser: [`${JS_ROOT}/parse/sql/flink/flinkSyntaxParser.js`],
genericAutocompleteParser: [`${JS_ROOT}/parse/sql/generic/genericAutocompleteParser.js`],
genericSyntaxParser: [`${JS_ROOT}/parse/sql/generic/genericSyntaxParser.js`],
hiveAutocompleteParser: [`${JS_ROOT}/parse/sql/hive/hiveAutocompleteParser.js`],
hiveSyntaxParser: [`${JS_ROOT}/parse/sql/hive/hiveSyntaxParser.js`],
impalaAutocompleteParser: [`${JS_ROOT}/parse/sql/impala/impalaAutocompleteParser.js`],
impalaSyntaxParser: [`${JS_ROOT}/parse/sql/impala/impalaSyntaxParser.js`],
ksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/ksql/ksqlAutocompleteParser.js`],
ksqlSyntaxParser: [`${JS_ROOT}/parse/sql/ksql/ksqlSyntaxParser.js`],
phoenixAutocompleteParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixAutocompleteParser.js`],
phoenixSyntaxParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixSyntaxParser.js`],
prestoAutocompleteParser: [`${JS_ROOT}/parse/sql/presto/prestoAutocompleteParser.js`],
prestoSyntaxParser: [`${JS_ROOT}/parse/sql/presto/prestoSyntaxParser.js`],
dasksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlAutocompleteParser.js`],
dasksqlSyntaxParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlSyntaxParser.js`]
},
performance: {
hints: false,
maxEntrypointSize: 1500000,
maxAssetSize: 1500000
},
output: {
path: `${DIST_DIR}/lib/parsers`,
library: '[name]',
libraryExport: 'default',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: `(typeof self !== 'undefined' ? self : this)`
}
});
const vue3WebCompWrapperConfig = Object.assign({}, defaultConfig, {
entry: {
index: [`${JS_ROOT}/vue/wrapper/index.ts`]
},
output: {
path: `${WRAPPER_DIR}/dist`,
library: '[name]',
libraryExport: 'default',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: `(typeof self !== 'undefined' ? self : this)`
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [`${WRAPPER_DIR}/src`, `${WRAPPER_DIR}/dist`]
}),
new CopyWebpackPlugin({
patterns: [{ from: `${JS_ROOT}/vue/wrapper/`, to: `${WRAPPER_DIR}/src` }]
})
]
});
module.exports = [copySourceConfig, webComponentsConfig, parserConfig, vue3WebCompWrapperConfig];