webpack.config.npm.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. 'er-diagram': [`${JS_ROOT}/components/er-diagram/webcomp.ts`],
  61. 'query-editor-components': [`${JS_ROOT}/apps/editor/components/QueryEditorWebComponent.ts`]
  62. },
  63. output: {
  64. path: `${DIST_DIR}/lib/components`
  65. },
  66. plugins: [new VueLoaderPlugin()]
  67. });
  68. const parserConfig = Object.assign({}, defaultConfig, {
  69. entry: {
  70. calciteAutocompleteParser: [`${JS_ROOT}/parse/sql/calcite/calciteAutocompleteParser.js`],
  71. calciteSyntaxParser: [`${JS_ROOT}/parse/sql/calcite/calciteSyntaxParser.js`],
  72. druidAutocompleteParser: [`${JS_ROOT}/parse/sql/druid/druidAutocompleteParser.js`],
  73. druidSyntaxParser: [`${JS_ROOT}/parse/sql/druid/druidSyntaxParser.js`],
  74. elasticsearchAutocompleteParser: [
  75. `${JS_ROOT}/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js`
  76. ],
  77. elasticsearchSyntaxParser: [`${JS_ROOT}/parse/sql/elasticsearch/elasticsearchSyntaxParser.js`],
  78. flinkAutocompleteParser: [`${JS_ROOT}/parse/sql/flink/flinkAutocompleteParser.js`],
  79. flinkSyntaxParser: [`${JS_ROOT}/parse/sql/flink/flinkSyntaxParser.js`],
  80. genericAutocompleteParser: [`${JS_ROOT}/parse/sql/generic/genericAutocompleteParser.js`],
  81. genericSyntaxParser: [`${JS_ROOT}/parse/sql/generic/genericSyntaxParser.js`],
  82. hiveAutocompleteParser: [`${JS_ROOT}/parse/sql/hive/hiveAutocompleteParser.js`],
  83. hiveSyntaxParser: [`${JS_ROOT}/parse/sql/hive/hiveSyntaxParser.js`],
  84. impalaAutocompleteParser: [`${JS_ROOT}/parse/sql/impala/impalaAutocompleteParser.js`],
  85. impalaSyntaxParser: [`${JS_ROOT}/parse/sql/impala/impalaSyntaxParser.js`],
  86. ksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/ksql/ksqlAutocompleteParser.js`],
  87. ksqlSyntaxParser: [`${JS_ROOT}/parse/sql/ksql/ksqlSyntaxParser.js`],
  88. phoenixAutocompleteParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixAutocompleteParser.js`],
  89. phoenixSyntaxParser: [`${JS_ROOT}/parse/sql/phoenix/phoenixSyntaxParser.js`],
  90. prestoAutocompleteParser: [`${JS_ROOT}/parse/sql/presto/prestoAutocompleteParser.js`],
  91. prestoSyntaxParser: [`${JS_ROOT}/parse/sql/presto/prestoSyntaxParser.js`],
  92. dasksqlAutocompleteParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlAutocompleteParser.js`],
  93. dasksqlSyntaxParser: [`${JS_ROOT}/parse/sql/dasksql/dasksqlSyntaxParser.js`]
  94. },
  95. performance: {
  96. hints: false,
  97. maxEntrypointSize: 1500000,
  98. maxAssetSize: 1500000
  99. },
  100. output: {
  101. path: `${DIST_DIR}/lib/parsers`,
  102. library: '[name]',
  103. libraryExport: 'default',
  104. libraryTarget: 'umd',
  105. umdNamedDefine: true,
  106. globalObject: `(typeof self !== 'undefined' ? self : this)`
  107. }
  108. });
  109. const WRAPPER_DIR = `${__dirname}/tools/vue3-webcomponent-wrapper`;
  110. const vue3WebCompWrapperConfig = Object.assign({}, defaultConfig, {
  111. entry: {
  112. index: [`${JS_ROOT}/vue/wrapper/index.ts`]
  113. },
  114. output: {
  115. path: `${WRAPPER_DIR}/dist`,
  116. library: '[name]',
  117. libraryExport: 'default',
  118. libraryTarget: 'umd',
  119. umdNamedDefine: true,
  120. globalObject: `(typeof self !== 'undefined' ? self : this)`
  121. },
  122. plugins: [
  123. new CleanWebpackPlugin([`${WRAPPER_DIR}/src`, `${WRAPPER_DIR}/dist`]),
  124. new CopyWebpackPlugin({
  125. patterns: [{ from: `${JS_ROOT}/vue/wrapper/`, to: `${WRAPPER_DIR}/src` }]
  126. })
  127. ]
  128. });
  129. module.exports = [libConfig, webComponentsConfig, parserConfig, vue3WebCompWrapperConfig];