webpack.config.npm.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 defaultConfig = Object.assign({}, require('./webpack.config'), {
  25. mode: 'production',
  26. optimization: {
  27. minimize: true
  28. },
  29. plugins: []
  30. });
  31. const libConfig = Object.assign({}, defaultConfig, {
  32. entry: {
  33. executor: [`${JS_ROOT}/apps/editor/execution/executor.ts`]
  34. },
  35. output: {
  36. path: `${DIST_DIR}/lib/execution`,
  37. library: '[name]',
  38. libraryExport: 'default',
  39. libraryTarget: 'umd',
  40. umdNamedDefine: true,
  41. globalObject: `(typeof self !== 'undefined' ? self : this)`
  42. },
  43. plugins: [
  44. new CleanWebpackPlugin([DIST_DIR]),
  45. new CopyWebpackPlugin({
  46. patterns: [
  47. { from: './package.json', to: `${DIST_DIR}/package.json` },
  48. { from: './NPM-README.md', to: `${DIST_DIR}/README.md` },
  49. { from: JS_ROOT, to: `${DIST_DIR}/src` },
  50. {
  51. from: `${JS_ROOT}/apps/editor/execution/executor.d.ts`,
  52. to: `${DIST_DIR}/lib/execution`
  53. }
  54. ]
  55. })
  56. ]
  57. });
  58. const webComponentsConfig = Object.assign({}, defaultConfig, {
  59. entry: {
  60. ErDiagram: [`${JS_ROOT}/components/er-diagram/webcomp.ts`],
  61. QueryEditorWebComponents: [`${JS_ROOT}/apps/editor/components/QueryEditorWebComponents.ts`]
  62. },
  63. output: {
  64. path: `${DIST_DIR}/lib/components`,
  65. library: '[name]',
  66. libraryExport: 'default',
  67. libraryTarget: 'umd'
  68. },
  69. plugins: [
  70. new VueLoaderPlugin(),
  71. new CopyWebpackPlugin({
  72. patterns: [
  73. {
  74. from: `${JS_ROOT}/apps/editor/components/QueryEditorWebComponents.d.ts`,
  75. to: `${DIST_DIR}/lib/components`
  76. }
  77. ]
  78. })
  79. ]
  80. });
  81. const parserConfig = Object.assign({}, defaultConfig, {
  82. entry: {
  83. calciteAutocompleteParser: [`${JS_ROOT}/parse/sql/calcite/calciteAutocompleteParser.js`],
  84. calciteSyntaxParser: [`${JS_ROOT}/parse/sql/calcite/calciteSyntaxParser.js`],
  85. druidAutocompleteParser: [`${JS_ROOT}/parse/sql/druid/druidAutocompleteParser.js`],
  86. druidSyntaxParser: [`${JS_ROOT}/parse/sql/druid/druidSyntaxParser.js`],
  87. elasticsearchAutocompleteParser: [
  88. `${JS_ROOT}/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js`
  89. ],
  90. elasticsearchSyntaxParser: [`${JS_ROOT}/parse/sql/elasticsearch/elasticsearchSyntaxParser.js`],
  91. flinkAutocompleteParser: [`${JS_ROOT}/parse/sql/flink/flinkAutocompleteParser.js`],
  92. flinkSyntaxParser: [`${JS_ROOT}/parse/sql/flink/flinkSyntaxParser.js`],
  93. genericAutocompleteParser: [`${JS_ROOT}/parse/sql/generic/genericAutocompleteParser.js`],
  94. genericSyntaxParser: [`${JS_ROOT}/parse/sql/generic/genericSyntaxParser.js`],
  95. hiveAutocompleteParser: [`${JS_ROOT}/parse/sql/hive/hiveAutocompleteParser.js`],
  96. hiveSyntaxParser: [`${JS_ROOT}/parse/sql/hive/hiveSyntaxParser.js`],
  97. impalaAutocompleteParser: [`${JS_ROOT}/parse/sql/impala/impalaAutocompleteParser.js`],
  98. impalaSyntaxParser: [`${JS_ROOT}/parse/sql/impala/impalaSyntaxParser.js`],
  99. ksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/ksql/ksqlAutocompleteParser.js`],
  100. ksqlSyntaxParser: [`${JS_ROOT}/parse/sql/ksql/ksqlSyntaxParser.js`],
  101. phoenixAutocompleteParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixAutocompleteParser.js`],
  102. phoenixSyntaxParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixSyntaxParser.js`],
  103. prestoAutocompleteParser: [`${JS_ROOT}/parse/sql/presto/prestoAutocompleteParser.js`],
  104. prestoSyntaxParser: [`${JS_ROOT}/parse/sql/presto/prestoSyntaxParser.js`],
  105. dasksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlAutocompleteParser.js`],
  106. dasksqlSyntaxParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlSyntaxParser.js`]
  107. },
  108. performance: {
  109. hints: false,
  110. maxEntrypointSize: 1500000,
  111. maxAssetSize: 1500000
  112. },
  113. output: {
  114. path: `${DIST_DIR}/lib/parsers`,
  115. library: '[name]',
  116. libraryExport: 'default',
  117. libraryTarget: 'umd',
  118. umdNamedDefine: true,
  119. globalObject: `(typeof self !== 'undefined' ? self : this)`
  120. }
  121. });
  122. const WRAPPER_DIR = `${__dirname}/tools/vue3-webcomponent-wrapper`;
  123. const vue3WebCompWrapperConfig = Object.assign({}, defaultConfig, {
  124. entry: {
  125. index: [`${JS_ROOT}/vue/wrapper/index.ts`]
  126. },
  127. output: {
  128. path: `${WRAPPER_DIR}/dist`,
  129. library: '[name]',
  130. libraryExport: 'default',
  131. libraryTarget: 'umd',
  132. umdNamedDefine: true,
  133. globalObject: `(typeof self !== 'undefined' ? self : this)`
  134. },
  135. plugins: [
  136. new CleanWebpackPlugin([`${WRAPPER_DIR}/src`, `${WRAPPER_DIR}/dist`]),
  137. new CopyWebpackPlugin({
  138. patterns: [{ from: `${JS_ROOT}/vue/wrapper/`, to: `${WRAPPER_DIR}/src` }]
  139. })
  140. ]
  141. });
  142. module.exports = [libConfig, webComponentsConfig, parserConfig, vue3WebCompWrapperConfig];