浏览代码

[frontend] Add initial module export of libs needed for web component usage

Johan Ahlen 4 年之前
父节点
当前提交
c1068c4883
共有 2 个文件被更改,包括 26 次插入17 次删除
  1. 2 1
      tsconfig.json
  2. 24 16
      webpack.config.npm.js

+ 2 - 1
tsconfig.json

@@ -1,5 +1,7 @@
 {
   "compilerOptions": {
+    "declaration": true,
+    "emitDeclarationOnly": true,
     "target": "esnext",
     "module": "esnext",
     "moduleResolution": "node",
@@ -21,7 +23,6 @@
     "ext",
     "parse",
     "jquery",
-
     "apps",
     "build",
     "dist",

+ 24 - 16
webpack.config.npm.js

@@ -16,10 +16,10 @@
  * limitations under the License.
  */
 
-const path = require('path');
-const { VueLoaderPlugin } = require('vue-loader');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
 const CopyWebpackPlugin = require('copy-webpack-plugin');
+const path = require('path');
+const { VueLoaderPlugin } = require('vue-loader');
 
 const DIST_DIR = path.join(__dirname, 'npm_dist');
 const JS_ROOT = path.join(__dirname, '/desktop/core/src/desktop/js');
@@ -32,24 +32,32 @@ const defaultConfig = Object.assign({}, require('./webpack.config'), {
   plugins: []
 });
 
-const npmSetupPlugins = [
-  new CleanWebpackPlugin([DIST_DIR]),
-  new CopyWebpackPlugin({
-    patterns: [
-      { from: './package.json', to: `${DIST_DIR}/package.json` },
-      { from: './NPM-README.md', to: `${DIST_DIR}/README.md` },
-      { from: JS_ROOT, to: `${DIST_DIR}/src` }
-    ]
-  })
-];
-
 const libConfig = Object.assign({}, defaultConfig, {
   entry: {
     executor: [`${JS_ROOT}/apps/editor/execution/executor.ts`]
   },
   output: {
-    path: `${DIST_DIR}/lib/`
-  }
+    path: `${DIST_DIR}/lib/execution`,
+    library: '[name]',
+    libraryExport: 'default',
+    libraryTarget: 'umd',
+    umdNamedDefine: true,
+    globalObject: `(typeof self !== 'undefined' ? self : this)`
+  },
+  plugins: [
+    new CleanWebpackPlugin([DIST_DIR]),
+    new CopyWebpackPlugin({
+      patterns: [
+        { from: './package.json', to: `${DIST_DIR}/package.json` },
+        { from: './NPM-README.md', to: `${DIST_DIR}/README.md` },
+        { from: JS_ROOT, to: `${DIST_DIR}/src` },
+        {
+          from: `${JS_ROOT}/apps/editor/execution/executor.d.ts`,
+          to: `${DIST_DIR}/lib/execution`
+        }
+      ]
+    })
+  ]
 });
 
 const webComponentsConfig = Object.assign({}, defaultConfig, {
@@ -60,7 +68,7 @@ const webComponentsConfig = Object.assign({}, defaultConfig, {
   output: {
     path: `${DIST_DIR}/lib/components`
   },
-  plugins: npmSetupPlugins.concat(new VueLoaderPlugin())
+  plugins: [new VueLoaderPlugin()]
 });
 
 const parserConfig = Object.assign({}, defaultConfig, {