webpack.config.npm.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. },
  92. output: {
  93. path: `${DIST_DIR}/lib/components`,
  94. library: '[name]',
  95. libraryExport: 'default',
  96. libraryTarget: 'umd'
  97. },
  98. plugins: [
  99. new VueLoaderPlugin(),
  100. new CopyWebpackPlugin({
  101. patterns: [
  102. {
  103. from: `${JS_ROOT}/apps/editor/components/QueryEditorWebComponents.d.ts`,
  104. to: `${DIST_DIR}/lib/components`
  105. }
  106. ]
  107. })
  108. ]
  109. });
  110. const parserConfig = Object.assign({}, defaultConfig, {
  111. entry: {
  112. calciteAutocompleteParser: [`${JS_ROOT}/parse/sql/calcite/calciteAutocompleteParser.js`],
  113. calciteSyntaxParser: [`${JS_ROOT}/parse/sql/calcite/calciteSyntaxParser.js`],
  114. druidAutocompleteParser: [`${JS_ROOT}/parse/sql/druid/druidAutocompleteParser.js`],
  115. druidSyntaxParser: [`${JS_ROOT}/parse/sql/druid/druidSyntaxParser.js`],
  116. elasticsearchAutocompleteParser: [
  117. `${JS_ROOT}/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js`
  118. ],
  119. elasticsearchSyntaxParser: [`${JS_ROOT}/parse/sql/elasticsearch/elasticsearchSyntaxParser.js`],
  120. flinkAutocompleteParser: [`${JS_ROOT}/parse/sql/flink/flinkAutocompleteParser.js`],
  121. flinkSyntaxParser: [`${JS_ROOT}/parse/sql/flink/flinkSyntaxParser.js`],
  122. genericAutocompleteParser: [`${JS_ROOT}/parse/sql/generic/genericAutocompleteParser.js`],
  123. genericSyntaxParser: [`${JS_ROOT}/parse/sql/generic/genericSyntaxParser.js`],
  124. hiveAutocompleteParser: [`${JS_ROOT}/parse/sql/hive/hiveAutocompleteParser.js`],
  125. hiveSyntaxParser: [`${JS_ROOT}/parse/sql/hive/hiveSyntaxParser.js`],
  126. impalaAutocompleteParser: [`${JS_ROOT}/parse/sql/impala/impalaAutocompleteParser.js`],
  127. impalaSyntaxParser: [`${JS_ROOT}/parse/sql/impala/impalaSyntaxParser.js`],
  128. ksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/ksql/ksqlAutocompleteParser.js`],
  129. ksqlSyntaxParser: [`${JS_ROOT}/parse/sql/ksql/ksqlSyntaxParser.js`],
  130. phoenixAutocompleteParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixAutocompleteParser.js`],
  131. phoenixSyntaxParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixSyntaxParser.js`],
  132. prestoAutocompleteParser: [`${JS_ROOT}/parse/sql/presto/prestoAutocompleteParser.js`],
  133. prestoSyntaxParser: [`${JS_ROOT}/parse/sql/presto/prestoSyntaxParser.js`],
  134. dasksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlAutocompleteParser.js`],
  135. dasksqlSyntaxParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlSyntaxParser.js`]
  136. },
  137. performance: {
  138. hints: false,
  139. maxEntrypointSize: 1500000,
  140. maxAssetSize: 1500000
  141. },
  142. output: {
  143. path: `${DIST_DIR}/lib/parsers`,
  144. library: '[name]',
  145. libraryExport: 'default',
  146. libraryTarget: 'umd',
  147. umdNamedDefine: true,
  148. globalObject: `(typeof self !== 'undefined' ? self : this)`
  149. }
  150. });
  151. const vue3WebCompWrapperConfig = Object.assign({}, defaultConfig, {
  152. entry: {
  153. index: [`${JS_ROOT}/vue/wrapper/index.ts`]
  154. },
  155. output: {
  156. path: `${WRAPPER_DIR}/dist`,
  157. library: '[name]',
  158. libraryExport: 'default',
  159. libraryTarget: 'umd',
  160. umdNamedDefine: true,
  161. globalObject: `(typeof self !== 'undefined' ? self : this)`
  162. },
  163. plugins: [
  164. new CleanWebpackPlugin([`${WRAPPER_DIR}/src`, `${WRAPPER_DIR}/dist`]),
  165. new CopyWebpackPlugin({
  166. patterns: [{ from: `${JS_ROOT}/vue/wrapper/`, to: `${WRAPPER_DIR}/src` }]
  167. })
  168. ]
  169. });
  170. module.exports = [
  171. executorLibConfig,
  172. hueConfigLibConfig,
  173. webComponentsConfig,
  174. parserConfig,
  175. vue3WebCompWrapperConfig
  176. ];