Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update web page title #310

Merged
merged 4 commits into from Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 90 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -64,6 +64,7 @@
"chai": "4.2.0",
"chai-subset": "1.6.0",
"classnames": "2.2.6",
"copy-webpack-plugin": "^5.0.4",
gaokun marked this conversation as resolved.
Show resolved Hide resolved
"core-js": "2.6.5",
"css-loader": "2.1.1",
"cssnano": "4.1.10",
Expand All @@ -77,7 +78,7 @@
"gulp-babel": "8.0.0",
"mobx": "5.9.4",
"mobx-preact": "3.0.0",
"mocha": "6.1.2",
"mocha": "^6.2.0",
gaokun marked this conversation as resolved.
Show resolved Hide resolved
"nightmare": "3.0.1",
"postcss-icss-values": "2.0.2",
"postcss-loader": "3.0.0",
Expand Down
14 changes: 14 additions & 0 deletions src/utils.js
Expand Up @@ -32,3 +32,17 @@ function createAssetsFilter(excludePatterns) {
return () => true;
}
}

/**
* @desc get string of current time
* format: MM/dd/yyyy HH:mm
* */
exports.getCurrentTime = function () {
const time = new Date();
const year = time.getFullYear();
const month = time.getMonth() + 1;
const day = time.getDate();
const hour = time.getHours();
const minute = time.getMinutes();
return `${month}/${day}/${year} ${hour}:${minute}`;
gaokun marked this conversation as resolved.
Show resolved Hide resolved
};
5 changes: 5 additions & 0 deletions src/viewer.js
Expand Up @@ -10,6 +10,7 @@ const opener = require('opener');
const mkdir = require('mkdirp');
const {bold} = require('chalk');

const utils = require('./utils');
const Logger = require('./Logger');
const analyzer = require('./analyzer');

Expand All @@ -23,6 +24,8 @@ module.exports = {
start: startServer
};

const title = `${process.env.npm_package_name || 'Webpack Bundle Analyzer'} [${utils.getCurrentTime()}]`;
gaokun marked this conversation as resolved.
Show resolved Hide resolved

async function startServer(bundleStats, opts) {
const {
port = 8888,
Expand Down Expand Up @@ -52,6 +55,7 @@ async function startServer(bundleStats, opts) {
app.use('/', (req, res) => {
res.render('viewer', {
mode: 'server',
title,
get chartData() { return chartData },
defaultSizes,
enableWebSocket: true,
Expand Down Expand Up @@ -133,6 +137,7 @@ async function generateReport(bundleStats, opts) {
`${projectRoot}/views/viewer.ejs`,
{
mode: 'static',
title,
chartData,
defaultSizes,
enableWebSocket: false,
Expand Down
Binary file added views/favicon.ico
Binary file not shown.
3 changes: 2 additions & 1 deletion views/viewer.ejs
Expand Up @@ -3,7 +3,8 @@
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Webpack Bundle Analyzer</title>
<title><%- title %></title>
gaokun marked this conversation as resolved.
Show resolved Hide resolved
<link rel="icon" href="favicon.ico">
gaokun marked this conversation as resolved.
Show resolved Hide resolved

<%- include('script', { filename: 'viewer.js' }) %>
</head>
Expand Down
9 changes: 9 additions & 0 deletions webpack.config.js
@@ -1,6 +1,7 @@
const compact = require('lodash/compact');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const BundleAnalyzePlugin = require('./lib/BundleAnalyzerPlugin');

module.exports = opts => {
Expand Down Expand Up @@ -143,6 +144,14 @@ module.exports = opts => {
);
}

plugins.push(new CopyWebpackPlugin([
gaokun marked this conversation as resolved.
Show resolved Hide resolved
{
from: `${__dirname}/views/favicon.ico`,
to: `${__dirname}/public`,
}
])
);

return plugins;
})([])
};
Expand Down