1
0
Fork 0

Use babel to transpile.

This commit is contained in:
Kitteh 2021-05-16 13:21:54 +01:00
parent 6edd037f8d
commit f4ab8f212e
2 changed files with 61 additions and 5 deletions

View file

@ -1,12 +1,20 @@
{ {
"devDependencies": { "devDependencies": {
"@babel/core": "^7.14.2",
"@babel/eslint-parser": "^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/prismjs": "^1.16.5",
"@types/uikit": "^3.3.1", "@types/uikit": "^3.3.1",
"@typescript-eslint/eslint-plugin": "^4.23.0", "@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0", "@typescript-eslint/parser": "^4.23.0",
"babel-loader": "^8.2.2",
"clipboard": "^2.0.8", "clipboard": "^2.0.8",
"codejar": "^3.4.0", "codejar": "^3.4.0",
"core-js": "^3.12.1",
"css-loader": "^5.2.4", "css-loader": "^5.2.4",
"date-fns": "^2.21.3", "date-fns": "^2.21.3",
"eslint": "^7.26.0", "eslint": "^7.26.0",

View file

@ -7,14 +7,62 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const { GitRevisionPlugin } = require('git-revision-webpack-plugin'); const { GitRevisionPlugin } = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin(); 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 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"; const DEBUG = MODE != "production";
let commitHash = gitRevisionPlugin.commithash(); 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 = { module.exports = {
mode: MODE, mode: MODE,
@ -33,8 +81,8 @@ module.exports = {
new MiniCssExtractPlugin(), new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({ title: "VaultUI" }), new HtmlWebpackPlugin({ title: "VaultUI" }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
BUILD_STRING: BUILD_STRING:
JSON.stringify(`Built At: ${new Date().toString()} by ${os.userInfo().username}@${os.hostname()} on commit ${commitHash}`), JSON.stringify(`Built At: ${new Date().toString()} by ${os.userInfo().username}@${os.hostname()} on commit ${commitHash}`),
}) })
], ],
devServer: { devServer: {
@ -55,7 +103,7 @@ module.exports = {
"sass-loader" "sass-loader"
], ],
}, },
{ test: /\.tsx?$/, loader: "ts-loader" } ...(DEBUG ? devrules : prodrules),
], ],
}, },
}; };