From f4ab8f212e44420b705e1907f25d7f10552bbbd0 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sun, 16 May 2021 13:21:54 +0100 Subject: [PATCH] Use babel to transpile. --- package.json | 8 +++++++ webpack.config.js | 58 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6f76a36..869fcc7 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,20 @@ { "devDependencies": { + "@babel/core": "^7.14.2", "@babel/eslint-parser": "^7.14.2", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/plugin-proposal-decorators": "^7.14.2", + "@babel/plugin-proposal-object-rest-spread": "^7.14.2", + "@babel/plugin-transform-runtime": "^7.14.2", + "@babel/preset-env": "^7.14.2", "@types/prismjs": "^1.16.5", "@types/uikit": "^3.3.1", "@typescript-eslint/eslint-plugin": "^4.23.0", "@typescript-eslint/parser": "^4.23.0", + "babel-loader": "^8.2.2", "clipboard": "^2.0.8", "codejar": "^3.4.0", + "core-js": "^3.12.1", "css-loader": "^5.2.4", "date-fns": "^2.21.3", "eslint": "^7.26.0", diff --git a/webpack.config.js b/webpack.config.js index 3c04412..993aaa9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,14 +7,62 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const { GitRevisionPlugin } = require('git-revision-webpack-plugin'); const gitRevisionPlugin = new GitRevisionPlugin(); - +var babelOptions = { + "presets": [ + [ + "@babel/preset-env", + { + "corejs": { "version": 3 }, + "useBuiltIns": "usage", + "targets": { + "edge": "17", + "firefox": "60", + "chrome": "67", + "safari": "11.1", + "ie": "11" + } + } + ] + ], + "plugins": [ + ["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }], + ["@babel/plugin-proposal-class-properties"], + ["@babel/transform-runtime"] + ] +}; const VERBOSE = Object.getOwnPropertyNames(process.env).includes("VERBOSE") || !true; -const MODE = process.env.WEBPACK_MODE || "production" +const MODE = process.env.WEBPACK_MODE || "production" const DEBUG = MODE != "production"; let commitHash = gitRevisionPlugin.commithash(); +let devrules = [{ test: /\.tsx?$/, loader: "ts-loader" }]; +let prodrules = [{ + test: /\.ts(x?)$/, + exclude: /node_modules/, + use: [ + { + loader: 'babel-loader', + options: babelOptions + }, + { + loader: 'ts-loader' + } + ] +}, +{ + test: /\.js$/, + exclude: /node_modules/, + use: [ + { + loader: 'babel-loader', + options: babelOptions + } + ] +}]; + +console.log("DEBUG:", DEBUG); module.exports = { mode: MODE, @@ -33,8 +81,8 @@ module.exports = { new MiniCssExtractPlugin(), new HtmlWebpackPlugin({ title: "VaultUI" }), new webpack.DefinePlugin({ - BUILD_STRING: - JSON.stringify(`Built At: ${new Date().toString()} by ${os.userInfo().username}@${os.hostname()} on commit ${commitHash}`), + BUILD_STRING: + JSON.stringify(`Built At: ${new Date().toString()} by ${os.userInfo().username}@${os.hostname()} on commit ${commitHash}`), }) ], devServer: { @@ -55,7 +103,7 @@ module.exports = { "sass-loader" ], }, - { test: /\.tsx?$/, loader: "ts-loader" } + ...(DEBUG ? devrules : prodrules), ], }, }; \ No newline at end of file