Skip to content

Commit 940e817

Browse files
author
chengyu.chengyulia
committed
feat: add feat/speedMeasure
1 parent b9579b8 commit 940e817

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@types/semver": "6.2.0",
6666
"@types/socket.io": "2.1.4",
6767
"@types/socket.io-client": "1.4.32",
68+
"@types/speed-measure-webpack-plugin": "1.3.0",
6869
"@types/update-notifier": "2.5.0",
6970
"@types/webpack": "4.41.0",
7071
"@types/webpack-dev-server": "3.9.0",
@@ -139,6 +140,7 @@
139140
"signale": "1.4.0",
140141
"socket.io": "2.3.0",
141142
"socket.io-client": "2.3.0",
143+
"speed-measure-webpack-plugin": "1.3.3",
142144
"style-loader": "1.1.3",
143145
"typescript": "3.8.2",
144146
"update-notifier": "3.0.1",

src/utils/babel-options.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import transformRuntime from '@babel/plugin-transform-runtime';
1414
import babelPresetEnv from '@babel/preset-env';
1515
import babelPresetReact from '@babel/preset-react';
1616
import babelPresetTypescript from '@babel/preset-typescript';
17-
import babelPluginReactCssModules from 'babel-plugin-react-css-modules';
1817
import * as babelPluginReactHotLoader from 'react-hot-loader/babel';
1918
import * as _ from 'lodash';
2019
import { babelPluginReactWrappedDisplayName } from './babel-plugin-react-wrapped-display-name';
@@ -32,6 +31,7 @@ export function getBabelOptions(options?: Partial<DefaultOptions>) {
3231
return {
3332
babelrc: false,
3433
comments: globalState.isDevelopment,
34+
cacheDirectory: true,
3535
presets: [[babelPresetEnv, { modules: mergedOptions.modules }], [babelPresetReact], [babelPresetTypescript]],
3636
plugins: [
3737
[transformRuntime],
@@ -49,24 +49,6 @@ export function getBabelOptions(options?: Partial<DefaultOptions>) {
4949
[babelPluginProposalClassProperties, { loose: true }],
5050
[babelPluginProposalJsonStrings],
5151
[babelPluginProposalOptionalCatchBinding],
52-
// TODO: gulp don't support css module
53-
...(globalState && globalState.sourceConfig && globalState.sourceConfig.type === 'project'
54-
? [
55-
[
56-
babelPluginReactCssModules,
57-
{
58-
filetypes: {
59-
'.scss': {
60-
syntax: 'postcss-scss',
61-
},
62-
'.less': {
63-
syntax: 'postcss-less',
64-
},
65-
},
66-
},
67-
],
68-
]
69-
: []),
7052
...mergedOptions.plugins,
7153
],
7254
};

src/utils/webpack-dev-server.ts

+8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import * as normalizePath from 'normalize-path';
44
import * as open from 'open';
55
import * as path from 'path';
66
import * as urlJoin from 'url-join';
7+
import * as yargs from 'yargs';
78
import * as webpack from 'webpack';
89
import * as WebpackBar from 'webpackbar';
910
import * as CircularDependencyPlugin from 'circular-dependency-plugin';
1011
import * as _ from 'lodash';
1112
import * as WebpackDevServer from 'webpack-dev-server';
13+
import * as SpeedMeasurePlugin from 'speed-measure-webpack-plugin';
1214
import { globalState } from './global-state';
1315
import { tempPath } from './structor-config';
1416
import { logInfo } from './log';
1517
import { getWebpackConfig, IOptions } from './webpack-config';
1618

19+
const smp = new SpeedMeasurePlugin();
20+
1721
interface IExtraOptions {
1822
pipeConfig?: (config?: webpack.Configuration) => Promise<webpack.Configuration>;
1923
devServerPort: number;
@@ -86,6 +90,10 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
8690

8791
WebpackDevServer.addDevServerEntrypoints(webpackConfig as any, webpackDevServerConfig);
8892

93+
if (yargs.argv.measureSpeed) {
94+
webpackConfig = smp.wrap(webpackConfig);
95+
}
96+
8997
const compiler = webpack(webpackConfig);
9098

9199
const devServer = new WebpackDevServer(compiler as any, webpackDevServerConfig);

src/utils/webpack.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import * as webpack from 'webpack';
22
import * as WebpackBar from 'webpackbar';
3+
import * as SpeedMeasurePlugin from 'speed-measure-webpack-plugin';
4+
import * as yargs from 'yargs';
35
import { getWebpackConfig, IOptions } from './webpack-config';
46
import { logWarn } from './log';
57

68
interface IExtraOptions {
79
pipeConfig?: (config?: webpack.Configuration) => Promise<webpack.Configuration>;
810
}
911

12+
const smp = new SpeedMeasurePlugin();
13+
1014
const stats = {
1115
warnings: false,
1216
version: false,
@@ -26,6 +30,10 @@ export const runWebpack = async (opts: IOptions<IExtraOptions>): Promise<any> =>
2630

2731
webpackConfig.plugins.push(new WebpackBar());
2832

33+
if (yargs.argv.measureSpeed) {
34+
webpackConfig = smp.wrap(webpackConfig);
35+
}
36+
2937
const compiler = webpack(webpackConfig);
3038

3139
return runCompiler(compiler);

yarn.lock

+15-13
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,13 @@
18601860
resolved "https://registry.npm.alibaba-inc.com/@types/source-list-map/download/@types/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9"
18611861
integrity sha1-AHiDYGP/rxdBI0m7o2QIfgrALsk=
18621862

1863+
1864+
version "1.3.0"
1865+
resolved "https://registry.npm.alibaba-inc.com/@types/speed-measure-webpack-plugin/download/@types/speed-measure-webpack-plugin-1.3.0.tgz#406a4ba9c087ecbad01266a3c9b206c7bb99bc24"
1866+
integrity sha1-QGpLqcCH7LrQEmajybIGx7uZvCQ=
1867+
dependencies:
1868+
"@types/webpack" "*"
1869+
18631870
"@types/stack-utils@^1.0.1":
18641871
version "1.0.1"
18651872
resolved "https://registry.npm.alibaba-inc.com/@types/stack-utils/download/@types/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@@ -1937,19 +1944,7 @@
19371944
"@types/source-list-map" "*"
19381945
source-map "^0.6.1"
19391946

1940-
"@types/webpack@*":
1941-
version "4.41.7"
1942-
resolved "https://registry.npm.alibaba-inc.com/@types/webpack/download/@types/webpack-4.41.7.tgz#22be27dbd4362b01c3954ca9b021dbc9328d9511"
1943-
integrity sha1-Ir4n29Q2KwHDlUypsCHbyTKNlRE=
1944-
dependencies:
1945-
"@types/anymatch" "*"
1946-
"@types/node" "*"
1947-
"@types/tapable" "*"
1948-
"@types/uglify-js" "*"
1949-
"@types/webpack-sources" "*"
1950-
source-map "^0.6.0"
1951-
1952-
1947+
"@types/webpack@*", "@types/[email protected]":
19531948
version "4.41.0"
19541949
resolved "https://registry.npm.alibaba-inc.com/@types/webpack/download/@types/webpack-4.41.0.tgz#b813a044d8b0dec7dfcd7622fdbe327bde06eb9a"
19551950
integrity sha1-uBOgRNiw3sffzXYi/b4ye94G65o=
@@ -12980,6 +12975,13 @@ spdy@^4.0.1:
1298012975
select-hose "^2.0.0"
1298112976
spdy-transport "^3.0.0"
1298212977

12978+
12979+
version "1.3.3"
12980+
resolved "https://registry.npm.alibaba-inc.com/speed-measure-webpack-plugin/download/speed-measure-webpack-plugin-1.3.3.tgz#6ff894fc83e8a6310dde3af863a0329cd79da4f5"
12981+
integrity sha1-b/iU/IPopjEN3jr4Y6AynNedpPU=
12982+
dependencies:
12983+
chalk "^2.0.1"
12984+
1298312985
split-string@^3.0.1, split-string@^3.0.2:
1298412986
version "3.1.0"
1298512987
resolved "https://registry.npm.alibaba-inc.com/split-string/download/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"

0 commit comments

Comments
 (0)