From 9c426d667cacfb0f4e74789281c1ea9983decf45 Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Wed, 26 Apr 2023 15:03:13 +0800 Subject: [PATCH] build: Make ES3 only in prod env --- README.md | 2 +- scripts/generatePolyfill/index.js | 2 +- .../generateUnrecognizableFeatures/index.js | 2 +- tsconfig.json | 15 ++----------- tsconfig.production.json | 22 +++++++++++++++++++ 5 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 tsconfig.production.json diff --git a/README.md b/README.md index 1ee18a14..cb3f5e5f 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ 机器人通过以下流程编译代码,然后提交到萌百: -- 执行 `tsc --build --verbose` 以编译 `*.js` 代码; +- 执行 `tsc --project tsconfig.production.json` 以编译 `*.js` 代码; - 执行 `npx postcss src/**/*.css --base src/ -d dist/ --verbose` 以编译 `*.css` 代码; - 根据模板生成 `MediaWiki:Gadgets-definition` 页面。 diff --git a/scripts/generatePolyfill/index.js b/scripts/generatePolyfill/index.js index a4fa733a..fd40750d 100644 --- a/scripts/generatePolyfill/index.js +++ b/scripts/generatePolyfill/index.js @@ -34,7 +34,7 @@ for (const file of await findPolyfillFiles()) { console.info("Start to compile src/ to temporary bundle file..."); const bundlePath = path.join(tempPath, "bundle.js"); console.log("bundlePath:", bundlePath); -await exec(`npx tsc --project tsconfig.json --outFile ${bundlePath}`); +await exec(`npx tsc --project tsconfig.production.json --outFile ${bundlePath}`); console.info("\tDone."); console.info("Start to analyse the temporary bundle file..."); const analysisReport = [...new Set(JSON.parse(await exec(`npx @financial-times/js-features-analyser analyse --file ${path.relative(".", bundlePath)}`)))].sort(); diff --git a/scripts/generateUnrecognizableFeatures/index.js b/scripts/generateUnrecognizableFeatures/index.js index b117fc2c..91f3b890 100644 --- a/scripts/generateUnrecognizableFeatures/index.js +++ b/scripts/generateUnrecognizableFeatures/index.js @@ -14,7 +14,7 @@ const tempPath = await mkdtmp(); console.info("Start to compile src/ to temporary bundle file..."); const bundlePath = path.join(tempPath, "bundle.js"); console.log("bundlePath:", bundlePath); -await exec(`npx tsc --project tsconfig.json --outFile ${bundlePath}`); +await exec(`npx tsc --project tsconfig.production.json --outFile ${bundlePath}`); console.info("\tDone."); console.info("Start to analyse the temporary bundle file..."); const analysisReport = [...new Set(JSON.parse(await exec(`npx @financial-times/js-features-analyser analyse --file ${path.relative(".", bundlePath)}`)))].sort(); diff --git a/tsconfig.json b/tsconfig.json index b507d99b..6cb96ff4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,26 +2,15 @@ "compilerOptions": { "allowJs": true, "removeComments": true, - "target": "ES3", + "target": "ESNext", "outDir": "dist/", "alwaysStrict": true, "strict": true, "downlevelIteration": true, - "incremental": true, "lib": [ - "ES5", - "ES2015", - "ES2016", - "ES2017", - "ES2018", - "ES2019", - "ES2020", - "ES2021", - "ES2022", "ESNext", "DOM" - ], - "ignoreDeprecations": "5.0" + ] }, "include": [ "src", diff --git a/tsconfig.production.json b/tsconfig.production.json new file mode 100644 index 00000000..8373a2d4 --- /dev/null +++ b/tsconfig.production.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "allowJs": true, + "removeComments": true, + "target": "ES3", + "outDir": "dist/", + "alwaysStrict": true, + "strict": true, + "downlevelIteration": true, + "lib": [ + "ESNext", + "DOM" + ], + "ignoreDeprecations": "5.0" + }, + "include": [ + "src", + ], + "exclude": [ + "dist", + ], +}