Skip to content

Commit

Permalink
html: update webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed May 17, 2019
1 parent 3f21d86 commit ccea4d2
Show file tree
Hide file tree
Showing 8 changed files with 3,077 additions and 4,955 deletions.
20 changes: 9 additions & 11 deletions html/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const gulp = require('gulp'),
clean = require('gulp-clean'),
inlinesource = require('gulp-inline-source');
const { src, dest, task } = require("gulp");
const clean = require('gulp-clean');
const inlinesource = require('gulp-inline-source');

gulp.task('clean', function () {
return gulp.src('dist', {read: false})
task('clean', () => {
return src('dist', {read: false, allowEmpty: true})
.pipe(clean());
});

gulp.task('inlinesource', function () {
return gulp.src('dist/index.html')
task('default', () => {
return src('dist/index.html')
.pipe(inlinesource())
.pipe(gulp.dest('../src/'));
});

gulp.task('default', ['inlinesource']);
.pipe(dest('../src/'));
});
11 changes: 6 additions & 5 deletions html/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import '../sass/app.scss';

import { Terminal, ITerminalOptions, IDisposable } from 'xterm';
import * as fit from 'xterm/lib/addons/fit/fit'
import * as Zmodem from 'zmodem.js/src/zmodem_browser';

import * as overlay from './overlay'
import { Modal } from './zmodem'
import * as Zmodem from 'zmodem.js/src/zmodem_browser';
import * as urljoin from 'url-join';

Terminal.applyAddon(fit);
Terminal.applyAddon(overlay);
Expand All @@ -29,7 +29,8 @@ declare let window: IWindowWithTerminal;
const modal = new Modal();
const terminalContainer = document.getElementById('terminal-container');
const protocol = window.location.protocol === 'https:' ? 'wss://': 'ws://';
const url = urljoin(protocol, window.location.host, window.location.pathname, 'ws', window.location.search);
const wsPath = window.location.pathname.endsWith('/') ? 'ws' : '/ws';
const url = [protocol, window.location.host, window.location.pathname, wsPath, window.location.search].join('');
const textDecoder = new TextDecoder();
const textEncoder = new TextEncoder();

Expand Down Expand Up @@ -153,7 +154,7 @@ let openWs = function() {
// https://stackoverflow.com/a/27923937/1727928
window.addEventListener('resize', () => {
clearTimeout(window.resizeTimeout);
window.resizeTimeout = setTimeout(() => term.fit(), 250);
window.resizeTimeout = <number><any>setTimeout(() => term.fit(), 250);
});
window.addEventListener('beforeunload', unloadCallback);

Expand Down Expand Up @@ -209,7 +210,7 @@ let openWs = function() {
window.removeEventListener('beforeunload', unloadCallback);
// 1000: CLOSE_NORMAL
if (event.code !== 1000 && autoReconnect > 0) {
term.reconnectTimeout = setTimeout(openWs, autoReconnect * 1000);
term.reconnectTimeout = <number><any>setTimeout(openWs, autoReconnect * 1000);
}
};
};
Expand Down
36 changes: 17 additions & 19 deletions html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@
"author": "Shuanglei Tao <tsl0922@gmail.com>",
"license": "MIT",
"scripts": {
"build": "NODE_ENV=production webpack --config webpack.prod.js && gulp",
"start": "gulp clean && webpack-serve webpack.dev.js"
"build": "NODE_ENV=production npx wp --config webpack.prod.js && gulp",
"start": "gulp clean && npx webpack-dev-server --config webpack.dev.js"
},
"dependencies": {
"url-join": "^4.0.0",
"xterm": "^3.13.0",
"zmodem.js": "^0.1.9"
},
"devDependencies": {
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.8",
"gulp": "^3.9.1",
"copy-webpack-plugin": "^5.0.3",
"css-loader": "^2.1.1",
"gulp": "^4.0.2",
"gulp-clean": "^0.4.0",
"gulp-inline-source": "^3.1.0",
"gulp-inline-source": "^4.0.0",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^3.2.0",
"http-proxy-middleware": "^0.18.0",
"koa-connect": "^2.0.1",
"mini-css-extract-plugin": "^0.4.0",
"node-sass": "^4.7.2",
"optimize-css-assets-webpack-plugin": "^4.0.1",
"sass-loader": "^6.0.6",
"style-loader": "^0.19.1",
"mini-css-extract-plugin": "^0.6.0",
"node-sass": "^4.12.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.2.4",
"ts-loader": "^6.0.0",
"typescript": "^3.4.5",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.6.0",
"webpack-cli": "^2.1.2",
"webpack-merge": "^4.1.2",
"webpack-serve": "^0.3.2"
"webpack": "^4.31.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.3.1",
"webpack-merge": "^4.2.1",
"webpack-nano": "^0.6.2"
}
}
6 changes: 4 additions & 2 deletions html/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const devMode = process.env.NODE_ENV !== 'production';

module.exports = {
entry: './js/app.ts',
entry: {
app: './js/app.ts'
},
output: {
path: __dirname + '/dist',
filename: devMode ? '[name].js' : '[name].[hash].js',
Expand Down Expand Up @@ -40,5 +42,5 @@ module.exports = {
performance : {
hints : false
},
devtool: 'inline-source-map',
devtool: 'source-map',
};
35 changes: 14 additions & 21 deletions html/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
const path = require('path');
const merge = require('webpack-merge');
const convert = require('koa-connect');
const proxy = require('http-proxy-middleware');
const config = require('./webpack.config.js');

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = merge(config, {
mode: 'development',
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000,
proxy: [{
context: ['/auth_token.js', '/ws'],
target: 'http://localhost:7681',
ws: true
}]
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
}),
],
serve: {
content: __dirname + '/dist',
add: (app, middleware, options) => {
var ttydProxy = proxy(
[
'/ws',
'/auth_token.js',
],
{
target: 'http://127.0.0.1:7681',
ws: true,
}
);
app.use(convert(ttydProxy));
},
}
template: 'index.html'
})
]
});
16 changes: 11 additions & 5 deletions html/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ const config = require('./webpack.config.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin');

module.exports = merge(config, {
mode: 'production',
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
new TerserPlugin({
sourceMap: true
}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: {
inline: false,
annotation: true
}
}
}),
new OptimizeCSSAssetsPlugin({}),
]
},
plugins: [
Expand Down

0 comments on commit ccea4d2

Please sign in to comment.