webpack.config.npm.js 6.2 KB

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