mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
添加cache-loader,debug模式下不再使用template缓存,修复一些 bug
This commit is contained in:
1 parent
dd7914e1fb
commit
11368bc831
21 files changed
+248
-266
No files matched your search
@@ -1,4 +0,0 @@
|
||||
global.DEBUG = true;
|
||||
require('./index.js')('development').catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
+10
-10
@@ -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
@@ -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);
|
||||
});
|
||||
@@ -1,3 +0,0 @@
|
||||
require('./index.js')('production').catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
@@ -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
@@ -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({
|
||||
|
||||
Reference in new issue
Block a user