2023-10-25 22:32:15 +02:00
|
|
|
const webpack = require("webpack");
|
2023-08-22 06:37:04 +02:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const LodashModuleReplacementPlugin = require("lodash-webpack-plugin");
|
2023-10-25 22:32:15 +02:00
|
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
|
|
|
const webpackMerge = require("webpack-merge");
|
2022-06-08 02:25:35 +02:00
|
|
|
const path = require("path");
|
2023-10-25 22:32:15 +02:00
|
|
|
const moment = require("dayjs");
|
|
|
|
const VERSION = require("../version.js");
|
2022-06-08 02:25:35 +02:00
|
|
|
|
2023-10-25 22:32:15 +02:00
|
|
|
function makeBuildStr() {
|
|
|
|
let buildStr = moment().format("YYYYMMDD-HHmmss");
|
|
|
|
// console.log("waveterm:web " + VERSION + " build " + buildStr);
|
|
|
|
return buildStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BUILD = makeBuildStr();
|
|
|
|
|
|
|
|
let BundleAnalyzerPlugin = null;
|
|
|
|
if (process.env.WEBPACK_ANALYZE) {
|
|
|
|
BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
var webCommon = {
|
2022-06-08 02:25:35 +02:00
|
|
|
entry: {
|
2023-10-26 03:45:14 +02:00
|
|
|
waveterm: ["./src/index.ts", "./src/app/app.less"],
|
2022-06-08 02:25:35 +02:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
// exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: "babel-loader",
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
"@babel/preset-env",
|
|
|
|
{
|
2023-08-22 06:37:04 +02:00
|
|
|
targets:
|
|
|
|
"defaults and not ie > 0 and not op_mini all and not op_mob > 0 and not kaios > 0 and not and_qq > 0 and not and_uc > 0 and not baidu > 0",
|
2022-06-08 02:25:35 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
"@babel/preset-react",
|
2023-08-22 06:37:04 +02:00
|
|
|
"@babel/preset-typescript",
|
|
|
|
],
|
2022-06-08 02:25:35 +02:00
|
|
|
plugins: [
|
2023-08-22 06:37:04 +02:00
|
|
|
["@babel/transform-runtime", { regenerator: true }],
|
2022-06-08 02:25:35 +02:00
|
|
|
"@babel/plugin-transform-react-jsx",
|
2023-08-22 06:37:04 +02:00
|
|
|
["@babel/plugin-proposal-decorators", { legacy: true }],
|
|
|
|
["@babel/plugin-proposal-class-properties", { loose: true }],
|
|
|
|
["@babel/plugin-proposal-private-methods", { loose: true }],
|
|
|
|
["@babel/plugin-proposal-private-property-in-object", { loose: true }],
|
2022-06-08 02:25:35 +02:00
|
|
|
"babel-plugin-jsx-control-statements",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2023-08-22 06:37:04 +02:00
|
|
|
use: ["style-loader", "css-loader"],
|
2022-06-08 02:25:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.less$/,
|
2023-08-22 06:37:04 +02:00
|
|
|
use: [{ loader: MiniCssExtractPlugin.loader }, "css-loader", "less-loader"],
|
2022-06-08 02:25:35 +02:00
|
|
|
},
|
2023-09-30 21:13:40 +02:00
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
2023-10-28 22:18:31 +02:00
|
|
|
use: [{ loader: "@svgr/webpack", options: { icon: true, svgo: false } }, "file-loader"],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.md$/,
|
2023-11-01 09:26:19 +01:00
|
|
|
type: "asset/source",
|
2023-10-28 22:18:31 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif)$/i,
|
2023-11-01 09:26:19 +01:00
|
|
|
type: "asset/resource",
|
2023-09-30 21:13:40 +02:00
|
|
|
},
|
2023-08-22 06:37:04 +02:00
|
|
|
],
|
2022-06-08 02:25:35 +02:00
|
|
|
},
|
2023-10-25 22:32:15 +02:00
|
|
|
resolve: {
|
|
|
|
extensions: [".ts", ".tsx", ".js", ".mjs", ".cjs", ".wasm", ".json", ".less", ".css"],
|
2024-02-13 07:47:51 +01:00
|
|
|
alias: {
|
|
|
|
"@/app": path.resolve(__dirname, "../src/app/"),
|
|
|
|
"@/util": path.resolve(__dirname, "../src/util/"),
|
|
|
|
"@/models": path.resolve(__dirname, "../src/models/"),
|
|
|
|
"@/common": path.resolve(__dirname, "../src/app/common/"),
|
|
|
|
"@/elements": path.resolve(__dirname, "../src/app/common/elements/"),
|
|
|
|
"@/modals": path.resolve(__dirname, "../src/app/common/modals/"),
|
|
|
|
"@/assets": path.resolve(__dirname, "../src/app/assets/"),
|
|
|
|
"@/plugins": path.resolve(__dirname, "../src/plugins/"),
|
|
|
|
},
|
2023-10-25 22:32:15 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var webDev = webpackMerge.merge(webCommon, {
|
|
|
|
mode: "development",
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, "../dist-dev"),
|
|
|
|
filename: "[name].js",
|
|
|
|
},
|
|
|
|
devtool: "source-map",
|
|
|
|
devServer: {
|
|
|
|
static: {
|
|
|
|
directory: path.join(__dirname, "../public"),
|
|
|
|
},
|
|
|
|
port: 9000,
|
|
|
|
headers: {
|
|
|
|
"Cache-Control": "no-store",
|
|
|
|
},
|
|
|
|
},
|
2022-06-08 02:25:35 +02:00
|
|
|
plugins: [
|
2023-08-22 06:37:04 +02:00
|
|
|
new MiniCssExtractPlugin({ filename: "[name].css", ignoreOrder: true }),
|
2022-11-02 05:18:40 +01:00
|
|
|
new LodashModuleReplacementPlugin(),
|
2023-10-25 22:32:15 +02:00
|
|
|
new webpack.DefinePlugin({
|
2023-11-01 09:26:19 +01:00
|
|
|
__WAVETERM_DEV__: "true",
|
|
|
|
__WAVETERM_VERSION__: JSON.stringify(VERSION),
|
|
|
|
__WAVETERM_BUILD__: JSON.stringify("devbuild"),
|
2023-10-25 22:32:15 +02:00
|
|
|
}),
|
2022-06-08 02:25:35 +02:00
|
|
|
],
|
2023-10-25 22:32:15 +02:00
|
|
|
watchOptions: {
|
|
|
|
aggregateTimeout: 200,
|
2022-06-08 02:25:35 +02:00
|
|
|
},
|
2023-10-25 22:32:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var webProd = webpackMerge.merge(webCommon, {
|
|
|
|
mode: "production",
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, "../dist"),
|
|
|
|
filename: "[name].js",
|
|
|
|
},
|
2023-11-01 09:26:19 +01:00
|
|
|
devtool: "source-map",
|
2023-10-25 22:32:15 +02:00
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({ filename: "[name].css", ignoreOrder: true }),
|
|
|
|
new LodashModuleReplacementPlugin(),
|
|
|
|
new webpack.DefinePlugin({
|
2023-11-01 09:26:19 +01:00
|
|
|
__WAVETERM_DEV__: "false",
|
|
|
|
__WAVETERM_VERSION__: JSON.stringify(VERSION),
|
|
|
|
__WAVETERM_BUILD__: JSON.stringify(BUILD),
|
2023-10-25 22:32:15 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (BundleAnalyzerPlugin != null) {
|
|
|
|
webProd.plugins.push(new BundleAnalyzerPlugin());
|
|
|
|
}
|
|
|
|
|
2023-10-28 22:18:31 +02:00
|
|
|
module.exports = { webDev: webDev, webProd: webProd };
|