Browse Source

add scripts

Paul 5 years ago
parent
commit
8ecf4bded5

+ 3
- 3
package.json View File

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

jest.config.js → scripts/jest/jest.config.js View File

2
   transform: {
2
   transform: {
3
     '^.+\\.tsx?$': 'ts-jest',
3
     '^.+\\.tsx?$': 'ts-jest',
4
   },
4
   },
5
+  rootDir: '../../',
5
   testRegex: '(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
6
   testRegex: '(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
6
   moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7
   moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7
 };
8
 };

webpack.config.js → scripts/webpack/webpack.config.dev.js View File

1
 /* eslint-disable @typescript-eslint/no-var-requires */
1
 /* eslint-disable @typescript-eslint/no-var-requires */
2
 
2
 
3
 const path = require('path');
3
 const path = require('path');
4
+const rootPath = process.cwd();
4
 const HtmlWebpackPlugin = require('html-webpack-plugin');
5
 const HtmlWebpackPlugin = require('html-webpack-plugin');
5
 
6
 
6
 module.exports = {
7
 module.exports = {
8
   entry: './example/main.ts',
9
   entry: './example/main.ts',
9
   devtool: 'inline-source-map',
10
   devtool: 'inline-source-map',
10
   devServer: {
11
   devServer: {
11
-    contentBase: './dist',
12
     compress: true,
12
     compress: true,
13
     hot: true,
13
     hot: true,
14
   },
14
   },
19
   ],
19
   ],
20
   output: {
20
   output: {
21
     filename: '[name].bundle.js',
21
     filename: '[name].bundle.js',
22
-    path: path.resolve(__dirname, 'dist'),
22
+    path: path.resolve(rootPath, 'dist'),
23
   },
23
   },
24
   resolve: { extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'] },
24
   resolve: { extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'] },
25
   module: {
25
   module: {

webpack.config.prod.js → scripts/webpack/webpack.config.umd.js View File

1
 /* eslint-disable @typescript-eslint/no-var-requires */
1
 /* eslint-disable @typescript-eslint/no-var-requires */
2
 
2
 
3
 const path = require('path');
3
 const path = require('path');
4
+const rootPath = process.cwd();
4
 
5
 
5
 module.exports = {
6
 module.exports = {
6
   mode: 'production',
7
   mode: 'production',
8
   devtool: false,
9
   devtool: false,
9
   output: {
10
   output: {
10
     filename: 'index.js',
11
     filename: 'index.js',
11
-    path: path.resolve(__dirname, 'dist/umd'),
12
+    path: path.resolve(rootPath, 'dist/umd'),
12
     library: 'imSdk',
13
     library: 'imSdk',
13
     libraryTarget: 'umd',
14
     libraryTarget: 'umd',
14
   },
15
   },