From 881b2e1fd45141c06f47c9b6bea6e93ae73bddc3 Mon Sep 17 00:00:00 2001 From: Treecat Date: Thu, 13 Apr 2023 14:12:47 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14512=20chore:=20demo=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/demo/package.json | 3 +- packages/demo/webpack.prod.js | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 packages/demo/webpack.prod.js diff --git a/packages/demo/package.json b/packages/demo/package.json index deaabb82e..feadc29f9 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "dev": "webpack-dev-server --open --config=webpack.dev.js" + "dev": "webpack-dev-server --open --config=webpack.dev.js", + "build": "webpack --config=webpack.prod.js" }, "keywords": [], "author": "", diff --git a/packages/demo/webpack.prod.js b/packages/demo/webpack.prod.js new file mode 100644 index 000000000..20bc06a53 --- /dev/null +++ b/packages/demo/webpack.prod.js @@ -0,0 +1,58 @@ +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const path = require('path'); +const TerserPlugin = require("terser-webpack-plugin"); +const webpack = require("webpack"); +const childProcess = require("child_process"); + +function git(command) { + return childProcess.execSync(`git ${command}`).toString().trim(); +} + +module.exports = { + mode: 'production', + entry: { + "demo.min": './src/index.js' + }, + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', + }, + }, + { + test: /\.less$/i, + use: ['style-loader', 'css-loader', 'less-loader'], + }, + ], + }, + devtool: 'source-map', + resolve: { + extensions: ['.js', '.ts'], + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, + optimization: { + usedExports: false, + minimize: true, + minimizer: [ + new TerserPlugin({ + include: /\.min/, + parallel: true, + terserOptions: { + output: { + comments: false, + }, + }, + }), + new webpack.BannerPlugin({ + banner: `time: ${new Date().toLocaleString("en-US")}; branch: ${git( + "name-rev --name-only HEAD" + )} commit: ${git("rev-parse HEAD")}`, + }) + ], + }, +};