Switch to Typescript and webpack

This commit is contained in:
Daniel Triendl
2020-11-04 22:59:32 +01:00
parent e40a0810ff
commit 7db79afca2
21 changed files with 14701 additions and 310 deletions

0
config/empty.js Normal file
View File

28
config/metadata.js Normal file
View File

@ -0,0 +1,28 @@
const pkg = require('../package.json')
module.exports = {
name: '3CX TAPI',
namespace: 'http://cp-solutions.at',
version: pkg.version,
author: pkg.author,
copyright: 'Copyright 2020 CP Solutions GmbH',
source: pkg.repository.url,
downloadURL: 'http://scootaloo.cp-austria.at/gitlist/3cx_tapi.git/raw/master/3CX_TAPI.user.js',
match: [
'https://192.168.0.154:5001/webclient*',
'https://cpsolution.my3cx.at:5001/webclient*'
],
require: [
'https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@v1.2/waitForKeyElements.js',
`https://cdn.jsdelivr.net/npm/axios@${pkg.dependencies.axios}/dist/axios.min.js`,
`https://cdn.jsdelivr.net/npm/axios-userscript-adapter@${pkg.dependencies['axios-userscript-adapter']}/dist/axiosGmxhrAdapter.min.js`
],
grant: [
'GM_xmlhttpRequest',
'GM.notification'
],
connect: [
'cpatapi.cpsrvweb2016.cp-austria.at'
],
'run-at': 'document-end'
}

View File

@ -0,0 +1,59 @@
const path = require('path')
const webpack = require('webpack')
const webpackConfig = {
node: {
Buffer: false
},
resolve: {
extensions: ['.js', '.ts']
},
// performance: {
// hints: false
// },
optimization: {
minimize: false
},
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, '../dist')
},
externals: {
axios: 'axios',
'axios-userscript-adapter': 'axiosGmxhrAdapter'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader'
},
{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader'
},
{
test: /\.less$/,
loader: [
'style-loader',
'css-loader',
'less-loader', // 将 Less 编译为 CSS
]
},
{
test: /\.css$/,
loader: [
'style-loader',
'css-loader',
]
}
]
},
plugins: [
new webpack.HashedModuleIdsPlugin()
]
}
module.exports = webpackConfig

View File

@ -0,0 +1,43 @@
const path = require("path");
const { merge } = require("webpack-merge");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const LiveReloadPlugin = require("webpack-livereload-plugin");
const UserScriptMetaDataPlugin = require("userscript-metadata-webpack-plugin");
const metadata = require("./metadata");
const webpackConfig = require("./webpack.config.base");
metadata.require.push(
"file://" + path.resolve(__dirname, "../dist/index.prod.user.js")
);
const cfg = merge(webpackConfig, {
entry: {
prod: webpackConfig.entry,
dev: path.resolve(__dirname, "./empty.js"),
},
output: {
filename: "index.[name].user.js",
path: path.resolve(__dirname, "../dist"),
},
devtool: "inline-source-map",
watch: true,
watchOptions: {
ignored: /node_modules/,
},
plugins: [
new LiveReloadPlugin({
delay: 500,
}),
new UserScriptMetaDataPlugin({
metadata,
}),
],
});
if (process.env.npm_config_report) {
cfg.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = cfg;

View File

@ -0,0 +1,23 @@
const { merge } = require("webpack-merge");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const UserScriptMetaDataPlugin = require('userscript-metadata-webpack-plugin')
const metadata = require('./metadata')
const webpackConfig = require('./webpack.config.base')
const cfg = merge({}, webpackConfig, {
output: {
filename: 'index.prod.user.js'
},
plugins: [
new UserScriptMetaDataPlugin({
metadata
})
]
})
if (process.env.npm_config_report) {
cfg.plugins.push(new BundleAnalyzerPlugin())
}
module.exports = cfg