@tmsfe/tmskit 0.0.3 → 0.0.5-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const chalk = require('chalk');
2
- const program = require('commander');
2
+ const commander = require('commander');
3
3
  const { log, suggestCommands } = require('./utils/widgets');
4
4
  const { TMS_NAME } = require('./config/constant.js');
5
5
  const commands = require('./entry');
@@ -7,24 +7,40 @@ const init = require('./init');
7
7
 
8
8
  init();
9
9
 
10
+ const program = new commander.Command(TMS_NAME);
11
+
10
12
  program
11
- .version(`${TMS_NAME} ${require('../package.json').version}`);
13
+ .version(`${TMS_NAME} ${require('../package.json').version}`, '-v, -V, --version');
12
14
 
13
- commands.forEach((cmd) => {
14
- const command = program.command(cmd.command);
15
+ function registerCommand(program, commands) {
16
+ commands.forEach((cmd) => {
17
+ if (cmd.type === 'child') {
18
+ const childProgram = new commander.Command(cmd.name);
19
+ cmd.usage && childProgram.usage(cmd.usage);
20
+ cmd.description && childProgram.description(cmd.description);
21
+ registerCommand(childProgram, cmd.commands);
15
22
 
16
- cmd.usage && command.usage(cmd.usage);
23
+ program.addCommand(childProgram);
24
+ } else {
25
+ const command = program.command(cmd.command);
17
26
 
18
- cmd.description && command.description(cmd.description);
27
+ cmd.usage && command.usage(cmd.usage);
19
28
 
20
- cmd.options?.forEach(opt => command.option(...opt));
29
+ cmd.description && command.description(cmd.description);
30
+
31
+ cmd.options?.forEach(opt => command.option(...opt));
32
+
33
+ command.action(cmd.action);
34
+ }
35
+ });
36
+ }
37
+
38
+ registerCommand(program, commands);
21
39
 
22
- command.action(cmd.action);
23
- });
24
40
 
25
41
  program.on('--help', () => {
26
42
  log();
27
- log(` Run ${chalk.cyan('tms <command> --help')} for detailed usage of given command.`);
43
+ log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
28
44
  log();
29
45
  });
30
46
 
package/src/init.js CHANGED
@@ -1,4 +1,3 @@
1
- const { exec } = require('shelljs');
2
1
  const semver = require('semver');
3
2
  const packageJson = require('../package.json');
4
3
  const chalk = require('chalk');
@@ -29,10 +28,6 @@ function initCliContext() {
29
28
  // 执行操作前检查node版本
30
29
  // 旧版本node直接提示升级,退出脚本
31
30
  checkNodeVersion(requiredVersion, packName);
32
-
33
-
34
- // 执行前配置正确的npm源
35
- exec('npm config set registry https://mirrors.tencent.com/npm/ --global', { silent: true });
36
31
  }
37
32
 
38
33
  module.exports = initCliContext;
@@ -1,5 +1,4 @@
1
1
  const Metalsmith = require('metalsmith');
2
- const fs = require('fs');
3
2
  const render = require('./render');
4
3
  const ask = require('./ask');
5
4
  const FILES_TO_IGNORE = require('./ignoreFiles');
