wxyyxc1992 пре 5 година
родитељ
комит
3678335f2f
3 измењених фајлова са 68 додато и 32 уклоњено
  1. 2
    1
      package.json
  2. 33
    31
      webpack.config.js
  3. 33
    0
      webpack.config.prod.js

+ 2
- 1
package.json Прегледај датотеку

@@ -9,8 +9,9 @@
9 9
     "type-check:watch": "npm run type-check -- --watch",
10 10
     "start": "webpack-dev-server --mode development",
11 11
     "test": "jest",
12
-    "build": "npm run clean && npm run build:cjs",
12
+    "build": "npm run clean && npm run build:cjs && npm run build:umd",
13 13
     "build:cjs": "tsc --project ./tsconfig.cjs.json",
14
+    "build:umd": "NODE_ENV=production webpack --config ./webpack.config.prod.js",
14 15
     "clean": "rimraf dist"
15 16
   },
16 17
   "repository": {

+ 33
- 31
webpack.config.js Прегледај датотеку

@@ -1,40 +1,42 @@
1
+/* eslint-disable @typescript-eslint/no-var-requires */
2
+
1 3
 const path = require('path');
2 4
 const HtmlWebpackPlugin = require('html-webpack-plugin');
3 5
 
4 6
 module.exports = {
5
-    mode: 'development',
6
-    entry: './example/main.ts',
7
-    devtool: 'inline-source-map',
8
-    devServer: {
9
-      contentBase: './dist',
10
-      compress: true,
11
-      hot: true,
12
-    },
13
-    plugins: [
14
-      new HtmlWebpackPlugin({
15
-          title: 'index'
16
-      })
17
-    ],
18
-    output: {
19
-        filename: '[name].bundle.js',
20
-        path: path.resolve(__dirname, 'dist')
21
-    },
22
-    resolve: { extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'] },
23
-    module: {
24
-      rules: [
7
+  mode: 'development',
8
+  entry: './example/main.ts',
9
+  devtool: 'inline-source-map',
10
+  devServer: {
11
+    contentBase: './dist',
12
+    compress: true,
13
+    hot: true,
14
+  },
15
+  plugins: [
16
+    new HtmlWebpackPlugin({
17
+      title: 'index',
18
+    }),
19
+  ],
20
+  output: {
21
+    filename: '[name].bundle.js',
22
+    path: path.resolve(__dirname, 'dist'),
23
+  },
24
+  resolve: { extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'] },
25
+  module: {
26
+    rules: [
25 27
       {
26
-          // Include ts, tsx, js, and jsx files.
27
-          test: /\.(ts|js)x?$/,
28
-          exclude: /node_modules/,
29
-          loader: 'babel-loader',
28
+        // Include ts, tsx, js, and jsx files.
29
+        test: /\.(ts|js)x?$/,
30
+        exclude: /node_modules/,
31
+        loader: 'babel-loader',
30 32
       },
31 33
       {
32
-          test: /\.(ts|js)x?$/,
33
-          loader: 'eslint-loader',
34
-          options: {
35
-            formatter: require('eslint-friendly-formatter')
36
-        }
37
-      }
34
+        test: /\.(ts|js)x?$/,
35
+        loader: 'eslint-loader',
36
+        options: {
37
+          formatter: require('eslint-friendly-formatter'),
38
+        },
39
+      },
38 40
     ],
39
-    }
41
+  },
40 42
 };

+ 33
- 0
webpack.config.prod.js Прегледај датотеку

@@ -0,0 +1,33 @@
1
+/* eslint-disable @typescript-eslint/no-var-requires */
2
+
3
+const path = require('path');
4
+
5
+module.exports = {
6
+  mode: 'production',
7
+  entry: './src/index.ts',
8
+  devtool: false,
9
+  output: {
10
+    filename: 'index.umd.js',
11
+    path: path.resolve(__dirname, 'dist'),
12
+    library: 'imSdk',
13
+    libraryTarget: 'umd',
14
+  },
15
+  resolve: { extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'] },
16
+  module: {
17
+    rules: [
18
+      {
19
+        // Include ts, tsx, js, and jsx files.
20
+        test: /\.(ts|js)x?$/,
21
+        exclude: /node_modules/,
22
+        loader: 'babel-loader',
23
+      },
24
+      {
25
+        test: /\.(ts|js)x?$/,
26
+        loader: 'eslint-loader',
27
+        options: {
28
+          formatter: require('eslint-friendly-formatter'),
29
+        },
30
+      },
31
+    ],
32
+  },
33
+};