添加cache-loader,debug模式下不再使用template缓存,修复一些 bug

This commit is contained in:
undefined committed 2020-07-11 20:00:43 +08:00
1 parent dd7914e1fb
commit 11368bc831
21 files changed
+248 -266

No files matched your search

-4
View File
@@ -1,4 +0,0 @@
global.DEBUG = true;
require('./index.js')('development').catch((e) => {
console.error(e);
});
+10 -10
View File
@@ -25,16 +25,6 @@ module.exports = {
console.error('Cannot hack sockjs');
}
},
yargs: () => {
const p = require.resolve('yargs');
const file = fs.readFileSync(p).toString().split('\n');
if (file[12].includes('const argv = yargs(processArgs, cwd, require)')) {
file[12] = 'const argv = yargs(processArgs, cwd)';
fs.writeFileSync(p, file.join('\n'));
} else if (!file[12].includes('const argv = yargs(processArgs, cwd)')) {
console.error('Cannot hack yargs');
}
},
saslprep: () => {
const q = require.resolve('saslprep');
const mem = path.join(path.dirname(q), 'code-points.mem');
@@ -48,4 +38,14 @@ module.exports = {
console.error('Cannot hack saslprep');
}
},
ftp: () => {
const p = require.resolve('ftp/lib/connection');
const file = fs.readFileSync(p).toString().split('\n');
if (file[51].includes('new Buffer')) {
file[51] = file[51].replace('new Buffer', 'Buffer.from');
fs.writeFileSync(p, file.join('\n'));
} else if (!file[51].includes('Buffer.from')) {
console.error('Cannot hack ftp');
}
},
};
+5 -1
View File
@@ -3,6 +3,7 @@ const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const yaml = require('js-yaml');
const argv = require('yargs-parser')(process.argv.slice(2));
const { root, ignoreFailure, rmdir } = require('./utils');
const template = require('./template');
const hack = require('./hack');
@@ -84,4 +85,7 @@ async function build(type) {
fs.writeFileSync(root('.build/install.js'), `global.Hydro="${d}"; ${installer}`);
}
module.exports = build;
build(argv.development ? 'development' : 'production').catch((e) => {
console.error(e);
process.exit(1);
});
-3
View File
@@ -1,3 +0,0 @@
require('./index.js')('production').catch((e) => {
console.error(e);
});
-21
View File
@@ -24,27 +24,6 @@ const build = (dirOrObject) => {
templates[i] = template;
}
} else templates = dirOrObject;
for (const i in templates) {
if (i.endsWith('.html') && !global.DEBUG && !templates[i].includes('No Compression')) {
templates[i] = templates[i]
.trim()
.replace(/ *\n */gmi, ' ')
.replace(/, /gmi, ',')
.replace(/%} {%/gmi, '%}{%')
.replace(/ %}/gmi, '%}')
.replace(/{% /gmi, '{%')
.replace(/> </gmi, '><')
.replace(/}} </gmi, '}}<')
.replace(/> {{/gmi, '>{{')
.replace(/{{ /gmi, '{{')
.replace(/ }}/gmi, '}}')
.replace(/%} </gmi, '%}<')
.replace(/> {%/gmi, '>{%')
.replace(/= /gmi, '=')
.replace(/ =/gmi, '=')
.trim();
}
}
return templates;
};
+20 -2
View File
@@ -1,4 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const webpack = require('webpack');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const { root } = require('./utils');
@@ -7,14 +8,31 @@ const build = async (type) => {
const config = {
mode: type,
entry: {
app: root('dist/loader.js'),
app: root('hydro/loader.ts'),
},
output: {
filename: '[name].js',
path: root('.build'),
},
target: 'node',
module: {},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'cache-loader',
options: {
cacheDirectory: path.resolve(__dirname, '..', '.cache', 'ts'),
},
},
'ts-loader',
],
},
],
},
resolve: { extensions: ['.js', '.ts'] },
plugins: [
new webpack.ProgressPlugin(),
new FriendlyErrorsPlugin({