From 57a5223a39d53ca26c1515d4cedf2b04324f1c36 Mon Sep 17 00:00:00 2001 From: Treecat Date: Tue, 28 Mar 2023 15:14:54 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14316=20fix:=20bundle=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 10 ++- packages/fineui/package.json | 12 +-- packages/fineui/src/bundle.js | 13 ++-- .../fineui/src/core/platform/web/index.js | 4 +- packages/fineui/src/index.js | 6 +- packages/fineui/webpack.prod.js | 76 ++++++++++--------- 6 files changed, 70 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index cb4d5c201..4a0a2c972 100644 --- a/package.json +++ b/package.json @@ -9,25 +9,33 @@ "dev": "npm-run-all --parallel dev:*", "dev:demo": "cd packages/demo && npm run dev", "dev:fineui": "cd packages/fineui && npm run dev", - "static": "node script/code.static.js" + "build": "cd packages/fineui && npm run build" }, "devDependencies": { "@babel/cli": "^7.21.0", "@babel/core": "^7.21.0", "@babel/runtime": "^7.21.0", "@fui/babel-preset-fineui": "^3.0.1", + "autoprefixer": "^10.4.14", "babel-loader": "^9.1.2", "babel-plugin-module-resolver": "^5.0.0", "css-loader": "^6.7.3", + "fork-ts-checker-webpack-plugin": "^8.0.0", "html-webpack-plugin": "^5.5.0", "less": "^4.1.3", "less-loader": "^11.1.0", + "mini-css-extract-plugin": "^2.7.5", "npm-run-all": "^4.1.5", + "optimize-css-assets-webpack-plugin": "^6.0.1", + "postcss": "^8.4.21", "style-loader": "^3.3.1", + "terser-webpack-plugin": "^5.3.7", "typescript": "^4.9.5", + "uglifyjs-webpack-plugin": "^2.2.0", "webpack": "^5.75.0", "webpack-bundle-analyzer": "^4.8.0", "webpack-cli": "^5.0.1", + "circular-dependency-plugin": "^5.2.2", "webpack-dev-server": "^4.11.1" } } diff --git a/packages/fineui/package.json b/packages/fineui/package.json index a12e7eea4..94b754ef1 100644 --- a/packages/fineui/package.json +++ b/packages/fineui/package.json @@ -1,11 +1,15 @@ { "name": "@fui/core", - "version": "2.0.20230208163847", + "version": "2.0.20230208163847", "description": "fineui", "main": "dist/fineui_without_conflict.min.js", "module": "dist/es/index.js", "types": "dist/type/index.d.ts", + "bin": { + "fui-cli": "./bin/cli/cli.js" + }, "sideEffects": [ + "src/**/*.js", "dist/es/core/*.js", "dist/es/core/element/**/*.js", "dist/es/core/platform/**/*.js", @@ -13,11 +17,9 @@ "dist/es/case/ztree/jquery.ztree.core-3.5.js", "dist/es/case/ztree/jquery.ztree.excheck-3.5.js" ], - "bin": { - "fui-cli": "./bin/cli/cli.js" - }, "scripts": { - "dev": "babel src -d dist/es --config-file ./esm.babel.js -w" + "dev": "babel src -d dist/es --config-file ./esm.babel.js -w", + "build": "webpack --config=webpack.prod.js" }, "repository": { "type": "git", diff --git a/packages/fineui/src/bundle.js b/packages/fineui/src/bundle.js index 4626a6e37..329d5be85 100644 --- a/packages/fineui/src/bundle.js +++ b/packages/fineui/src/bundle.js @@ -1,4 +1,4 @@ -import * as fineui from "./index"; +import * as fuiExport from "./index"; import { shortcut, provider } from "@/core/5.inject"; import { _global } from "@/core/0.foundation"; import * as Decorators from "@/core/decorator"; @@ -6,9 +6,10 @@ import * as Decorators from "@/core/decorator"; _global.BI = _global.BI || {}; _global.BI.Decorators = Decorators; -_global.Fix = fineui.Fix; -_global._ = fineui._; +Object.assign(_global, { + Fix: fuiExport.Fix, + _: fuiExport._, + $: fuiExport.$, +}); -_global.$ = fineui.$; - -Object.assign(_global.BI, fineui, { shortcut, provider }); +Object.assign(_global.BI, fuiExport, { shortcut, provider }); diff --git a/packages/fineui/src/core/platform/web/index.js b/packages/fineui/src/core/platform/web/index.js index 054b6dede..17213f37d 100644 --- a/packages/fineui/src/core/platform/web/index.js +++ b/packages/fineui/src/core/platform/web/index.js @@ -2,5 +2,5 @@ export * from "./detectElementResize"; export * from "./function"; export * from "./load"; -import "./jquery/index"; -import "./config"; + + diff --git a/packages/fineui/src/index.js b/packages/fineui/src/index.js index 65b0a003d..eaae67490 100644 --- a/packages/fineui/src/index.js +++ b/packages/fineui/src/index.js @@ -1,7 +1,11 @@ // sideEffects import "./polyfill"; -import "./core/platform/web/jquery"; import "./core/system"; +import "./core/element"; +import "./core/platform"; +import "./core/platform/web/jquery" +// 必须要等上面的准备好, 才初始化 config +import "./core/platform/web/config"; import _jquery from "jquery"; diff --git a/packages/fineui/webpack.prod.js b/packages/fineui/webpack.prod.js index 074fea17a..a3ea227d8 100644 --- a/packages/fineui/webpack.prod.js +++ b/packages/fineui/webpack.prod.js @@ -1,21 +1,31 @@ -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const path = require('path'); +const webpack = require("webpack"); +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); +const TerserPlugin = require("terser-webpack-plugin"); +const path = require("path"); +const autoprefixer = require("autoprefixer"); +const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); +const CircularDependencyPlugin = require("circular-dependency-plugin"); +const childProcess = require("child_process"); + +function git(command) { + return childProcess.execSync(`git ${command}`).toString().trim(); +} module.exports = { - mode: 'production', - entry: './src/index.js', - devServer: { - port: 3000, - liveReload: true, + mode: "production", + entry: "./src/bundle.js", + output: { + path: path.resolve(__dirname, "dist"), + filename: "[name].js", }, - devtool: 'hidden-source-map', + devtool: false, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { - loader: 'babel-loader', + loader: "babel-loader", }, }, { @@ -23,22 +33,22 @@ module.exports = { use: [ MiniCssExtractPlugin.loader, { - loader: 'css-loader', + loader: "css-loader", options: { url: false, }, }, { - loader: 'postcss-loader', + loader: "postcss-loader", options: { plugins: [autoprefixer], }, }, { - loader: 'less-loader', + loader: "less-loader", options: { relativeUrls: false, - modifyVars: lessVariables, + // modifyVars: lessVariables, }, }, ], @@ -46,32 +56,26 @@ module.exports = { ], }, resolve: { - extensions: ['.js', '.ts'], + extensions: [".js", ".ts"], alias: { - '@': path.resolve(__dirname, '../src'), + "@": path.resolve(__dirname, "src"), }, }, plugins: [ - new MiniCssExtractPlugin({ - path: dirs.DEST, - filename: '[name].css', - }), - new ForkTsCheckerWebpackPlugin({}), - new OptimizeCssAssetsPlugin({ - assetNameRegExp: /\.css$/g, - cssProcessor: require('cssnano'), - cssProcessorPluginOptions: { - preset: [ - 'default', - { - discardComments: { - removeAll: true, - }, - normalizeUnicode: false, - }, - ], - }, - canPrint: true, - }), + new CircularDependencyPlugin(), ], + optimization: { + usedExports: false, + minimize: true, + minimizer: [ + new TerserPlugin({ + include: /\.js$/i, + }), + new webpack.BannerPlugin({ + banner: `time: ${new Date().toLocaleString()}; branch: ${git( + "name-rev --name-only HEAD" + )} commit: ${git("rev-parse HEAD")}`, + }), + ], + }, };