mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(route) rm minify
This commit is contained in:
parent
d98156faed
commit
039b535098
3 changed files with 63 additions and 39 deletions
|
|
@ -137,7 +137,6 @@
|
|||
"jonny": "^1.0.0",
|
||||
"markdown-it": "^8.0.0",
|
||||
"mellow": "^2.0.0",
|
||||
"minify": "^2.0.0",
|
||||
"minimist": "^1.2.0",
|
||||
"nomine": "^1.0.1",
|
||||
"omnes": "^1.0.3",
|
||||
|
|
@ -175,6 +174,8 @@
|
|||
"file-loader": "^0.11.2",
|
||||
"gunzip-maybe": "^1.3.1",
|
||||
"html-looks-like": "^1.0.2",
|
||||
"html-webpack-exclude-assets-plugin": "^0.0.5",
|
||||
"html-webpack-plugin": "^2.29.0",
|
||||
"jscs": "^3.0.1",
|
||||
"jshint": "^2.8.0",
|
||||
"minor": "^1.2.2",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ const ponse = require('ponse');
|
|||
const files = require('files-io');
|
||||
const rendy = require('rendy');
|
||||
const exec = require('execon');
|
||||
const minify = require('minify');
|
||||
const format = require('format-io');
|
||||
const squad = require('squad');
|
||||
const apart = require('apart');
|
||||
|
|
@ -24,7 +23,13 @@ const prefixer = require(DIR_SERVER + 'prefixer');
|
|||
const CloudFunc = require(DIR_SERVER + 'cloudfunc');
|
||||
const prefix = squad(prefixer, apart(config, 'prefix'));
|
||||
|
||||
const PATH_INDEX = DIR_HTML + 'index.html';
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const getIndexPath = () => {
|
||||
const dist = isDev ? 'dist-dev' : 'dist';
|
||||
|
||||
return DIR + `${dist}/index.html`;
|
||||
}
|
||||
|
||||
const TMPL_PATH = [
|
||||
'file',
|
||||
|
|
@ -153,26 +158,16 @@ function readFiles(callback) {
|
|||
function route(request, response, callback) {
|
||||
let name = ponse.getPathName(request);
|
||||
|
||||
const isAuth = RegExp('^(/auth|/auth/github)$').test(name);
|
||||
const isFS = RegExp('^/$|^' + FS).test(name);
|
||||
const p = {
|
||||
request : request,
|
||||
response : response,
|
||||
request,
|
||||
response,
|
||||
gzip : true,
|
||||
name : name
|
||||
name,
|
||||
};
|
||||
|
||||
if (!isAuth && !isFS)
|
||||
return callback();
|
||||
|
||||
if (isAuth) {
|
||||
p.name = DIR_HTML + name + '.html';
|
||||
ponse.sendFile(p);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isFS)
|
||||
return;
|
||||
return callback();
|
||||
|
||||
name = name.replace(CloudFunc.FS, '') || '/';
|
||||
const fullPath = root(name);
|
||||
|
|
@ -183,7 +178,7 @@ function route(request, response, callback) {
|
|||
|
||||
if (!error)
|
||||
return buildIndex(dir, (error, data) => {
|
||||
p.name = PATH_INDEX;
|
||||
p.name = getIndexPath();
|
||||
|
||||
if (error)
|
||||
return ponse.sendError(error, p);
|
||||
|
|
@ -207,28 +202,22 @@ function route(request, response, callback) {
|
|||
}
|
||||
|
||||
function buildIndex(json, callback) {
|
||||
const isMinify = config('minify');
|
||||
|
||||
exec.if(!isMinify, (error, name) => {
|
||||
fs.readFile(name || PATH_INDEX, 'utf8', (error, template) => {
|
||||
if (error)
|
||||
return;
|
||||
|
||||
const panel = CloudFunc.buildFromJSON({
|
||||
data : json,
|
||||
prefix : prefix(),
|
||||
template : Template
|
||||
});
|
||||
|
||||
const data = indexProcessing({
|
||||
panel : panel,
|
||||
data : template
|
||||
});
|
||||
|
||||
callback(error, data);
|
||||
fs.readFile(getIndexPath(), 'utf8', (error, template) => {
|
||||
if (error)
|
||||
return;
|
||||
|
||||
const panel = CloudFunc.buildFromJSON({
|
||||
data : json,
|
||||
prefix : prefix(),
|
||||
template : Template
|
||||
});
|
||||
}, (callback) => {
|
||||
minify(PATH_INDEX, 'name', callback);
|
||||
|
||||
const data = indexProcessing({
|
||||
panel : panel,
|
||||
data : template
|
||||
});
|
||||
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@ const distDev = path.resolve(__dirname, 'dist-dev');
|
|||
const devtool = isDev ? 'eval' : 'source-map';
|
||||
const notEmpty = (a) => a;
|
||||
const clean = (array) => array.filter(notEmpty);
|
||||
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin')
|
||||
|
||||
const extractMain = new ExtractTextPlugin('[name].css');
|
||||
const extractNojs = new ExtractTextPlugin('nojs.css');
|
||||
|
|
@ -34,6 +37,12 @@ const plugins = clean([
|
|||
name: 'cloudcmd',
|
||||
filename: 'cloudcmd.js',
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: 'html/index.html',
|
||||
minify: !isDev && getMinifyHtmlOptions(),
|
||||
excludeAssets: [/\\*/],
|
||||
}),
|
||||
new HtmlWebpackExcludeAssetsPlugin(),
|
||||
extractMain,
|
||||
extractNojs,
|
||||
extractView,
|
||||
|
|
@ -129,3 +138,28 @@ function extract(name, extractCss) {
|
|||
};
|
||||
}
|
||||
|
||||
function getMinifyHtmlOptions() {
|
||||
return {
|
||||
removeComments: true,
|
||||
removeCommentsFromCDATA: true,
|
||||
removeCDATASectionsFromCDATA: true,
|
||||
collapseWhitespace: true,
|
||||
collapseBooleanAttributes: true,
|
||||
removeAttributeQuotes: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
/* оставляем, поскольку у нас
|
||||
* в элемент fm генерируеться
|
||||
* таблица файлов
|
||||
*/
|
||||
removeEmptyElements: false,
|
||||
removeOptionalTags: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
|
||||
minifyJS: true,
|
||||
minifyCSS: true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue