From 140f3f42c2f9033821dfe2731d4444cdd8156516 Mon Sep 17 00:00:00 2001 From: lovelope Date: Thu, 15 Aug 2019 23:23:54 +0800 Subject: [PATCH] refactor: webpack config write with ts --- babel.config.js | 2 +- package-lock.json | 260 +++++++++++++++--- package.json | 17 +- ...{getStyleLoaders.js => getStyleLoaders.ts} | 52 +++- tools/{getValueByEnv.js => getValueByEnv.ts} | 7 +- tools/{paths.js => paths.ts} | 7 +- tools/{proxy.config.js => proxy.config.ts} | 0 tools/{switch.config.js => switch.config.ts} | 0 tools/{theme.js => theme.ts} | 2 +- tools/{urls.js => urls.ts} | 0 ....babel.js => webpack.config.base.babel.ts} | 22 +- ...js => webpack.config.development.babel.ts} | 25 +- ...l.babel.js => webpack.config.dll.babel.ts} | 10 +- ....js => webpack.config.production.babel.ts} | 28 +- tsconfig.json | 3 +- webpack.config.js | 8 +- 16 files changed, 350 insertions(+), 93 deletions(-) rename tools/{getStyleLoaders.js => getStyleLoaders.ts} (60%) rename tools/{getValueByEnv.js => getValueByEnv.ts} (75%) rename tools/{paths.js => paths.ts} (83%) rename tools/{proxy.config.js => proxy.config.ts} (100%) rename tools/{switch.config.js => switch.config.ts} (100%) rename tools/{theme.js => theme.ts} (90%) rename tools/{urls.js => urls.ts} (100%) rename tools/{webpack.config.base.babel.js => webpack.config.base.babel.ts} (92%) rename tools/{webpack.config.development.babel.js => webpack.config.development.babel.ts} (73%) rename tools/{webpack.config.dll.babel.js => webpack.config.dll.babel.ts} (72%) rename tools/{webpack.config.production.babel.js => webpack.config.production.babel.ts} (88%) diff --git a/babel.config.js b/babel.config.js index 8e49edbc..efb0ed14 100644 --- a/babel.config.js +++ b/babel.config.js @@ -25,7 +25,7 @@ module.exports = { overrides: [ { test: ['./tools'], - presets: [['@babel/preset-env']], + presets: ['@babel/preset-env', '@babel/preset-typescript'], }, ], }; diff --git a/package-lock.json b/package-lock.json index 083aaa0e..7574bdce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1404,6 +1404,35 @@ "integrity": "sha1-M2utwb7sudrMOL6izzKt9ieoQho=", "dev": true }, + "@types/body-parser": { + "version": "1.17.0", + "resolved": "https://registry.npm.taobao.org/@types/body-parser/download/@types/body-parser-1.17.0.tgz", + "integrity": "sha1-n1ydm9BLtUvjLV65/A2Ml05s9Yw=", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "@types/connect": { + "version": "3.4.32", + "resolved": "https://registry.npm.taobao.org/@types/connect/download/@types/connect-3.4.32.tgz", + "integrity": "sha1-qg6WFrlDXMrQK8UrW0VP/Cxwuig=", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/connect-history-api-fallback": { + "version": "1.3.2", + "resolved": "https://registry.npm.taobao.org/@types/connect-history-api-fallback/download/@types/connect-history-api-fallback-1.3.2.tgz", + "integrity": "sha1-QKSXUAI46/MK4o/faHwvkpafJjU=", + "dev": true, + "requires": { + "@types/express-serve-static-core": "*", + "@types/node": "*" + } + }, "@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npm.taobao.org/@types/eslint-visitor-keys/download/@types/eslint-visitor-keys-1.0.0.tgz", @@ -1416,6 +1445,27 @@ "integrity": "sha1-KGLz9Yqaf3w+eNefEw3U1xwlwqc=", "dev": true }, + "@types/express": { + "version": "4.17.0", + "resolved": "https://registry.npm.taobao.org/@types/express/download/@types/express-4.17.0.tgz", + "integrity": "sha1-SertsglYKobxLtm3JRYPEtBO8oc=", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.16.7", + "resolved": "https://registry.npm.taobao.org/@types/express-serve-static-core/download/@types/express-serve-static-core-4.16.7.tgz", + "integrity": "sha1-ULpvimkcCKPdn6f7ol7zEz0pgEk=", + "dev": true, + "requires": { + "@types/node": "*", + "@types/range-parser": "*" + } + }, "@types/glob": { "version": "7.1.1", "resolved": "https://registry.npm.taobao.org/@types/glob/download/@types/glob-7.1.1.tgz", @@ -1427,18 +1477,50 @@ "@types/node": "*" } }, + "@types/http-proxy": { + "version": "1.17.0", + "resolved": "https://registry.npm.taobao.org/@types/http-proxy/download/@types/http-proxy-1.17.0.tgz", + "integrity": "sha1-uvgv9qonI/0p+Q47oThOZlAGhj4=", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/http-proxy-middleware": { + "version": "0.19.2", + "resolved": "https://registry.npm.taobao.org/@types/http-proxy-middleware/download/@types/http-proxy-middleware-0.19.2.tgz", + "integrity": "sha1-HES5ZIfLLzMxArdixWqPAiQehb0=", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/http-proxy": "*", + "@types/node": "*" + } + }, "@types/json-schema": { "version": "7.0.3", "resolved": "https://registry.npm.taobao.org/@types/json-schema/download/@types/json-schema-7.0.3.tgz", "integrity": "sha1-vf1p1h5GTcyBslFZwnDXWnPBpjY=", "dev": true }, + "@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npm.taobao.org/@types/json5/download/@types/json5-0.0.29.tgz", + "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", + "dev": true + }, "@types/lodash": { "version": "4.14.136", "resolved": "https://registry.npm.taobao.org/@types/lodash/download/@types/lodash-4.14.136.tgz", "integrity": "sha1-QT6FCJBGuGXZYMn/HUAOBMMatg8=", "dev": true }, + "@types/mime": { + "version": "2.0.1", + "resolved": "https://registry.npm.taobao.org/@types/mime/download/@types/mime-2.0.1.tgz", + "integrity": "sha1-3EiIQjEqfwdRSTEpBbXjwLBUx50=", + "dev": true + }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npm.taobao.org/@types/minimatch/download/@types/minimatch-3.0.3.tgz", @@ -1468,6 +1550,12 @@ "integrity": "sha1-aQoUdbhPKohP0HzXl8APXzE1bqg=", "dev": true }, + "@types/range-parser": { + "version": "1.2.3", + "resolved": "https://registry.npm.taobao.org/@types/range-parser/download/@types/range-parser-1.2.3.tgz", + "integrity": "sha1-fuMwunyq+5gJC+zoal7kQRWQTCw=", + "dev": true + }, "@types/react": { "version": "16.9.1", "resolved": "https://registry.npm.taobao.org/@types/react/download/@types/react-16.9.1.tgz", @@ -1500,6 +1588,16 @@ "integrity": "sha1-qYS0BccC+lp+xqvFazfyujXvWvY=", "dev": true }, + "@types/serve-static": { + "version": "1.13.2", + "resolved": "https://registry.npm.taobao.org/@types/serve-static/download/@types/serve-static-1.13.2.tgz", + "integrity": "sha1-9axNemQgqZpqRa9HGfTc2M2Qekg=", + "dev": true, + "requires": { + "@types/express-serve-static-core": "*", + "@types/mime": "*" + } + }, "@types/tapable": { "version": "1.0.4", "resolved": "https://registry.npm.taobao.org/@types/tapable/download/@types/tapable-1.0.4.tgz", @@ -1571,11 +1669,27 @@ } } }, - "@types/webpack-env": { - "version": "1.14.0", - "resolved": "https://registry.npm.taobao.org/@types/webpack-env/download/@types/webpack-env-1.14.0.tgz", - "integrity": "sha1-jt/F+Obq4g7u08oNApdO1O5eTvw=", - "dev": true + "@types/webpack-dev-server": { + "version": "3.1.7", + "resolved": "https://registry.npm.taobao.org/@types/webpack-dev-server/download/@types/webpack-dev-server-3.1.7.tgz", + "integrity": "sha1-o+eiA2bmi8mFPHMLVumUY0y3jaw=", + "dev": true, + "requires": { + "@types/connect-history-api-fallback": "*", + "@types/express": "*", + "@types/http-proxy-middleware": "*", + "@types/serve-static": "*", + "@types/webpack": "*" + } + }, + "@types/webpack-merge": { + "version": "4.1.5", + "resolved": "https://registry.npm.taobao.org/@types/webpack-merge/download/@types/webpack-merge-4.1.5.tgz", + "integrity": "sha1-Jl++5IEEdIYND0wX4BBwMoge7Uc=", + "dev": true, + "requires": { + "@types/webpack": "*" + } }, "@typescript-eslint/eslint-plugin": { "version": "1.13.0", @@ -2123,6 +2237,12 @@ "integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=", "dev": true }, + "arg": { + "version": "4.1.1", + "resolved": "https://registry.npm.taobao.org/arg/download/arg-4.1.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Farg%2Fdownload%2Farg-4.1.1.tgz", + "integrity": "sha1-SF+OfDkM5MX3glfb6oDUvhH+2kw=", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npm.taobao.org/argparse/download/argparse-1.0.10.tgz", @@ -2266,13 +2386,13 @@ "dependencies": { "inherits": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", + "resolved": "https://registry.npm.taobao.org/inherits/download/inherits-2.0.1.tgz", "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=", "dev": true }, "util": { "version": "0.10.3", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", + "resolved": "https://registry.npm.taobao.org/util/download/util-0.10.3.tgz", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "dev": true, "requires": { @@ -2699,7 +2819,7 @@ }, "brorand": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", + "resolved": "https://registry.npm.taobao.org/brorand/download/brorand-1.1.0.tgz", "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=", "dev": true }, @@ -2742,7 +2862,7 @@ }, "browserify-rsa": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", + "resolved": "https://registry.npm.taobao.org/browserify-rsa/download/browserify-rsa-4.0.1.tgz", "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=", "dev": true, "requires": { @@ -2752,7 +2872,7 @@ }, "browserify-sign": { "version": "4.0.4", - "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.0.4.tgz", + "resolved": "https://registry.npm.taobao.org/browserify-sign/download/browserify-sign-4.0.4.tgz", "integrity": "sha1-qk62jl17ZYuqa/alfmMMvXqT0pg=", "dev": true, "requires": { @@ -2787,7 +2907,7 @@ }, "buffer": { "version": "4.9.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", + "resolved": "https://registry.npm.taobao.org/buffer/download/buffer-4.9.1.tgz", "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=", "dev": true, "requires": { @@ -2798,7 +2918,7 @@ "dependencies": { "isarray": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz?cache=0&sync_timestamp=1562592125418&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fisarray%2Fdownload%2Fisarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true } @@ -2818,13 +2938,13 @@ }, "buffer-xor": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", + "resolved": "https://registry.npm.taobao.org/buffer-xor/download/buffer-xor-1.0.3.tgz", "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=", "dev": true }, "builtin-status-codes": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/builtin-status-codes/download/builtin-status-codes-3.0.0.tgz", "integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=", "dev": true }, @@ -3546,7 +3666,7 @@ }, "console-browserify": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", + "resolved": "https://registry.npm.taobao.org/console-browserify/download/console-browserify-1.1.0.tgz", "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", "dev": true, "requires": { @@ -3555,7 +3675,7 @@ }, "constants-browserify": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/constants-browserify/-/constants-browserify-1.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/constants-browserify/download/constants-browserify-1.0.0.tgz", "integrity": "sha1-wguW2MYXdIqvHBYCF2DNJ/y4y3U=", "dev": true }, @@ -4191,7 +4311,7 @@ }, "date-now": { "version": "0.1.4", - "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", + "resolved": "https://registry.npm.taobao.org/date-now/download/date-now-0.1.4.tgz", "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", "dev": true }, @@ -4252,6 +4372,12 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "deepmerge": { + "version": "2.2.1", + "resolved": "https://registry.npm.taobao.org/deepmerge/download/deepmerge-2.2.1.tgz", + "integrity": "sha1-XT/yKgHAD2RUBaL7wX0HeKGAEXA=", + "dev": true + }, "default-gateway": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/default-gateway/-/default-gateway-4.2.0.tgz", @@ -4348,7 +4474,7 @@ }, "des.js": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/des.js/download/des.js-1.0.0.tgz", "integrity": "sha1-wHTS4qpqipoH29YfmhXCzYPsjsw=", "dev": true, "requires": { @@ -4383,6 +4509,12 @@ "integrity": "sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw==", "dev": true }, + "diff": { + "version": "4.0.1", + "resolved": "https://registry.npm.taobao.org/diff/download/diff-4.0.1.tgz", + "integrity": "sha1-DGZ8tGfru1zqfxTxNcwtuneAqP8=", + "dev": true + }, "diffie-hellman": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", @@ -6938,7 +7070,7 @@ }, "hash-base": { "version": "3.0.4", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", + "resolved": "https://registry.npm.taobao.org/hash-base/download/hash-base-3.0.4.tgz", "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", "dev": true, "requires": { @@ -7063,7 +7195,7 @@ }, "hmac-drbg": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "resolved": "https://registry.npm.taobao.org/hmac-drbg/download/hmac-drbg-1.0.1.tgz", "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", "dev": true, "requires": { @@ -7443,7 +7575,7 @@ }, "https-browserify": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/https-browserify/download/https-browserify-1.0.0.tgz", "integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=", "dev": true }, @@ -9030,6 +9162,12 @@ "semver": "^5.6.0" } }, + "make-error": { + "version": "1.3.5", + "resolved": "https://registry.npm.taobao.org/make-error/download/make-error-1.3.5.tgz", + "integrity": "sha1-7+ToH22yjK3WBccPKcgxtY73dsg=", + "dev": true + }, "mamacro": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/mamacro/-/mamacro-0.0.3.tgz", @@ -9338,7 +9476,7 @@ }, "minimalistic-crypto-utils": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "resolved": "https://registry.npm.taobao.org/minimalistic-crypto-utils/download/minimalistic-crypto-utils-1.0.1.tgz", "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=", "dev": true }, @@ -9608,7 +9746,7 @@ "dependencies": { "punycode": { "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "resolved": "https://registry.npm.taobao.org/punycode/download/punycode-1.4.1.tgz", "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", "dev": true } @@ -9929,7 +10067,7 @@ }, "os-browserify": { "version": "0.3.0", - "resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.3.0.tgz", + "resolved": "https://registry.npm.taobao.org/os-browserify/download/os-browserify-0.3.0.tgz", "integrity": "sha1-hUNzx/XCMVkU/Jv8a9gjj92h7Cc=", "dev": true }, @@ -11490,7 +11628,7 @@ }, "process": { "version": "0.11.10", - "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "resolved": "https://registry.npm.taobao.org/process/download/process-0.11.10.tgz", "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=", "dev": true }, @@ -11703,7 +11841,7 @@ }, "querystring-es3": { "version": "0.2.1", - "resolved": "https://registry.npmjs.org/querystring-es3/-/querystring-es3-0.2.1.tgz", + "resolved": "https://registry.npm.taobao.org/querystring-es3/download/querystring-es3-0.2.1.tgz", "integrity": "sha1-nsYfeQSYdXB9aUFFlv2Qek1xHnM=", "dev": true }, @@ -14676,7 +14814,7 @@ }, "to-arraybuffer": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz", + "resolved": "https://registry.npm.taobao.org/to-arraybuffer/download/to-arraybuffer-1.0.1.tgz", "integrity": "sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=", "dev": true }, @@ -14812,6 +14950,43 @@ "integrity": "sha1-O1Kx8Tkk9GDD+/0N9ptYfby8di4=", "dev": true }, + "ts-node": { + "version": "8.3.0", + "resolved": "https://registry.npm.taobao.org/ts-node/download/ts-node-8.3.0.tgz", + "integrity": "sha1-5AWWGEETcZJKH7XzsSWRXzJO+1c=", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.6", + "yn": "^3.0.0" + } + }, + "tsconfig-paths": { + "version": "3.8.0", + "resolved": "https://registry.npm.taobao.org/tsconfig-paths/download/tsconfig-paths-3.8.0.tgz", + "integrity": "sha1-TjQgLVtBlY8mnPVrAe2VuFPVn3I=", + "dev": true, + "requires": { + "@types/json5": "^0.0.29", + "deepmerge": "^2.0.1", + "json5": "^1.0.1", + "minimist": "^1.2.0", + "strip-bom": "^3.0.0" + }, + "dependencies": { + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npm.taobao.org/json5/download/json5-1.0.1.tgz", + "integrity": "sha1-d5+wAYYE+oVOrL9iUhgNg1Q+Pb4=", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + } + } + }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npm.taobao.org/tslib/download/tslib-1.10.0.tgz", @@ -14829,7 +15004,7 @@ }, "tty-browserify": { "version": "0.0.0", - "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/tty-browserify/download/tty-browserify-0.0.0.tgz", "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=", "dev": true }, @@ -15257,7 +15432,7 @@ "dependencies": { "inherits": { "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "resolved": "https://registry.npm.taobao.org/inherits/download/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true } @@ -15462,7 +15637,7 @@ "dependencies": { "extend-shallow": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", + "resolved": "https://registry.npm.taobao.org/extend-shallow/download/extend-shallow-2.0.1.tgz", "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", "dev": true, "requires": { @@ -15473,7 +15648,7 @@ }, "fill-range": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/fill-range/download/fill-range-4.0.0.tgz", "integrity": "sha1-1USBHUKPmOsGpj3EAtJAPDKMOPc=", "dev": true, "requires": { @@ -15485,7 +15660,7 @@ "dependencies": { "extend-shallow": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", + "resolved": "https://registry.npm.taobao.org/extend-shallow/download/extend-shallow-2.0.1.tgz", "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", "dev": true, "requires": { @@ -15502,7 +15677,7 @@ }, "is-number": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/is-number/download/is-number-3.0.0.tgz", "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", "dev": true, "requires": { @@ -15511,7 +15686,7 @@ "dependencies": { "kind-of": { "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "resolved": "https://registry.npm.taobao.org/kind-of/download/kind-of-3.2.2.tgz", "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", "dev": true, "requires": { @@ -15543,7 +15718,7 @@ }, "to-regex-range": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-2.1.1.tgz", + "resolved": "https://registry.npm.taobao.org/to-regex-range/download/to-regex-range-2.1.1.tgz", "integrity": "sha1-fIDBe53+vlmeJzZ+DU3VWQFB2zg=", "dev": true, "requires": { @@ -15800,6 +15975,15 @@ "uuid": "^3.3.2" } }, + "webpack-merge": { + "version": "4.2.1", + "resolved": "https://registry.npm.taobao.org/webpack-merge/download/webpack-merge-4.2.1.tgz", + "integrity": "sha1-XpI8+ALqKs5P1a8dMkc2imM0ibQ=", + "dev": true, + "requires": { + "lodash": "^4.17.5" + } + }, "webpack-sources": { "version": "1.4.3", "resolved": "https://registry.npm.taobao.org/webpack-sources/download/webpack-sources-1.4.3.tgz", @@ -16000,6 +16184,12 @@ "camelcase": "^4.1.0" } }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npm.taobao.org/yn/download/yn-3.1.1.tgz", + "integrity": "sha1-HodAGgnXZ8HV6rJqbkwYUYLS61A=", + "dev": true + }, "zwitch": { "version": "1.0.4", "resolved": "https://registry.npm.taobao.org/zwitch/download/zwitch-1.0.4.tgz", diff --git a/package.json b/package.json index cf55ffe4..2e3f77b1 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,15 @@ "author": "lovelope ", "main": "index.js", "scripts": { - "build": "cross-env NODE_ENV=production webpack --config tools/webpack.config.production.babel.js", - "build:dll": "cross-env NODE_ENV=production webpack --config tools/webpack.config.dll.babel.js", + "build": "cross-env NODE_ENV=production webpack", + "build:dll": "cross-env NODE_ENV=production webpack --config tools/webpack.config.dll.babel.ts", "fix": "npm run fix-js && npm run lint-css", "fix-js": "npm run lint-js --fix", - "format": "prettier --config prettier.config.js --write '**/*.{js,jsx,css,less,json}'", + "format": "prettier --config prettier.config.js --write \"**/*.{ts,tsx,js,jsx,css,less,json,md,html}\"", "lint": "npm run lint-js && npm run lint-css", "lint-css": "stylelint \"src/**/*.{less}\" --syntax less", "lint-js": "eslint . --ext .js,.jsx,.ts,.tsx", - "start": "cross-env NODE_ENV=development webpack-dev-server --config tools/webpack.config.development.babel.js --color --progress" + "start": "cross-env NODE_ENV=development webpack-dev-server --color --progress" }, "husky": { "hooks": { @@ -97,7 +97,9 @@ "@types/node": "^12.7.2", "@types/react": "^16.9.1", "@types/react-dom": "^16.8.5", - "@types/webpack-env": "^1.14.0", + "@types/webpack": "^4.32.1", + "@types/webpack-dev-server": "^3.1.7", + "@types/webpack-merge": "^4.1.5", "@typescript-eslint/eslint-plugin": "^1.13.0", "@typescript-eslint/parser": "^1.13.0", "babel-eslint": "^10.0.2", @@ -142,10 +144,13 @@ "stylelint-order": "^3.0.1", "terser": "^4.1.4", "terser-webpack-plugin": "^1.4.1", + "ts-node": "^8.3.0", + "tsconfig-paths": "^3.8.0", "typescript": "^3.5.3", "url-loader": "^2.1.0", "webpack": "^4.39.2", "webpack-cli": "^3.3.6", - "webpack-dev-server": "^3.8.0" + "webpack-dev-server": "^3.8.0", + "webpack-merge": "^4.2.1" } } diff --git a/tools/getStyleLoaders.js b/tools/getStyleLoaders.ts similarity index 60% rename from tools/getStyleLoaders.js rename to tools/getStyleLoaders.ts index f7ac046d..82c16956 100644 --- a/tools/getStyleLoaders.js +++ b/tools/getStyleLoaders.ts @@ -1,23 +1,55 @@ -// eslint-disable-next-line import/no-extraneous-dependencies +/* eslint-disable import/no-extraneous-dependencies */ +import webpack from 'webpack'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; /** - * 获取 cssLoaders - * @param {object} options 配置 - * @param {boolean} options.isProd 是否为生产环境 - * @param {boolean} options.sourceMap 是否开启sourceMap - * @param {boolean} options.modules 是否开启css modules - * @param {boolean} options.useLess 是否使用 less - * @param {object} options.modifyVars 覆盖 less 变量 - * @returns {object[]} loader数组 + * 获取 cssLoaders 配置 + * @interface GetStyleLoadersOptions */ +interface GetStyleLoadersOptions { + /** + * 是否为生产环境 + * @type {boolean} + * @memberof GetStyleLoadersOptions + */ + isProd?: boolean; + + /** + * 是否开启sourceMap + * @type {boolean} + * @memberof GetStyleLoadersOptions + */ + sourceMap?: boolean; + + /** + * 是否开启css modules + * @type {boolean} + * @memberof GetStyleLoadersOptions + */ + modules?: boolean; + + /** + * 是否使用 less + * @type {boolean} + * @memberof GetStyleLoadersOptions + */ + useLess?: boolean; + + /** + * 覆盖 less 变量 + * @type {object} + * @memberof GetStyleLoadersOptions + */ + modifyVars?: {}; +} + export default function getStyleLoaders({ isProd = true, // 生产环境 sourceMap = true, // 打开 sourceMap modules = false, // 开启 css module useLess = false, // 使用 less modifyVars = {}, // 修改 less 变量 -}) { +}: GetStyleLoadersOptions): webpack.RuleSetUseItem[] { return [ isProd ? MiniCssExtractPlugin.loader diff --git a/tools/getValueByEnv.js b/tools/getValueByEnv.ts similarity index 75% rename from tools/getValueByEnv.js rename to tools/getValueByEnv.ts index 1932ccd5..73da38de 100644 --- a/tools/getValueByEnv.js +++ b/tools/getValueByEnv.ts @@ -4,9 +4,12 @@ * @param {Object} obj 对象 * @param {Object} param1 { @param {String} field key 值, @param {String} defaultEnv 默认环境} */ -export default function getValueByEnv(obj, { field = '', defaultEnv = 'dev' }) { +export default function getValueByEnv( + obj, + { field = '', defaultEnv = 'dev' } +): any { let value = obj[defaultEnv]; - Object.keys(obj).forEach(envKey => { + Object.keys(obj).forEach((envKey: string): void => { if (process.env[`npm_config_${envKey}`]) { value = obj[envKey]; } diff --git a/tools/paths.js b/tools/paths.ts similarity index 83% rename from tools/paths.js rename to tools/paths.ts index 64c718ec..af3a82ed 100644 --- a/tools/paths.js +++ b/tools/paths.ts @@ -2,12 +2,13 @@ import fs from 'fs'; import path from 'path'; const appDirectory = fs.realpathSync(process.cwd()); -const resolveApp = relativePath => path.resolve(appDirectory, relativePath); +const resolveApp = (relativePath): string => + path.resolve(appDirectory, relativePath); // 查找入口文件,可能是 ts 也可能是 js -const resolveModule = (resolveFn, filePath) => { +const resolveModule = (resolveFn, filePath): string => { const moduleFileExtensions = ['js', 'jsx', 'ts', 'tsx']; - const extension = moduleFileExtensions.find(ext => + const extension = moduleFileExtensions.find((ext): boolean => fs.existsSync(resolveFn(`${filePath}.${ext}`)) ); diff --git a/tools/proxy.config.js b/tools/proxy.config.ts similarity index 100% rename from tools/proxy.config.js rename to tools/proxy.config.ts diff --git a/tools/switch.config.js b/tools/switch.config.ts similarity index 100% rename from tools/switch.config.js rename to tools/switch.config.ts diff --git a/tools/theme.js b/tools/theme.ts similarity index 90% rename from tools/theme.js rename to tools/theme.ts index 81fbf0d3..84147629 100644 --- a/tools/theme.js +++ b/tools/theme.ts @@ -2,7 +2,7 @@ import lessToJs from 'less-vars-to-js'; import fs from 'fs'; -export default function getTheme(path) { +export default function getTheme(path): object { let themeContent = ''; // 解决 theme 文件不存在的异常 diff --git a/tools/urls.js b/tools/urls.ts similarity index 100% rename from tools/urls.js rename to tools/urls.ts diff --git a/tools/webpack.config.base.babel.js b/tools/webpack.config.base.babel.ts similarity index 92% rename from tools/webpack.config.base.babel.js rename to tools/webpack.config.base.babel.ts index 595314cb..587ef250 100644 --- a/tools/webpack.config.base.babel.js +++ b/tools/webpack.config.base.babel.ts @@ -1,3 +1,6 @@ +/* eslint-disable import/extensions */ +/* eslint-disable import/no-extraneous-dependencies */ + import path from 'path'; import os from 'os'; @@ -7,10 +10,10 @@ import ProgressBarPlugin from 'progress-bar-webpack-plugin'; import LodashModuleReplacementPlugin from 'lodash-webpack-plugin'; import mdHighlightPlugin from '@mapbox/rehype-prism'; -import paths, { PUBLIC_PATH } from './paths.js'; -import getTheme from './theme.js'; -import getStyleLoaders from './getStyleLoaders.js'; -import switchConfig from './switch.config.js'; +import paths, { PUBLIC_PATH } from './paths'; +import getTheme from './theme'; +import getStyleLoaders from './getStyleLoaders'; +import switchConfig from './switch.config'; // 构造出共享进程池,进程池中包含cpu+1个子进程 const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length + 1 }); @@ -29,7 +32,11 @@ const REGEXP_MODULE_LESS = /\.module\.less$/; const REGEXP_CSS = /\.css$/; const REGEXP_LESS = /\.less$/; -export default { +/** + * + * @export {webpack.Configuration} default + */ +const config: webpack.Configuration = { context: paths.appRoot, mode: isProd ? 'production' : 'development', @@ -50,7 +57,7 @@ export default { ? 'js/[name].[hash:8].chunk.js' : 'js/[name].chunk.js', // 格式化 windows 上的文件路径 - devtoolModuleFilenameTemplate: info => + devtoolModuleFilenameTemplate: (info): string => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), }, @@ -209,6 +216,7 @@ export default { fs: 'empty', net: 'empty', tls: 'empty', + // eslint-disable-next-line @typescript-eslint/camelcase child_process: 'empty', }, @@ -229,3 +237,5 @@ export default { performance: false, }; + +export default config; diff --git a/tools/webpack.config.development.babel.js b/tools/webpack.config.development.babel.ts similarity index 73% rename from tools/webpack.config.development.babel.js rename to tools/webpack.config.development.babel.ts index 0870ad99..71eba9a6 100644 --- a/tools/webpack.config.development.babel.js +++ b/tools/webpack.config.development.babel.ts @@ -1,17 +1,22 @@ +/* eslint-disable import/extensions */ +/* eslint-disable import/no-extraneous-dependencies */ + import webpack from 'webpack'; +import webpackDevServer from 'webpack-dev-server'; +import merge from 'webpack-merge'; import HtmlWebpackPlugin from 'html-webpack-plugin'; -import webpackConfigBase from './webpack.config.base.babel.js'; -import paths, { PUBLIC_PATH } from './paths.js'; -import proxyConfigAll from './proxy.config.js'; -import getValueByEnv from './getValueByEnv.js'; + +import webpackConfigBase from './webpack.config.base.babel'; +import paths, { PUBLIC_PATH } from './paths'; +import proxyConfigAll from './proxy.config'; +import getValueByEnv from './getValueByEnv'; const HOST = process.env.HOST || '0.0.0.0'; // 本机IP const PORT = process.env.PORT || 8080; // 端口号 const proxyCurrent = getValueByEnv(proxyConfigAll, { defaultEnv: 'dev' }); -const webpackConfigDev = { - ...webpackConfigBase, +const webpackConfigDev: webpack.Configuration = merge(webpackConfigBase, { devServer: { // 允许访问的机器列表 allowedHosts: [HOST, 'localhost', '127.0.0.1'], @@ -51,8 +56,8 @@ const webpackConfigDev = { // 此选项允许浏览器使用本地 IP 打开。 useLocalIp: true, - }, - plugins: webpackConfigBase.plugins.concat([ + } as webpackDevServer.Configuration, + plugins: [ // html 模板 new HtmlWebpackPlugin({ inject: true, @@ -61,7 +66,7 @@ const webpackConfigDev = { // 模块热替换 new webpack.HotModuleReplacementPlugin(), - ]), -}; + ], +}); export default webpackConfigDev; diff --git a/tools/webpack.config.dll.babel.js b/tools/webpack.config.dll.babel.ts similarity index 72% rename from tools/webpack.config.dll.babel.js rename to tools/webpack.config.dll.babel.ts index 8c9b247c..70db4db2 100644 --- a/tools/webpack.config.dll.babel.js +++ b/tools/webpack.config.dll.babel.ts @@ -1,7 +1,11 @@ +/* eslint-disable import/extensions */ +/* eslint-disable import/no-extraneous-dependencies */ + import webpack from 'webpack'; -import paths from './paths.js'; -export default { +import paths from './paths'; + +const dllConfig: webpack.Configuration = { mode: 'production', entry: { vendor: ['react', 'react-dom', 'react-router', 'mobx', 'mobx-react'], @@ -18,3 +22,5 @@ export default { }), ], }; + +export default dllConfig; diff --git a/tools/webpack.config.production.babel.js b/tools/webpack.config.production.babel.ts similarity index 88% rename from tools/webpack.config.production.babel.js rename to tools/webpack.config.production.babel.ts index a2172b98..b9a9e2e2 100644 --- a/tools/webpack.config.production.babel.js +++ b/tools/webpack.config.production.babel.ts @@ -1,3 +1,7 @@ +/* eslint-disable @typescript-eslint/camelcase */ +/* eslint-disable import/extensions */ +/* eslint-disable import/no-extraneous-dependencies */ + import webpack from 'webpack'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import Terser from 'terser'; @@ -7,11 +11,12 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin'; import { CleanWebpackPlugin } from 'clean-webpack-plugin'; import HtmlWebpackTagsPlugin from 'html-webpack-tags-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; -import webpackConfigBase from './webpack.config.base.babel.js'; -import paths from './paths.js'; -import urls from './urls.js'; -import getValueByEnv from './getValueByEnv.js'; -import switchConfig from './switch.config.js'; + +import webpackConfigBase from './webpack.config.base.babel'; +import paths, { PUBLIC_PATH } from './paths'; +import urls from './urls'; +import getValueByEnv from './getValueByEnv'; +import switchConfig from './switch.config'; const { USE_DLL, @@ -26,9 +31,9 @@ const PRIVATE_SOURCE_MAP_SERVER = getValueByEnv(urls, { field: 'PRIVATE_SOURCE_MAP_SERVER', defaultEnv: 'online', }); -const SOURCE_MAP_PUBLICH_PATH = USE_PRIVATE_SOURCE_MAP_SERVER +const SOURCE_MAP_PUBLIC_PATH = USE_PRIVATE_SOURCE_MAP_SERVER ? PRIVATE_SOURCE_MAP_SERVER - : paths.publicPath; + : PUBLIC_PATH; let manifestJson = null; if (USE_DLL) { @@ -42,7 +47,7 @@ if (USE_DLL) { } } -const webpackConfigProd = { +const webpackConfigProd: webpack.Configuration = { ...webpackConfigBase, mode: 'production', @@ -137,7 +142,7 @@ const webpackConfigProd = { USE_DLL && new webpack.DllReferencePlugin({ manifest: manifestJson, - }), + } as webpack.DllReferencePlugin.Options), USE_DLL && new HtmlWebpackTagsPlugin({ @@ -148,8 +153,7 @@ const webpackConfigProd = { // 自定义 sourcemap 地址 new webpack.SourceMapDevToolPlugin({ filename: 'sourcemaps/[file].map', - publicPath: SOURCE_MAP_PUBLICH_PATH, - fileContext: 'js', + publicPath: SOURCE_MAP_PUBLIC_PATH, }), // 清理旧文件, plugins 顺序应该放在最后 @@ -165,7 +169,7 @@ const webpackConfigProd = { { from: paths.appPublic, to: paths.appDist, - transform(content, filePath) { + transform(content, filePath): string { if (/\.js$/.test(filePath)) { // 将 Buffer(content) 转为 String(source) const source = content.toString('utf8'); diff --git a/tsconfig.json b/tsconfig.json index a501b9c7..6cf5b8ab 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,8 +15,7 @@ }, "sourceMap": true, "strict": true, - "target": "esnext", - "types": ["node", "react", "react-dom", "antd", "webpack-env"] + "target": "esnext" }, "exclude": ["node_modules", "dist"], "include": ["src/**/*"] diff --git a/webpack.config.js b/webpack.config.js index 6612478d..9cde6e19 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,8 +1,10 @@ -require('@babel/register'); +require('@babel/register')({ + extensions: ['.ts', '.js'], +}); -const webpackConfigProd = require('./tools/webpack.config.production.babel.js') +const webpackConfigProd = require('./tools/webpack.config.production.babel.ts') .default; -const webpackConfigDev = require('./tools/webpack.config.development.babel.js') +const webpackConfigDev = require('./tools/webpack.config.development.babel.ts') .default; if (process.env.NODE_ENV === 'production') {