feat: 修改 webpack配置文件

This commit is contained in:
tackchen 2020-12-16 13:37:28 +08:00
parent 78a8be2fb9
commit 98cf22b47e
4 changed files with 47 additions and 59 deletions

View File

@ -3,15 +3,12 @@ const rename = require('gulp-rename');
const fs = require('fs'); const fs = require('fs');
const babel = require('gulp-babel'); const babel = require('gulp-babel');
const toc = require('gulp-markdown-toc'); const toc = require('gulp-markdown-toc');
let version = require('../package.json').version; const version = require('../package.json').version;
let files = [
'../npm/order/package.json', const plugins = ['order', 'poly', 'trad', 'draw', 'idiom', 'xhy', 'radical'];
'../npm/poly/package.json',
'../npm/trad/package.json', const files = [
'../npm/draw/package.json', ...plugins.map(plugin => `../npm/${plugin}/package.json`),
'../npm/idiom/package.json',
'../npm/xhy/package.json',
'../npm/radical/package.json',
'../npm/cnchar/package.json', '../npm/cnchar/package.json',
'../npm/all/package.json', '../npm/all/package.json',
'../npm/hanzi-util/package.json', '../npm/hanzi-util/package.json',
@ -20,14 +17,14 @@ let files = [
function modVersion () { function modVersion () {
files.forEach(file => { files.forEach(file => {
let pkg = require(file); const pkg = require(file);
pkg.version = version; pkg.version = version;
fs.writeFile(file.substr(1), JSON.stringify(pkg, null, 4), 'utf8', (err) => { fs.writeFile(file.substr(1), JSON.stringify(pkg, null, 4), 'utf8', (err) => {
if (err) throw err; if (err) throw err;
}); });
}); });
} }
let depFiles = [ const depFiles = [
'../npm/all/package.json', '../npm/all/package.json',
'../npm/hanzi-util/package.json', '../npm/hanzi-util/package.json',
'../npm/hanzi-util-base/package.json' '../npm/hanzi-util-base/package.json'
@ -35,9 +32,9 @@ let depFiles = [
function modDep () { function modDep () {
depFiles.forEach(file => { depFiles.forEach(file => {
let pkg = require(file); const pkg = require(file);
let dep = pkg.dependencies; const dep = pkg.dependencies;
for (let key in dep) { for (const key in dep) {
if (key.substr(0, 6) === 'cnchar') { if (key.substr(0, 6) === 'cnchar') {
dep[key] = '^' + version; dep[key] = '^' + version;
} }
@ -56,50 +53,41 @@ function task () {
transEs6ByBabel(); transEs6ByBabel();
} }
function buildPluginGulpFiles (plugin) {
const path = `src/plugin/${plugin}/`;
return [`${path}dict/*.json`, `${path}types`, `${path}*.d.ts`];
}
function gulpPlugin (plugin) {
gulp.src(buildPluginGulpFiles(plugin))
.pipe(gulp.dest(`npm/${plugin}`));
}
function copyToNPM () { function copyToNPM () {
gulp.src('helper/README.md') const gulpReadme = gulp.src(['helper/README.md', 'LICENSE'])
.pipe(toc()) .pipe(toc())
.pipe(gulp.dest('.')) .pipe(gulp.dest('.'))
.pipe(gulp.dest('npm/cnchar'))
.pipe(gulp.dest('npm/order'))
.pipe(gulp.dest('npm/poly'))
.pipe(gulp.dest('npm/trad'))
.pipe(gulp.dest('npm/draw'))
.pipe(gulp.dest('npm/idiom'))
.pipe(gulp.dest('npm/radical'))
.pipe(gulp.dest('npm/xhy'));
gulp.src(['src/main/*.json', 'src/main/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/cnchar')); .pipe(gulp.dest('npm/cnchar'));
gulp.src(['src/plugin/order/*.json', 'src/plugin/order/*.d.ts', 'LICENSE']) plugins.forEach(plugin => {
.pipe(gulp.dest('npm/order')); gulpReadme = gulpReadme.pipe(`npm/${plugin}`);
});
gulp.src(['src/plugin/poly/*.json', 'src/plugin/poly/*.d.ts', 'LICENSE']) gulp.src(['src/main/dict/*.json', 'src/main/types', 'src/main/*.d.ts'])
.pipe(gulp.dest('npm/poly')); .pipe(gulp.dest('npm/cnchar'));
gulp.src(['src/plugin/trad/*.json', 'src/plugin/trad/*.d.ts', 'LICENSE']) plugins.forEach(plugin => {
.pipe(gulp.dest('npm/trad')); gulpPlugin(plugin);
});
gulp.src(['src/plugin/draw/*.json', 'src/plugin/draw/*.d.ts', 'LICENSE']) gulp.src(['src/main/*.d.ts', 'src/main/types'])
.pipe(gulp.dest('npm/draw'));
gulp.src(['src/plugin/idiom/*.json', 'src/plugin/idiom/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/idiom'));
gulp.src(['src/plugin/radical/*.json', 'src/plugin/radical/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/radical'));
gulp.src(['src/plugin/xhy/*.json', 'src/plugin/xhy/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/xhy'));
gulp.src(['src/main/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/hanzi-util-base')); .pipe(gulp.dest('npm/hanzi-util-base'));
gulp.src(['helper/all/*.d.ts', 'LICENSE']) gulp.src(['helper/all/*.d.ts'])
.pipe(gulp.dest('npm/all')) .pipe(gulp.dest('npm/all'))
.pipe(gulp.dest('npm/hanzi-util')); .pipe(gulp.dest('npm/hanzi-util'));
} }
function copyLatest () { function copyLatest () {
// gulp.src(`dist/*.${version}.min.js`) // gulp.src(`dist/*.${version}.min.js`)
// .pipe(rename(function (path) { // .pipe(rename(function (path) {

View File

@ -2,7 +2,7 @@ const version = require('../package.json').version;
const path = require('path'); const path = require('path');
const tool = require('../helper/tool'); const tool = require('../helper/tool');
tool.write('./src/main/version.js', 'module.exports = \'' + version + '\';'); tool.write('./src/main/version.ts', 'module.exports = \'' + version + '\';');
// module.exports = { // module.exports = {
// entry: path.resolve('./', 'src/main/index.js'), // entry: path.resolve('./', 'src/main/index.js'),
@ -22,7 +22,7 @@ tool.write('./src/main/version.js', 'module.exports = \'' + version + '\';');
module.exports = { module.exports = {
mode: 'production', mode: 'production',
entry: path.resolve('./', 'src/main/index.js'), entry: path.resolve('./', 'src/main/index.ts'),
output: { output: {
path: path.resolve('./', 'npm/cnchar'), path: path.resolve('./', 'npm/cnchar'),
filename: 'cnchar.min.js', filename: 'cnchar.min.js',

View File

@ -24,7 +24,7 @@ module.exports = (env) => {
const plugin = env.pluginname; const plugin = env.pluginname;
return { return {
mode: 'production', mode: 'production',
entry: path.resolve('./', 'src/plugin/' + plugin + '/index.js'), entry: path.resolve('./', 'src/plugin/' + plugin + '/index.ts'),
output: { output: {
path: path.resolve('./', 'npm/' + plugin), path: path.resolve('./', 'npm/' + plugin),
filename: 'cnchar.' + plugin + '.min.js', filename: 'cnchar.' + plugin + '.min.js',