@@ -33,7 +33,7 @@ async function create(appName) {
33
33
  const cwd = process.cwd();
34
34
  const targetDir = path.resolve(cwd, appName);
35
35
  const appType = 'mp';
36
- createAppDir(targetDir);
36
+ await createAppDir(targetDir);
37
37
 
38
38
  // 创建缓存目录
39
39
  io.ensureDirExist(TEMPLATE_DIR);
@@ -41,7 +41,7 @@ async function create(appName) {
41
41
  await createTask(downloadRepoForGit, '拉取模板仓库', '拉取模板仓库完成')(
42
42
  'https://git.woa.com/tmsfe/tms-frontend.git',
43
43
  TEMPLATE_DIR,
44
- 'feat-albertluo-template82b',
44
+ 'master',
45
45
  );
46
46
 
47
47
  // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
@@ -49,8 +49,6 @@ async function create(appName) {
49
49
  appName,
50
50
  appType,
51
51
  }).then(() => {
52
- succeed('项目创建完成,开始初始化...');
53
-
54
52
  shelljs.cd(appName);
55
53
  const hooks = require(resolve(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
56
54
  if (hooks.afterCreate) {
@@ -63,6 +61,7 @@ async function create(appName) {
63
61
  });
64
62
  }
65
63
  shelljs.rm('-rf', resolve(appName, TEMPLATE_TKIT_DIR));
64
+ succeed('项目创建完成.');
66
65
  })
67
66
  .catch((err) => {
68
67
  fail(err.message);
@@ -1,15 +1,15 @@
1
1
  const shelljs = require('shelljs');
2
- const webpackBuildServer = require('../../../webpack/buildServer');
3
2
  const { resolve } = require('../../../utils/widgets');
4
3
  const init = require('../init/index');
4
+ const gulpBuild = require('../../../gulp/build');
5
5
 
6
6
  async function build(tmsConfig, targetModules, env) {
7
7
  // 开始构建前,清理输出目录
8
- await shelljs.rm('-rf', resolve('dist'));
8
+ await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
9
9
 
10
10
  const { targetModules: newModules } = await init(tmsConfig, targetModules);
11
11
 
12
- webpackBuildServer(tmsConfig, newModules, env);
12
+ gulpBuild(tmsConfig, newModules, env);
13
13
  }
14
14
 
15
15
  module.exports = build;
@@ -1,4 +1,4 @@
1
- const webpackServer = require('../../../webpack/devServer');
1
+ const gulpDev = require('../../../gulp/dev');
2
2
  const fs = require('fs');
3
3
  const { resolve } = require('../../../utils/widgets');
4
4
  const init = require('../init/index');
@@ -45,7 +45,7 @@ function isInit(tmsConfig, targetModules, contextDir) {
45
45
  }
46
46
 
47
47
  // 判断package.json的版本是否有新的版本
48
- return checkDependencies(targetModules, resolve('./'), tmsConfig.webpack.outputDir);
48
+ return checkDependencies(targetModules, resolve('./'), tmsConfig.gulp.outputDir);
49
49
  }
50
50
 
51
51
  async function dev(tmsConfig, targetModules, env) {
@@ -60,7 +60,7 @@ async function dev(tmsConfig, targetModules, env) {
60
60
  }
61
61
 
62
62
  console.log('当前dev启动的有效模块', newModules.map(item => item.name));
63
- webpackServer(tmsConfig, newModules, env);
63
+ gulpDev(tmsConfig, newModules, env);
64
64
  }
65
65
 
66
66
  module.exports = dev;
@@ -2,7 +2,7 @@ const init = require('./init/index');
2
2
  const dev = require('./dev/index');
3
3
  const build = require('./build/index');
4
4
  const install = require('./install/index');
5
- const { createTask, resolve } = require('../../utils/widgets');
5
+ const { createTask } = require('../../utils/widgets');
6
6
  const { MODE } = require('../../config/constant');
7
7
  const { readTmsConfig, checkModules } = require('../../utils/tkitUtils');
8
8
 
@@ -12,10 +12,12 @@ const handleModulesArg = (cmd) => {
12
12
  return MODE.main;
13
13
  }
14
14
  // 单模块 或 多模块开发
15
+ const { argv } = process;
16
+ const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
15
17
  if (cmd.module) {
16
18
  return [
17
19
  cmd.module,
18
- ...cmd.args,
20
+ ...reset,
19
21
  ];
20
22
  }
21
23
  // 全量模块
@@ -23,11 +25,6 @@ const handleModulesArg = (cmd) => {
23
25
  };
24
26
 
25
27
  async function run(commandName, cmd) {
26
- if (commandName === 'install') {
27
- install(resolve('./'));
28
- return;
29
- }
30
-
31
28
  const moduleArg = handleModulesArg(cmd);
32
29
  const { env } = cmd;
33
30
 
@@ -52,6 +49,9 @@ async function run(commandName, cmd) {
52
49
  case 'dev':
53
50
  dev(tmsConfig, modules, env);
54
51
  return;
52
+ case 'install':
53
+ install(tmsConfig, modules, env);
54
+ return;
55
55
  case 'build':
56
56
  build(tmsConfig, modules, env);
57
57
  return;
@@ -3,44 +3,38 @@ const fs = require('fs');
3
3
  const io = require('../../../utils/io');
4
4
  const { resolve, createTask } = require('../../../utils/widgets');
5
5
  const { buildOutputAppJson } = require('../../../utils/buildAppJson');
6
- const { npmInstallAll } = require('../../../utils/npmUtils');
7
- const { buildMpNpm } = require('../../../utils/mpCiUtils');
8
- const { MODULE_CODE_DIR, CACHE_DIR, DEFAULT_COPY_CONFIG, DEFAULT_MODULE_DIR } = require('../../../config/constant');
6
+ const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG, DEFAULT_MODULE_DIR } = require('../../../config/constant');
9
7
  const { cloneModules } = require('../../../utils/cloneModules');
10
8
  const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
11
9
  const { fail } = require('../../../utils/log');
10
+ const install = require('../install');
12
11
 
13
12
  /**
14
- * 拷贝package.json\模块的代码到编译输出目录
13
+ * 拷贝相关配置文件到编译输出目录
15
14
  * @param { object } tmsConfig
16
15
  * @param { array } modules
17
16
  * @param { array } defaultFiles 默认需要拷贝的配置项
18
17
  * @returns
19
18
  */
20
19
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
21
- const outputDir = resolve(tmsConfig.webpack.outputDir);
20
+ const outputDir = resolve(tmsConfig.gulp.outputDir);
22
21
  io.ensureDirExist(outputDir);
23
22
  defaultFiles.forEach((item) => {
24
23
  if (fs.existsSync(resolve(item))) {
25
- shelljs.cp('-rf', resolve(item), resolve(tmsConfig.webpack.outputDir, item));
24
+ shelljs.cp('-rf', resolve(item), resolve(tmsConfig.gulp.outputDir, item));
26
25
  }
27
26
  });
28
27
 
29
- // 拷贝模块的代码到编译输出目录
28
+ // 拷贝模块的package.json到编译输出目录
30
29
  targetModules.forEach((item) => {
31
- const outputModuleDir = resolve(`${tmsConfig.webpack.outputDir}/${item.root}`);
30
+ const outputModuleDir = resolve(`${tmsConfig.gulp.outputDir}/${item.root}`);
32
31
  if (!fs.existsSync(resolve(item.path))) {
33
32
  fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
34
33
  process.exit(1);
35
34
  }
36
- if (!fs.existsSync(outputModuleDir)) {
37
- shelljs.mkdir('-p', outputModuleDir);
38
- } else {
39
- // 删除除了node_modules、miniprogram_npm 的其他文件
40
- // eslint-disable-next-line
41
- shelljs.exec('find . -not \( -name node_modules -or -name miniprogram_npm \) -delete', { silent: true });
42
- }
43
- shelljs.cp('-Rf', `${resolve(item.path)}/*`, outputModuleDir);
35
+ io.ensureDirExist(outputModuleDir);
36
+ const modulePackagePath = resolve(item.path, 'package.json');
37
+ if (fs.existsSync(modulePackagePath)) shelljs.cp('-Rf', modulePackagePath, outputModuleDir);
44
38
  });
45
39
  };
46
40
 
@@ -63,19 +57,8 @@ async function task(tmsConfig, targetModules) {
63
57
  '拷贝文件到编译输出目录完成',
64
58
  )(tmsConfig, newModules, DEFAULT_COPY_CONFIG);
65
59
 
66
- // npm install
67
- await createTask(
68
- npmInstallAll,
69
- '开始npm install',
70
- 'npm install 完成',
71
- )(newModules, resolve(tmsConfig.webpack.outputDir), `${CACHE_DIR}/node_modules`);
72
-
73
- // 构建miniprograme_npm
74
- await createTask(
75
- buildMpNpm,
76
- '开始构建miniprograme_npm',
77
- '构建miniprograme_npm 完成',
78
- )({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsConfig.privateKey });
60
+ // install
61
+ await install(tmsConfig, newModules, false);
79
62
 
80
63
  // 动态生成编译后的app.json;
81
64
  await createTask(
@@ -1,40 +1,31 @@
1
- const shelljs = require('shelljs');
2
- const { createTask } = require('../../../utils/widgets');
1
+ const { createTask, resolve } = require('../../../utils/widgets');
3
2
  const { buildMpNpm } = require('../../../utils/mpCiUtils');
4
- const glob = require('glob-ignore');
5
- const path = require('path');
3
+ const { CACHE_DIR, DEFAULT_MODULE_DIR } = require('../../../config/constant');
4
+ const { cloudNpmInstall, mpNpmInstallAll } = require('../../../utils/npmUtils');
5
+ const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
6
6
 
7
- function npmInstall(contextDir) {
8
- return new Promise((resolve, reject) => {
9
- glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
10
- console.log('files', files);
11
- if (err) {
12
- reject(err);
13
- }
14
- files.forEach((file) => {
15
- const dir = path.dirname(file);
16
- shelljs.cd(dir);
17
- shelljs.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', { silent: false });
18
- });
19
- resolve();
20
- });
21
- });
22
- }
23
-
24
- async function install(contextDir) {
25
- // npm install
7
+ async function install(tmsConfig, modules, isCloud = true) {
8
+ const newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName, DEFAULT_MODULE_DIR);
9
+ // 小程序npm install
26
10
  await createTask(
27
- npmInstall,
28
- '开始npm install',
29
- 'npm install完成',
30
- )(contextDir);
11
+ mpNpmInstallAll,
12
+ '小程序 开始npm install',
13
+ '小程序npm install 完成',
14
+ )(newModules, resolve(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`);
31
15
 
32
16
  // 构建miniprograme_npm
33
17
  await createTask(
34
18
  buildMpNpm,
35
- '开始构建miniprogram_npm',
36
- '构建miniprogram_npm 完成',
37
- )({ appId: 'null', projectPath: contextDir, privateKey: 'null' });
19
+ '开始构建miniprograme_npm',
20
+ '构建miniprograme_npm 完成',
21
+ )({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsConfig.privateKey });
22
+
23
+ // 安装云函数的
24
+ isCloud && createTask(
25
+ cloudNpmInstall,
26
+ '云函数npm install',
27
+ '云函数npm install安装完毕',
28
+ )(resolve(tmsConfig.cloudDir));
38
29
  }
39
30
 
40
31
  module.exports = install;
@@ -133,7 +133,7 @@ function buildOutputAppJson(tmsConfig, modules) {
133
133
  // 更新主包,需在subpackages处理完成后执行, pages/
134
134
  updateMainPackages(appJson, tmsConfig.mainPackages, DEFAULT_MODULE_DIR);
135
135
 
136
- fs.writeFileSync(resolve(`${tmsConfig.webpack.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
136
+ fs.writeFileSync(resolve(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
137
137
 
138
138
  return appJson;
139
139
  }
package/src/utils/io.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const fs = require('fs');
2
+ const path = require('path');
2
3
  /**
3
4
  * 判断目录是否为空
4
5
  * @param {string} dirname 目录名
@@ -15,7 +16,51 @@ const ensureDirExist = (dirname) => {
15
16
  }
16
17
  };
17
18
 
19
+ // 复制文件
20
+ const copyFile = function (src, dest) {
21
+ if (fs.existsSync(dest)) {
22
+ fs.unlinkSync(dest);
23
+ }
24
+ const dir = dest.substr(0, dest.lastIndexOf('/'));
25
+ ensureDirExist(dir);
26
+ fs.copyFileSync(src, dest);
27
+ };
28
+
29
+ // 添加后缀
30
+ function ext(filePath, extensions) {
31
+ let newFilePath = filePath;
32
+ try {
33
+ const stat = fs.lstatSync(newFilePath);
34
+ if (stat.isDirectory()) {
35
+ newFilePath += (newFilePath[newFilePath.length - 1] === '/') ? 'index' : '/index';
36
+ }
37
+ } catch (e) {}
38
+
39
+ for (const ext of extensions) {
40
+ const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
41
+ if (fs.existsSync(file)) {
42
+ return {
43
+ file,
44
+ ext,
45
+ };
46
+ }
47
+ }
48
+ return null;
49
+ }
50
+
51
+ // 判断文件是否在某个目录
52
+ const fileInDir = (dir, file) => {
53
+ const relativePath = path.relative(dir, file);
54
+ if (relativePath.startsWith('..')) {
55
+ return false;
56
+ }
57
+ return true;
58
+ };
59
+
18
60
  module.exports = {
19
61
  isDirEmpty,
62
+ copyFile,
20
63
  ensureDirExist,
64
+ ext,
65
+ fileInDir,
21
66
  };
@@ -4,11 +4,12 @@
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const shell = require('shelljs');
7
+ const glob = require('glob-ignore');
7
8
  const LOG = require('./log');
8
9
 
9
10
  const dirpath = process.cwd(); // 项目根目录
10
11
 
11
- const getTarNpmFilename = targetDir => `${targetDir.replaceAll('/', '-')}.tar.gz`;
12
+ const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`;
12
13
 
13
14
  // 缓存npm包
14
15
  const npmCache = function (targetDir, cacheDir) {
@@ -38,9 +39,8 @@ const getNpmCache = function (targetDir, cacheDir) {
38
39
 
39
40
 
40
41
  // 遍历安装指定目录下所有项目的npm依赖
41
- const npmInstallAll = async (modules, contextDir, cacheDir) => {
42
+ const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
42
43
  const packageJsonFiles = await findAllPackageJson(modules, contextDir);
43
-
44
44
  await Promise.all(packageJsonFiles.map(file => new Promise((resolve) => {
45
45
  const dir = path.dirname(file);
46
46
  shell.cd(dir);
@@ -109,7 +109,12 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
109
109
  const cwd = contextDir || dirpath;
110
110
  const result = [path.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
111
111
 
112
+
112
113
  subRoots.forEach((subRoot) => {
114
+ if (!subRoot.root) {
115
+ LOG.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
116
+ process.exit(1);
117
+ }
113
118
  const toppath = path.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
114
119
  const list = findFilesByFilter(toppath, packageJsonName);
115
120
 
@@ -119,8 +124,25 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
119
124
  return result;
120
125
  };
121
126
 
127
+ function cloudNpmInstall(contextDir) {
128
+ return new Promise((resolve, reject) => {
129
+ glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
130
+ if (err) {
131
+ reject(err);
132
+ }
133
+ files.forEach((file) => {
134
+ const dir = path.dirname(file);
135
+ shell.cd(dir);
136
+ shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', { silent: false });
137
+ });
138
+ resolve();
139
+ });
140
+ });
141
+ }
142
+
122
143
 
123
144
  module.exports = {
124
- npmInstallAll,
145
+ cloudNpmInstall,
146
+ mpNpmInstallAll,
125
147
  findAllPackageJson,
126
148
  };
@@ -1,65 +0,0 @@
1
- const WebpackChain = require('webpack-chain');
2
- const webpack = require('webpack');
3
- const { getEntry, stringified, getAlias } = require('./utils');
4
- const { resolve } = require('../utils/widgets');
5
- const { DEFAULT_WEBPACK_ENTRY, DEFAULT_MODULE_DIR } = require('../config/constant');
6
-
7
- module.exports = (tmsConfig, modules) => {
8
- const { envData = {}, webpack: tmsWebpack } = tmsConfig;
9
- let webpackConfig = new WebpackChain();
10
-
11
- const alias = getAlias(modules);
12
- const entry = getEntry(DEFAULT_WEBPACK_ENTRY, modules, tmsConfig, DEFAULT_MODULE_DIR);
13
- webpackConfig.merge({
14
- entry,
15
- output: {
16
- path: resolve(`./${tmsWebpack.outputDir}`),
17
- libraryTarget: 'commonjs2',
18
- filename: '[name]',
19
- },
20
- // TODO 有报错,先注释掉
21
- // cache: {
22
- // type: 'filesystem',
23
- // cacheDirectory: resolve(`./${tmsConfig.webpack.outputDir}/node_modules/.cache`),
24
- // },
25
- resolve: {
26
- extensions: ['.tsx', '.ts', '.js'],
27
- alias: Object.assign(tmsWebpack.alias, alias),
28
- },
29
- devtool: tmsWebpack.sourceMap ? 'source-map' : false,
30
- });
31
-
32
- webpackConfig.module
33
- .rule('ts-loader')
34
- .test(/\.ts$/)
35
- .use('ts-loader')
36
- .loader(require.resolve('ts-loader'))
37
- .options({
38
- configFile: resolve('./tsconfig.json'),
39
- // 只进行语法转换,不进行类型校验,提高构建速度
40
- transpileOnly: true,
41
- })
42
- .end();
43
-
44
- // webpackConfig.module
45
- // .rule('babel')
46
- // .test(/\.(js|mjs|jsx|ts|tsx)$/)
47
- // .pre()
48
- // .exclude.add(/(node_modules|miniprogram_npm)/).end()
49
- // .use(require.resolve('babel-loader'))
50
- // .loader(require.resolve('babel-loader'));
51
-
52
- webpackConfig
53
- .plugin('definePlugin')
54
- .use(webpack.DefinePlugin, [stringified(envData)])
55
- .end();
56
-
57
- // 执行tms.config.js自定义的webpackChain
58
- if (tmsWebpack.webpackChain) {
59
- webpackConfig = tmsWebpack.webpackChain(webpackConfig, {
60
- modules,
61
- });
62
- }
63
-
64
- return webpackConfig;
65
- };
@@ -1,21 +0,0 @@
1
- const webpackConfig = require('./base');
2
- const { DEFAULT_COPY_CONFIG } = require('../config/constant');
3
- const { getCopyPlugin } = require('./utils');
4
-
5
- module.exports = (...args) => {
6
- const [tmsConfig, modules] = args;
7
- const webpackBuildConfig = webpackConfig(...args);
8
-
9
- webpackBuildConfig.mode('production');
10
-
11
- const copyPluginParams = getCopyPlugin(DEFAULT_COPY_CONFIG, modules, tmsConfig, 'build');
12
- // console.log('copyPluginParams', copyPluginParams);
13
- webpackBuildConfig
14
- .plugin('copy-webpack-plugin')
15
- .use(require('copy-webpack-plugin'), [{
16
- patterns: copyPluginParams,
17
- }])
18
- .end();
19
-
20
- return webpackBuildConfig;
21
- };
@@ -1,34 +0,0 @@
1
- const webpack = require('webpack');
2
- const webBuildConfig = require('./build');
3
- const { createTask } = require('../utils/widgets');
4
- const { fail } = require('../utils/log');
5
-
6
- function compilerRun(compiler) {
7
- return new Promise((resolve) => {
8
- compiler.run((err, stats) => {
9
- resolve({ err, stats });
10
- });
11
- });
12
- }
13
-
14
- module.exports = async (...args) => {
15
- const config = webBuildConfig(...args);
16
- const compiler = webpack(config.toConfig());
17
-
18
- const { err, stats } = await createTask(compilerRun, '开始webpack打包编译', 'webpack打包编译完成')(compiler);;
19
-
20
- if (err) {
21
- fail(err);
22
- console.log('详细的错误信息:', err);
23
- }
24
-
25
- if (stats.hasErrors() || stats.hasWarnings()) {
26
- console.log(stats.toString({
27
- // 增加控制台颜色开关
28
- colors: true,
29
- errorDetails: true,
30
- }));
31
- };
32
-
33
- return compiler;
34
- };
@@ -1,31 +0,0 @@
1
- const webpackConfig = require('./base');
2
- const { DEFAULT_COPY_CONFIG } = require('../config/constant');
3
- const { getCopyPlugin } = require('./utils');
4
-
5
- module.exports = (...args) => {
6
- const [tmsConfig, modules] = args;
7
- const webpackDevConfig = webpackConfig(...args);
8
-
9
- webpackDevConfig.devtool('source-map');
10
-
11
- webpackDevConfig.mode('development');
12
-
13
- const copyPluginParams = getCopyPlugin(DEFAULT_COPY_CONFIG, modules, tmsConfig, 'dev');
14
- // console.log('copyPluginParams', copyPluginParams);
15
- webpackDevConfig
16
- .plugin('copy-webpack-plugin')
17
- .use(require('copy-webpack-plugin'), [{
18
- patterns: copyPluginParams,
19
- }])
20
- .end();
21
-
22
- webpackDevConfig
23
- .plugin('ExtractPlugin')
24
- .use(require('./plugins/entryExtractPlugin'), [{
25
- tmsConfig,
26
- modules,
27
- }])
28
- .end();
29
-
30
- return webpackDevConfig;
31
- };
@@ -1,37 +0,0 @@
1
- const webpack = require('webpack');
2
- const webDevConfig = require('./dev');
3
- const { setupDevWebPackHooks } = require('./utils');
4
- const { fail } = require('../utils/log');
5
-
6
- module.exports = (...args) => {
7
- const config = webDevConfig(...args);
8
- const compiler = webpack(config.toConfig());
9
-
10
- setupDevWebPackHooks({
11
- compiler,
12
- }, () => {
13
- // TODO 判断open参数,打开微信开发者工具
14
- // openDevtool(api.resolve(config.outputDir || 'dist'))
15
- });
16
-
17
- compiler.watch(
18
- {
19
- aggregateTimeout: 1000,
20
- poll: undefined,
21
- },
22
- (err, stats) => {
23
- if (err) {
24
- fail(err);
25
- console.log('详细的错误信息:', err);
26
- }
27
- if (stats.hasErrors() || stats.hasWarnings()) {
28
- console.log(stats.toString({
29
- // 增加控制台颜色开关
30
- colors: true,
31
- }));
32
- };
33
- },
34
- );
35
-
36
- return compiler;
37
- };