Skip to content

Commit e7dc1e6

Browse files
author
Maiz
committed
refactor(Global): Lazy load style tag when vConsole init; Use this || self as globalObject. (issue Tencent#441)
1 parent ab2ae13 commit e7dc1e6

File tree

5 files changed

+73
-56
lines changed

5 files changed

+73
-56
lines changed

CHANGELOG.md

+56-53
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ English | [简体中文](./CHANGELOG_CN.md)
33
#### 3.10.0-rc (2021-11-xx)
44

55
- `Feat(Log)` Add support for `BigInt` and update `Symbol` log style.
6-
- `Fix(Network)` Fix `URIError` when decode URI fail. (issue #470)
6+
- `Refactor(Global)` Lazy load style tag when vConsole init; Use `this || self` as `globalObject`. (issue #441)
77
- `Fix(Log)` Fix "Cannot convert a Symbol value to a string" error when logged a `symbol` value.
8+
- `Fix(Log)` Now commands and output logs can be copied.
9+
- `Fix(Network)` Fix `URIError` when decode URI fail. (issue #470)
10+
- `Fix(Network)` Fix potential `forEach` error. (issue #471)
811

912

1013
#### 3.9.4 (2021-10-26)
@@ -100,8 +103,8 @@ English | [简体中文](./CHANGELOG_CN.md)
100103

101104
#### 3.5.0 (2021-04-28)
102105

103-
- `Feature(Log)` Add ability to copy a single line of logs. (by @akai)
104-
- `Feature(Plugin)` New third-party plugin [vconsole-vue-devtools-plugin](https://github.com/Zippowxk/vue-vconsole-devtools). (by @Zippowxk)
106+
- `Feat(Log)` Add ability to copy a single line of logs. (by @akai)
107+
- `Feat(Plugin)` New third-party plugin [vconsole-vue-devtools-plugin](https://github.com/Zippowxk/vue-vconsole-devtools). (by @Zippowxk)
105108
- `Perf(System)` Rename "System" field to "Client", and add `MacOS` version.
106109
- `Fix(Log)` Use natural sorting to sort object and array's keys. (issue #372)
107110
- `Fix(Network)` Fix JSON parse error when `contentType` is `text/html`. (by @zimv)
@@ -110,7 +113,7 @@ English | [简体中文](./CHANGELOG_CN.md)
110113

111114
#### V3.4.1 (2021-04-09)
112115

113-
- `Feature(Global)` Add `setSwitchPosition(x, y)` method to update the position of switch button, see [Public Properties & Methods](./doc/public_properties_methods.md) for more details.
116+
- `Feat(Global)` Add `setSwitchPosition(x, y)` method to update the position of switch button, see [Public Properties & Methods](./doc/public_properties_methods.md) for more details.
114117
- `Perf(Global)` Add `Symbol` polyfill. (issue #361)
115118
- `Fix(Global)` Update theme style after `setOption()`.
116119
- `Fix(Global)` Remove `transitionEnd` to prevent compatibility issues. (issue #364)
@@ -120,14 +123,14 @@ English | [简体中文](./CHANGELOG_CN.md)
120123

121124
#### V3.4.0 (2021-01-14)
122125

123-
- `Feature(Global)` Add darkmode theme, see `vConsole.option.theme` in [Public Properties & Methods](./doc/public_properties_methods.md). (PR #307 by @progrape)
124-
- `Feature(Global)` Add safe area to switch button. (issue #353)
125-
- `Feature(Log)` Auto move input cursor to the bracket after autocomplete command. (issue #293)
126-
- `Feature(System)` Add `Location` info to System tab. (issue #343)
127-
- `Feature(Network)` Add `fetch` log in Network tab. (by @weiqian93)
128-
- `Feature(Network)` Add Request Headers to Network tab.
129-
- `Feature(Network)` Use short URL and display parameters in Network tab. (issue #291)
130-
- `Feature(Plugin)` New third-party plugin [vconsole-stats-plugin](https://github.com/smackgg/vConsole-Stats). (by @smackgg)
126+
- `Feat(Global)` Add darkmode theme, see `vConsole.option.theme` in [Public Properties & Methods](./doc/public_properties_methods.md). (PR #307 by @progrape)
127+
- `Feat(Global)` Add safe area to switch button. (issue #353)
128+
- `Feat(Log)` Auto move input cursor to the bracket after autocomplete command. (issue #293)
129+
- `Feat(System)` Add `Location` info to System tab. (issue #343)
130+
- `Feat(Network)` Add `fetch` log in Network tab. (by @weiqian93)
131+
- `Feat(Network)` Add Request Headers to Network tab.
132+
- `Feat(Network)` Use short URL and display parameters in Network tab. (issue #291)
133+
- `Feat(Plugin)` New third-party plugin [vconsole-stats-plugin](https://github.com/smackgg/vConsole-Stats). (by @smackgg)
131134
- `Fix(Global)` The position of the switch button will be reset by mistake when clicked.
132135
- `Fix(Global)` Fix `document.documentElement.offsetHeight|offsetWidth` is unreliable in newer browsers. (PR #314 by @littlee)
133136
- `Fix(Global)` Prevent dispatchEvent for disabled or readOnly elements. (PR #314 by @norux)
@@ -141,31 +144,31 @@ English | [简体中文](./CHANGELOG_CN.md)
141144

142145
#### V3.3.4 (2019-08-19)
143146

144-
- `Feature(Log)` Add `%c` log format to support custom log style, see [Tutorial](./doc/tutorial.md) for more details.
145-
- `Feature(Plugin)` Add `VConsole.VConsoleLogPlugin` (`VConsole.VConsole*` plugins etc.) to `VConsole` class.
147+
- `Feat(Log)` Add `%c` log format to support custom log style, see [Tutorial](./doc/tutorial.md) for more details.
148+
- `Feat(Plugin)` Add `VConsole.VConsoleLogPlugin` (`VConsole.VConsole*` plugins etc.) to `VConsole` class.
146149
- `Fix(Global)` Fix a few minor issues. (#267 by @Molunerfinn, #272 by @domom)
147150
- `Fix(Storage)` Fix remove cookie fail when it is set path=/ or top domain. (#264 by @qianxinfeng)
148151
- `Perf(Global)` Display vConsole on `window DOMContentLoaded` instead of `window load`.
149152

150153

151154
#### V3.3.2 (2019-07-04)
152155

153-
- `Feature(Global)` Add TypeScript definition file. (by @jas0ncn)
156+
- `Feat(Global)` Add TypeScript definition file. (by @jas0ncn)
154157
- `Fix(Log)` Avoid scrolling to bottom when away from bottom edge. (by @ele828)
155158
- `Fix(Global)` Fix switch button position issue. (by @rexschuang)
156159
- `Fix(Global)` Fix a few minor issues. (by @stenders)
157160

158161

159162
#### V3.3.0 (2019-02-02)
160163

161-
- `Feature(Log)` Add the ability to collapse the same log.
164+
- `Feat(Log)` Add the ability to collapse the same log.
162165
- `Fix(Log)` Fix issue which formatted log (like `console.log('[foo]', 'bar')`) will not display in Log tab.
163166

164167

165168
#### V3.2.2 (2019-01-17)
166169

167-
- `Feature` Add console command prompt. (by @65147400)
168-
- `Feature` Add SessionStorage support in Storage tab. (by @hkc452)
170+
- `Feat` Add console command prompt. (by @65147400)
171+
- `Feat` Add SessionStorage support in Storage tab. (by @hkc452)
169172
- `Fix` Fix `JSON.stringify` function which was incorrectly rewritten.
170173
- `Fix` Fix `logNumber` bug which was not reset when clear logs. (by @liuyuekeng)
171174
- `Fix` Fix unencoded HTML tag in Network tab. (by @mokang)
@@ -176,18 +179,18 @@ English | [简体中文](./CHANGELOG_CN.md)
176179

177180
#### V3.2.0 (2018-04-10)
178181

179-
- `Feature` Support `console.time()` and `console.timeEnd()`.
180-
- `Feature` Add `disableLogScrolling` (in `vConsole.option`).
182+
- `Feat` Support `console.time()` and `console.timeEnd()`.
183+
- `Feat` Add `disableLogScrolling` (in `vConsole.option`).
181184
- `Fix` Fix `setOption()` error.
182185
- `Fix` Fix cookies' value wrong display.
183186
- `Fix` Fix "Uncaught InvalidStateError". (by @fireyy)
184187

185188

186189
#### V3.1.0 (2017-12-27)
187190

188-
- `Feature` Add `vConsole.showSwitch()` and `vConsole.hideSwitch()` methods, see [Public Properties & Methods](./doc/public_properties_methods.md).
189-
- `Feature` Add `onReady` and `onClearLog` callback function to `vConsole.option`.
190-
- `Feature` Auto clear logs when `console.clear()` is called.
191+
- `Feat` Add `vConsole.showSwitch()` and `vConsole.hideSwitch()` methods, see [Public Properties & Methods](./doc/public_properties_methods.md).
192+
- `Feat` Add `onReady` and `onClearLog` callback function to `vConsole.option`.
193+
- `Feat` Auto clear logs when `console.clear()` is called.
191194
- `Fix` Fix `\r` error when build in Windows.
192195
- `Fix` Fix `Symbol` error in iOS8 or other old OS.
193196

@@ -196,31 +199,31 @@ English | [简体中文](./CHANGELOG_CN.md)
196199

197200
Basic:
198201

199-
- `Feature` Require manual init vConsole `var vConsole = new VConsole(option)`.
200-
- `Feature` Add configuaration `vConsole.option`, which can be set when `new VConsole` or `setOption(key, value)`.
201-
- `Feature` Support for custom loading of default built-in plugins by using `defaultPlugins` in the above option.
202-
- `Feature` Add `setOption(key, value)` method.
202+
- `Feat` Require manual init vConsole `var vConsole = new VConsole(option)`.
203+
- `Feat` Add configuaration `vConsole.option`, which can be set when `new VConsole` or `setOption(key, value)`.
204+
- `Feat` Support for custom loading of default built-in plugins by using `defaultPlugins` in the above option.
205+
- `Feat` Add `setOption(key, value)` method.
203206
- `Perf` Support CSP rule `unsafe-eval` and `unsafe-inline`.
204207
- `Perf` Optimize `font-size` when `initial-scale < 1`.
205208

206209
Log plugin:
207210

208-
- `Feature` Support `maxLogNumber` option to limit maximum log number.
211+
- `Feat` Support `maxLogNumber` option to limit maximum log number.
209212
- `Fix` Fix the crash caused by printing large objects.
210213
- `Perf` Only the logs written as `console.log('[system]', xxx)` will be shown in System tab, so `console.log('[system] xxx')` will be shown in default log tab.
211214

212215
Network plugin:
213216

214-
- `Feature` Support `Query String Parameters` and `Form Data`.
217+
- `Feat` Support `Query String Parameters` and `Form Data`.
215218
- `Perf` Auto format JSON response.
216219
- `Fix` Fix bug that XHR status is always "Pending" when using 3rd HTTP libraries.
217220

218221
Plugins:
219222

220-
- `Feature` Plugins can get vConsole instance by `this.vConsole` on/after `init` event is called.
221-
- `Feature` Add `updateOption` event to detect `vConsole.option` changes.
222-
- `Feature` Add Element tab as a built-in plugin.
223-
- `Feature` Add Storage tab as a built-in plugin.
223+
- `Feat` Plugins can get vConsole instance by `this.vConsole` on/after `init` event is called.
224+
- `Feat` Add `updateOption` event to detect `vConsole.option` changes.
225+
- `Feat` Add Element tab as a built-in plugin.
226+
- `Feat` Add Storage tab as a built-in plugin.
224227

225228

226229

@@ -240,16 +243,16 @@ Plugins:
240243

241244
#### V2.5.0 (2016-09-28)
242245

243-
- `Feature` Add `vConsole.removePlugin()` method, see [Public Properties & Methods](./doc/public_properties_methods.md).
244-
- `Feature` Add `remove` plugin event, see [Plugin: Event List](./doc/plugin_event_list.md).
246+
- `Feat` Add `vConsole.removePlugin()` method, see [Public Properties & Methods](./doc/public_properties_methods.md).
247+
- `Feat` Add `remove` plugin event, see [Plugin: Event List](./doc/plugin_event_list.md).
245248
- `Perf` Disable page scrolling while vConsole is scrolling.
246249
- `Fix` Fix `window.onerror()` typo.
247250

248251

249252
#### V2.4.0 (2016-08-31)
250253

251-
- `Feature` Add `addTopBar` plugin event, see [Plugin: Event List](./doc/plugin_event_list.md).
252-
- `Feature` Add log type filter to Log & System tab.
254+
- `Feat` Add `addTopBar` plugin event, see [Plugin: Event List](./doc/plugin_event_list.md).
255+
- `Feat` Add log type filter to Log & System tab.
253256
- `Perf` Log list will not automatically scroll to bottom while printing new logs if the viewport is not at the end of list.
254257
- `Perf` Fix UI bugs.
255258
- `Fix` Fix XSS issue when print object logs.
@@ -264,27 +267,27 @@ Plugins:
264267

265268
#### V2.3.0 (2016-08-15)
266269

267-
- `Feature` Objects or Arrays can be expended layer by layer.
268-
- `Feature` All object's properties, including private properties, can be enumerable now.
270+
- `Feat` Objects or Arrays can be expended layer by layer.
271+
- `Feat` All object's properties, including private properties, can be enumerable now.
269272
- `Perf` Support `tap` event within vConsole's DOM container to speed up `click` event.
270273

271274

272275
#### V2.2.1 (2016-08-08)
273276

274277
- `Perf` Add complete performance timing log to System tab.
275-
- `Feature` Add third-party plugin list to README.
278+
- `Feat` Add third-party plugin list to README.
276279

277280

278281
#### V2.2.0 (2016-07-13)
279282

280-
- `Feature` Add `vConsole.version` property.
281-
- `Feature` Add `xhr._noVConsole` property to `XMLHttpRequest` objects to customize whether a XHR should display in Network tab.
283+
- `Feat` Add `vConsole.version` property.
284+
- `Feat` Add `xhr._noVConsole` property to `XMLHttpRequest` objects to customize whether a XHR should display in Network tab.
282285

283286

284287
#### V2.1.0 (2016-06-29)
285288

286-
- `Feature` Add `vConsole.tool` & `vConsole.$` helper functions, see [Helper Functions](./doc/helper_functions.md).
287-
- `Feature` Public properties & methods of vConsole are available, see [Public Properties & Methods](./doc/public_properties_methods.md).
289+
- `Feat` Add `vConsole.tool` & `vConsole.$` helper functions, see [Helper Functions](./doc/helper_functions.md).
290+
- `Feat` Public properties & methods of vConsole are available, see [Public Properties & Methods](./doc/public_properties_methods.md).
288291
- `Fix` Fix issue that `error` in `window.onerror()` may be undefined.
289292
- `Fix` Fix error that `xhr.status` may be unavailable when `xhr.readyState < 4`.
290293

@@ -299,10 +302,10 @@ Plugins:
299302

300303
#### v2.0.0 (2016-06-05)
301304

302-
- `Feature` Rebuild completely, support custom plugin, see [Plugin: Getting Started](./doc/plugin_getting_started.md).
303-
- `Feature` Support execute JS command line in Log tab.
304-
- `Feature` Support circular structure object in Log and System tab.
305-
- `Feature` Support viewing request headers and response in Network tab.
305+
- `Feat` Rebuild completely, support custom plugin, see [Plugin: Getting Started](./doc/plugin_getting_started.md).
306+
- `Feat` Support execute JS command line in Log tab.
307+
- `Feat` Support circular structure object in Log and System tab.
308+
- `Feat` Support viewing request headers and response in Network tab.
306309
- `Perf` Switch button will not be dragged out of screen.
307310
- `Perf` Auto print User Agent in System tab.
308311
- `Perf` Show log's time in Log and System tab.
@@ -315,7 +318,7 @@ Plugins:
315318

316319
#### v1.3.0 (2016-05-20)
317320

318-
- `Feature` Support Drag and Drop switch button.
321+
- `Feat` Support Drag and Drop switch button.
319322
- `Fix` Fix initialization failure when loaded asynchronously.
320323

321324

@@ -326,17 +329,17 @@ Plugins:
326329

327330
#### v1.2.0 (2016-05-11)
328331

329-
- `Feature` Add network panel.
330-
- `Feature` Deprecate `vConsole.ready()` method.
332+
- `Feat` Add network panel.
333+
- `Feat` Deprecate `vConsole.ready()` method.
331334
- `Perf` Display formatted Object & Array variable.
332335
- `Perf` Add English README and CHANGELOG.
333336
- `Perf` Improve UI.
334337

335338

336339
#### v1.1.0 (2016-05-06)
337340

338-
- `Feature` Support `window.onerror()` to catch exceptions and errors.
339-
- `Feature` Support `[default|system|...]` string to print logs to specific panel.
341+
- `Feat` Support `window.onerror()` to catch exceptions and errors.
342+
- `Feat` Support `[default|system|...]` string to print logs to specific panel.
340343

341344

342345
#### v1.0.5 (2016-04-29)

dev/node.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('../dist/vconsole.min');
2+
console.log(VConsole);

src/core/core.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Unless required by applicable law or agreed to in writing, software distributed
1616
import * as tool from '../lib/tool';
1717
import $ from '../lib/query';
1818

19-
import './core.less';
19+
import coreStyle from './core.less';
2020
import tpl from './core.html';
2121
import tplTabbar from './tabbar.html';
2222
import tplTabbox from './tabbox.html';
@@ -82,6 +82,9 @@ class VConsole {
8282
}
8383
const that = this;
8484

85+
// styles
86+
coreStyle.use();
87+
8588
// @ts-ignore
8689
this.version = __VERSION__;
8790
this.$dom = null;

src/types.d.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
declare module '*.html' {
22
const _: string;
33
export default _;
4-
}
4+
}
5+
6+
declare module '*.less' {
7+
const use: () => void;
8+
export { use };
9+
}

webpack.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = (env, argv) => {
2323
umdNamedDefine: true,
2424
export: "default",
2525
},
26+
globalObject: 'this || self',
2627
},
2728
resolve: {
2829
extensions: ['.ts', '.js', '.html', '.less', '.mjs', '.svelte'],
@@ -51,7 +52,10 @@ module.exports = (env, argv) => {
5152
test: /\.(less|css)$/i,
5253
// loader: 'style-loader!css-loader!less-loader'
5354
use: [
54-
{ loader: 'style-loader' },
55+
{
56+
loader: 'style-loader',
57+
options: { injectType: 'lazySingletonStyleTag' },
58+
},
5559
{ loader: 'css-loader' },
5660
{
5761
loader: 'less-loader',

0 commit comments

Comments
 (0)