diff --git a/CHANGELOG.md b/CHANGELOG.md index f5e56f7a..4e308c2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ English | [简体中文](./CHANGELOG_CN.md) +## 3.14.2 (2022-03-25) + +- `Fix(Network)` Remove debugging console.log. +- `Chore` Drop `console.log` in Webpack process to ensure that no debugging logs appear in release version. +- `Chore` Add new build command to compile files in different scenarios. + + ## 3.14.1 (2022-03-24) - `Fix(Network)` Fix `responseSize` error when `readyState === 3`. diff --git a/CHANGELOG_CN.md b/CHANGELOG_CN.md index e3090a5a..cee668d7 100644 --- a/CHANGELOG_CN.md +++ b/CHANGELOG_CN.md @@ -1,5 +1,12 @@ [English](./CHANGELOG.md) | 简体中文 +## 3.14.2 (2022-03-25) + +- `Fix(Network)` 删除调试日志。 +- `Chore` 在构建时自动删除 `console.log` 以确保调试日志不会出现在正式版本中。 +- `Chore` 添加新的编译命令以编译出不同场景下的文件。 + + ## 3.14.1 (2022-03-24) - `Fix(Network)` 修复当 `readyState === 3` 时的 `responseSize` 错误。 diff --git a/dev/plugin.html b/dev/plugin.html index b9b7e760..9469fd75 100644 --- a/dev/plugin.html +++ b/dev/plugin.html @@ -18,6 +18,7 @@ newGlobalToolButton newTabUseJQuery newTabUseDOM + newBuiltinTab removePlugin @@ -117,6 +118,16 @@ console.info('newTabUseDOM() End'); } +function newBuiltinTab() { + class MyPlugin extends window.VConsole.VConsoleStoragePlugin { + + } + var plugin = new MyPlugin('tab6', 'Tab6'); + vConsole.addPlugin(plugin); + vConsole.show(); + vConsole.showPlugin('tab6'); +} + const pluginList = ['default', 'system', 'network', 'element', 'storage']; function removePlugin() { console.info('removePlugin() Start'); diff --git a/package-lock.json b/package-lock.json index 6b08f482..21db0e7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vconsole", - "version": "3.14.0", + "version": "3.14.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vconsole", - "version": "3.14.0", + "version": "3.14.2", "license": "MIT", "dependencies": { "@babel/runtime": "^7.17.2", diff --git a/package.json b/package.json index b4192475..da71fa74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vconsole", - "version": "3.14.1", + "version": "3.14.2", "description": "A lightweight, extendable front-end developer tool for mobile web page.", "homepage": "https://github.com/Tencent/vConsole", "files": [ @@ -12,13 +12,20 @@ "main": "dist/vconsole.min.js", "typings": "dist/vconsole.min.d.ts", "scripts": { - "build": "webpack --mode=production --progress", + "build": "webpack --mode=production --progress --env target=web", + "build:wx": "webpack --mode=production --progress --env target=wx", "build:typings": "node ./build/build.typings.js", "build:dev": "webpack --mode=development --progress", "watch": "webpack --mode=development --watch --progress", "serve": "webpack serve --config webpack.serve.config --progress", "test:pack": "npx npm-packlist" }, + "sideEffects": [ + "lib/*", + "element/*", + "network/*", + "storage/*" + ], "keywords": [ "console", "debug", diff --git a/src/core/core.ts b/src/core/core.ts index 9249c9aa..2b3962bc 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -37,12 +37,11 @@ import { VConsoleStoragePlugin } from '../storage/storage'; import { VConsoleLogExporter } from '../log/log.exporter'; import { VConsoleNetworkExporter } from '../network/network.exporter'; - const VCONSOLE_ID = '#__vconsole'; export class VConsole { public version: string = __VERSION__; - public isInited: boolean; + public isInited: boolean = false; public option: VConsoleOptions = {}; protected compInstance: SvelteComponent; @@ -54,13 +53,13 @@ export class VConsole { public network: VConsoleNetworkExporter; // Export static classes - public static VConsolePlugin = VConsolePlugin; - public static VConsoleLogPlugin = VConsoleLogPlugin; - public static VConsoleDefaultPlugin = VConsoleDefaultPlugin; - public static VConsoleSystemPlugin = VConsoleSystemPlugin; - public static VConsoleNetworkPlugin = VConsoleNetworkPlugin; - public static VConsoleElementPlugin = VConsoleElementPlugin; - public static VConsoleStoragePlugin = VConsoleStoragePlugin; + public static VConsolePlugin: typeof VConsolePlugin; + public static VConsoleLogPlugin: typeof VConsoleLogPlugin; + public static VConsoleDefaultPlugin: typeof VConsoleDefaultPlugin; + public static VConsoleSystemPlugin: typeof VConsoleSystemPlugin; + public static VConsoleNetworkPlugin: typeof VConsoleNetworkPlugin; + public static VConsoleElementPlugin: typeof VConsoleElementPlugin; + public static VConsoleStoragePlugin: typeof VConsoleStoragePlugin; constructor(opt?: VConsoleOptions) { if (!!VConsole.instance && VConsole.instance instanceof VConsole) { @@ -163,10 +162,12 @@ export class VConsole { const plugins = { // 'default': { proto: VConsoleSystemPlugin, name: 'Log' }, 'system': { proto: VConsoleSystemPlugin, name: 'System' }, - 'network': { proto: VConsoleNetworkPlugin, name: 'Network' }, - 'element': { proto: VConsoleElementPlugin, name: 'Element' }, - 'storage': { proto: VConsoleStoragePlugin, name: 'Storage' } }; + if (__TARGET__ === 'web') { + plugins['network'] = { proto: VConsoleNetworkPlugin, name: 'Network' }; + plugins['element'] = { proto: VConsoleElementPlugin, name: 'Element' }; + plugins['storage'] = { proto: VConsoleStoragePlugin, name: 'Storage' }; + } if (!!list && tool.isArray(list)) { for (let i = 0; i < list.length; i++) { const pluginConf = plugins[list[i]]; @@ -559,4 +560,16 @@ export class VConsole { } // END class -export default VConsole; + +// Export built-in plugins +VConsole.VConsolePlugin = VConsolePlugin; +VConsole.VConsoleLogPlugin = VConsoleLogPlugin; +VConsole.VConsoleDefaultPlugin = VConsoleDefaultPlugin; +VConsole.VConsoleSystemPlugin = VConsoleSystemPlugin; + +// for tree shaking +if (__TARGET__ === 'web') { + VConsole.VConsoleNetworkPlugin = VConsoleNetworkPlugin; + VConsole.VConsoleElementPlugin = VConsoleElementPlugin; + VConsole.VConsoleStoragePlugin = VConsoleStoragePlugin; +} diff --git a/src/network/beacon.proxy.ts b/src/network/beacon.proxy.ts index afd3b22b..815e3564 100644 --- a/src/network/beacon.proxy.ts +++ b/src/network/beacon.proxy.ts @@ -19,7 +19,7 @@ export class BeaconProxyHandler implement } public apply(target: T, thisArg: T, argsList: any[]) { - console.log('on call!!') + // console.log('on call!!') const urlString: string = argsList[0]; const data: BodyInit = argsList[1]; const item = new VConsoleNetworkRequestItem(); diff --git a/src/network/fetch.proxy.ts b/src/network/fetch.proxy.ts index 4c61d21d..52b8effc 100644 --- a/src/network/fetch.proxy.ts +++ b/src/network/fetch.proxy.ts @@ -195,7 +195,7 @@ export class FetchProxyHandler implements ProxyHandler { - console.log(item.responseType, responseValue) + // console.log(item.responseType, responseValue) item.responseSize = typeof responseValue === 'string' ? responseValue.length : responseValue.byteLength; item.responseSizeText = tool.getBytesText(item.responseSize); item.response = Helper.genResonseByResponseType(item.responseType, responseValue); diff --git a/src/types.d.ts b/src/types.d.ts index bc028f56..f1735771 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,4 +1,5 @@ declare var __VERSION__: string; +declare var __TARGET__: 'web' | 'wx'; declare module '*.html' { const _: string; diff --git a/src/vconsole.ts b/src/vconsole.ts index 09d3bfad..95fa4057 100644 --- a/src/vconsole.ts +++ b/src/vconsole.ts @@ -17,7 +17,7 @@ Unless required by applicable law or agreed to in writing, software distributed import 'core-js/stable/symbol'; import 'core-js/stable/promise'; -// classes +// vConsole Core Class import { VConsole } from './core/core'; // export diff --git a/webpack.config.js b/webpack.config.js index 3422f54f..0471721d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,9 +4,11 @@ const { execSync } = require('child_process'); const TerserPlugin = require('terser-webpack-plugin'); const sveltePreprocess = require('svelte-preprocess'); const pkg = require('./package.json'); +const BuildTarget = ['web', 'wx']; module.exports = (env, argv) => { const isDev = argv.mode === 'development'; + const __TARGET__ = BuildTarget.indexOf(env.target) === -1 ? BuildTarget[0] : env.target; return { mode: argv.mode, devtool: false, @@ -95,18 +97,13 @@ module.exports = (env, argv) => { minimizer: [ new TerserPlugin({ extractComments: false, + terserOptions: { + compress: { + pure_funcs: ['console.log'], // drop `console.log` only + }, + }, }), ], - // splitChunks: { - // cacheGroups: { - // styles: { - // name: "styles", - // type: "css/mini-extract", - // chunks: "all", - // enforce: true, - // }, - // }, - // }, }, watchOptions: { ignored: ['**/node_modules'], @@ -126,6 +123,7 @@ module.exports = (env, argv) => { }), new Webpack.DefinePlugin({ __VERSION__: JSON.stringify(pkg.version), + __TARGET__: JSON.stringify(__TARGET__), }), { apply: (compiler) => {