webpack.config.npm.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**
  2. * Licensed to Cloudera, Inc. under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. Cloudera, Inc. licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. const CleanWebpackPlugin = require('clean-webpack-plugin');
  19. const CopyWebpackPlugin = require('copy-webpack-plugin');
  20. const path = require('path');
  21. const { VueLoaderPlugin } = require('vue-loader');
  22. const DIST_DIR = path.join(__dirname, 'npm_dist');
  23. const JS_ROOT = path.join(__dirname, '/desktop/core/src/desktop/js');
  24. const WRAPPER_DIR = `${__dirname}/tools/vue3-webcomponent-wrapper`;
  25. const defaultConfig = Object.assign({}, require('./webpack.config'), {
  26. mode: 'production',
  27. optimization: {
  28. minimize: true
  29. },
  30. plugins: []
  31. });
  32. const executorLibConfig = Object.assign({}, defaultConfig, {
  33. entry: {
  34. executor: [`${JS_ROOT}/apps/editor/execution/executor.ts`]
  35. },
  36. output: {
  37. path: `${DIST_DIR}/lib/execution`,
  38. library: '[name]',
  39. libraryExport: 'default',
  40. libraryTarget: 'umd',
  41. umdNamedDefine: true,
  42. globalObject: `(typeof self !== 'undefined' ? self : this)`
  43. },
  44. plugins: [
  45. new CleanWebpackPlugin([DIST_DIR]),
  46. new CopyWebpackPlugin({
  47. patterns: [
  48. { from: './package.json', to: `${DIST_DIR}/package.json` },
  49. { from: './NPM-README.md', to: `${DIST_DIR}/README.md` },
  50. { from: JS_ROOT, to: `${DIST_DIR}` },
  51. {
  52. from: `${JS_ROOT}/apps/editor/execution/executor.d.ts`,
  53. to: `${DIST_DIR}/lib/execution`
  54. }
  55. ]
  56. })
  57. ]
  58. });
  59. const hueConfigLibConfig = Object.assign({}, defaultConfig, {
  60. entry: {
  61. hueConfig: [`${JS_ROOT}/config/hueConfig.ts`],
  62. contextCatalog: [`${JS_ROOT}/catalog/contextCatalog.ts`]
  63. },
  64. output: {
  65. path: `${DIST_DIR}/lib/config`,
  66. library: '[name]',
  67. libraryExport: 'default',
  68. libraryTarget: 'umd',
  69. umdNamedDefine: true,
  70. globalObject: `(typeof self !== 'undefined' ? self : this)`
  71. },
  72. plugins: [
  73. new CopyWebpackPlugin({
  74. patterns: [
  75. {
  76. from: `${JS_ROOT}/config/hueConfig.d.ts`,
  77. to: `${DIST_DIR}/lib/config`
  78. },
  79. {
  80. from: `${JS_ROOT}/catalog/contextCatalog.d.ts`,
  81. to: `${DIST_DIR}/lib/config`
  82. }
  83. ]
  84. })
  85. ]
  86. });
  87. const webComponentsConfig = Object.assign({}, defaultConfig, {
  88. entry: {
  89. ErDiagram: [`${JS_ROOT}/components/er-diagram/webcomp.ts`],
  90. QueryEditorWebComponents: [`${JS_ROOT}/apps/editor/components/QueryEditorWebComponents.ts`],
  91. SqlScratchpadWebComponent: [
  92. `${JS_ROOT}/apps/editor/components/sqlScratchpad/SqlScratchpadWebComponent.ts`
  93. ]
  94. },
  95. output: {
  96. path: `${DIST_DIR}/lib/components`,
  97. library: '[name]',
  98. libraryExport: 'default',
  99. libraryTarget: 'umd'
  100. },
  101. plugins: [
  102. new VueLoaderPlugin(),
  103. new CopyWebpackPlugin({
  104. patterns: [
  105. {
  106. from: `${JS_ROOT}/apps/editor/components/QueryEditorWebComponents.d.ts`,
  107. to: `${DIST_DIR}/lib/components`
  108. },
  109. {
  110. from: `${JS_ROOT}/apps/editor/components/sqlScratchpad/SqlScratchpadWebComponent.d.ts`,
  111. to: `${DIST_DIR}/lib/components`
  112. }
  113. ]
  114. })
  115. ]
  116. });
  117. const parserConfig = Object.assign({}, defaultConfig, {
  118. entry: {
  119. calciteAutocompleteParser: [`${JS_ROOT}/parse/sql/calcite/calciteAutocompleteParser.js`],
  120. calciteSyntaxParser: [`${JS_ROOT}/parse/sql/calcite/calciteSyntaxParser.js`],
  121. druidAutocompleteParser: [`${JS_ROOT}/parse/sql/druid/druidAutocompleteParser.js`],
  122. druidSyntaxParser: [`${JS_ROOT}/parse/sql/druid/druidSyntaxParser.js`],
  123. elasticsearchAutocompleteParser: [
  124. `${JS_ROOT}/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js`
  125. ],
  126. elasticsearchSyntaxParser: [`${JS_ROOT}/parse/sql/elasticsearch/elasticsearchSyntaxParser.js`],
  127. flinkAutocompleteParser: [`${JS_ROOT}/parse/sql/flink/flinkAutocompleteParser.js`],
  128. flinkSyntaxParser: [`${JS_ROOT}/parse/sql/flink/flinkSyntaxParser.js`],
  129. genericAutocompleteParser: [`${JS_ROOT}/parse/sql/generic/genericAutocompleteParser.js`],
  130. genericSyntaxParser: [`${JS_ROOT}/parse/sql/generic/genericSyntaxParser.js`],
  131. hiveAutocompleteParser: [`${JS_ROOT}/parse/sql/hive/hiveAutocompleteParser.js`],
  132. hiveSyntaxParser: [`${JS_ROOT}/parse/sql/hive/hiveSyntaxParser.js`],
  133. impalaAutocompleteParser: [`${JS_ROOT}/parse/sql/impala/impalaAutocompleteParser.js`],
  134. impalaSyntaxParser: [`${JS_ROOT}/parse/sql/impala/impalaSyntaxParser.js`],
  135. ksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/ksql/ksqlAutocompleteParser.js`],
  136. ksqlSyntaxParser: [`${JS_ROOT}/parse/sql/ksql/ksqlSyntaxParser.js`],
  137. phoenixAutocompleteParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixAutocompleteParser.js`],
  138. phoenixSyntaxParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixSyntaxParser.js`],
  139. prestoAutocompleteParser: [`${JS_ROOT}/parse/sql/presto/prestoAutocompleteParser.js`],
  140. prestoSyntaxParser: [`${JS_ROOT}/parse/sql/presto/prestoSyntaxParser.js`],
  141. dasksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlAutocompleteParser.js`],
  142. dasksqlSyntaxParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlSyntaxParser.js`]
  143. },
  144. performance: {
  145. hints: false,
  146. maxEntrypointSize: 1500000,
  147. maxAssetSize: 1500000
  148. },
  149. output: {
  150. path: `${DIST_DIR}/lib/parsers`,
  151. library: '[name]',
  152. libraryExport: 'default',
  153. libraryTarget: 'umd',
  154. umdNamedDefine: true,
  155. globalObject: `(typeof self !== 'undefined' ? self : this)`
  156. }
  157. });
  158. const vue3WebCompWrapperConfig = Object.assign({}, defaultConfig, {
  159. entry: {
  160. index: [`${JS_ROOT}/vue/wrapper/index.ts`]
  161. },
  162. output: {
  163. path: `${WRAPPER_DIR}/dist`,
  164. library: '[name]',
  165. libraryExport: 'default',
  166. libraryTarget: 'umd',
  167. umdNamedDefine: true,
  168. globalObject: `(typeof self !== 'undefined' ? self : this)`
  169. },
  170. plugins: [
  171. new CleanWebpackPlugin([`${WRAPPER_DIR}/src`, `${WRAPPER_DIR}/dist`]),
  172. new CopyWebpackPlugin({
  173. patterns: [{ from: `${JS_ROOT}/vue/wrapper/`, to: `${WRAPPER_DIR}/src` }]
  174. })
  175. ]
  176. });
  177. module.exports = [
  178. executorLibConfig,
  179. hueConfigLibConfig,
  180. webComponentsConfig,
  181. parserConfig,
  182. vue3WebCompWrapperConfig
  183. ];