akfun 1.5.17 → 1.6.1

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/module/index.js CHANGED
@@ -129,7 +129,7 @@ let argv = yargs
129
129
  )
130
130
  .command(
131
131
  'build',
132
- '构建生产环境的代码',
132
+ '构建生产环境代码',
133
133
  (yargs) => {
134
134
  yargs
135
135
  .reset()
@@ -142,7 +142,7 @@ let argv = yargs
142
142
  )
143
143
  .command(
144
144
  'build2lib',
145
- '构建第三方功能包',
145
+ '构建lib库',
146
146
  (yargs) => {
147
147
  yargs
148
148
  .reset()
@@ -155,7 +155,7 @@ let argv = yargs
155
155
  )
156
156
  .command(
157
157
  'build2esm',
158
- '构建esm功能包',
158
+ '构建esm模块',
159
159
  (yargs) => {
160
160
  yargs
161
161
  .reset()
package/module/inspect.js CHANGED
@@ -1,10 +1,11 @@
1
1
  const path = require('path');
2
2
  const ora = require('ora');
3
3
  const fs = require('fs');
4
+ const {curConsoleTag} = require("../src/utils/akfunParams");
4
5
  const getCurWebpackConfig = require('../src/utils/getCurWebpackConfig.js'); // 用于获取当前webpack配置的方法
5
6
 
6
7
  // 根据当前配置文件内容创建指定名称的文件
7
- const createConfigJs = function (fileCont, fileName) {
8
+ const createConfigJs = function (fileName, fileCont) {
8
9
  let filePath = path.resolve(process.cwd(), fileName);
9
10
 
10
11
  fs.writeFile(filePath, JSON.stringify(fileCont, null, 2), (err) => {
@@ -17,22 +18,23 @@ const createConfigJs = function (fileCont, fileName) {
17
18
  /**
18
19
  * 用于输出当前项目配置文件
19
20
  */
20
- module.exports = (type) => {
21
- const spinner = ora( '[akfun]正在获取当前环境的配置数据...').start();
21
+ module.exports = (type, _consoleTag) => {
22
+ const consoleTag = _consoleTag || curConsoleTag;
23
+ const spinner = ora( `${consoleTag}正在获取当前环境的配置数据...`).start();
22
24
  if (type === 'dev') {
23
25
  const devConfig = getCurWebpackConfig(type);
24
- createConfigJs(devConfig, 'current-akfun-dev-config.js');
25
- spinner.succeed( '[akfun]当前配置数据已输出至akfun-dev-config.js中!');
26
+ createConfigJs('current-akfun-dev-config.js', devConfig);
27
+ spinner.succeed( `${consoleTag}当前配置数据已输出至akfun-dev-config.js中!`);
26
28
  } else if (type === 'lib') {
27
29
  const libraryConfig = getCurWebpackConfig(type);
28
- createConfigJs(libraryConfig, 'current-akfun-build2lib-config.js');
29
- spinner.succeed( '[akfun]当前配置数据已输出至akfun-build2lib-config.js中!');
30
+ createConfigJs('current-akfun-build2lib-config.js', libraryConfig);
31
+ spinner.succeed( `${consoleTag}当前配置数据已输出至akfun-build2lib-config.js中!`);
30
32
  } else if (type === 'build') {
31
33
  const prodConfig = getCurWebpackConfig(type);
32
34
  // 默认输出生产环境的配置文件
33
- createConfigJs(prodConfig, 'current-akfun-build-config.js');
34
- spinner.succeed( '[akfun]当前配置数据已输出至akfun-build-config.js中!');
35
+ createConfigJs('current-akfun-build-config.js', prodConfig);
36
+ spinner.succeed( `${consoleTag}当前配置数据已输出至akfun-build-config.js中!`);
35
37
  } else {
36
- console.log(`不能识别type=${type}。`)
38
+ spinner.fail(`${consoleTag}type不能为空。`);
37
39
  }
38
40
  };
package/module/main.js CHANGED
@@ -2,11 +2,24 @@
2
2
  const buildAction = require('../src/build.js'); // 构建脚本:生产环境
3
3
  const devAction = require('../src/dev-server.js'); // 构建脚本:开发环境
4
4
  const build2esm = require('../src/build2esm.js'); // 构建esm输出模块
5
+ const inspect = require('./inspect.js');
6
+ const gitClone = require('../src/utils/gitClone.js');
7
+ const createFile = require('../src/utils/createFile');
8
+ const {resolve} = require('../src/utils/pathUtils');
9
+ const getConfigObj = require('../src/utils/getConfigObj');
10
+ const deepMergeConfig = require('../src/utils/deepMergeConfig');
5
11
  const getCurWebpackConfig = require('../src/utils/getCurWebpackConfig.js'); // 用于获取当前webpack配置的方法
6
12
 
7
13
  module.exports = {
8
14
  dev: devAction,
9
15
  build: buildAction,
10
16
  build2esm,
17
+ inspect,
18
+ gitClone,
19
+ createFile,
20
+ resolve,
21
+ getConfigObj,
22
+ deepMergeConfig,
23
+ getCurWebpackConfig,
11
24
  curWebpackBaseConfPath: getCurWebpackConfig('base'),
12
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akfun",
3
- "version": "1.5.17",
3
+ "version": "1.6.1",
4
4
  "description": "前端脚手架:支持Vue技术栈和react技术栈",
5
5
  "keywords": [
6
6
  "前端工程",
@@ -73,7 +73,6 @@
73
73
  "@rollup/plugin-node-resolve": "^9.0.0",
74
74
  "@typescript-eslint/eslint-plugin": "^3.9.0",
75
75
  "@typescript-eslint/parser": "^3.9.0",
76
- "eslint-config-prettier": "^7.2.0",
77
76
  "@vue/compiler-sfc": "^3.0.0-rc.10",
78
77
  "@vue/eslint-config-typescript": "^5.0.2",
79
78
  "autoprefixer": "^9.8.0",
@@ -92,6 +91,7 @@
92
91
  "es6-promise-polyfill": "^1.2.0",
93
92
  "eslint": "^7.2.0",
94
93
  "eslint-config-airbnb-base": "^14.1.0",
94
+ "eslint-config-prettier": "^7.2.0",
95
95
  "eslint-friendly-formatter": "^4.0.1",
96
96
  "eslint-import-resolver-webpack": "^0.12.1",
97
97
  "eslint-loader": "^4.0.2",
@@ -112,6 +112,7 @@
112
112
  "http-proxy-middleware": "^1.0.4",
113
113
  "inquirer": "^7.3.3",
114
114
  "mini-css-extract-plugin": "^0.9.0",
115
+ "monaco-editor-webpack-plugin": "6.0.0",
115
116
  "node-sass": "^4.14.1",
116
117
  "opn": "^6.0.0",
117
118
  "optimize-css-assets-webpack-plugin": "^5.0.3",
@@ -152,8 +153,8 @@
152
153
  "webpack-dev-middleware": "^3.7.2",
153
154
  "webpack-hot-middleware": "^2.25.0",
154
155
  "webpack-merge": "^4.2.2",
155
- "yargs": "^12.0.2",
156
- "webpack-node-externals": "^3.0.0"
156
+ "webpack-node-externals": "^3.0.0",
157
+ "yargs": "^12.0.2"
157
158
  },
158
159
  "devDependencies": {
159
160
  "@commitlint/cli": "^8.3.5",
package/src/build.js CHANGED
@@ -3,27 +3,31 @@ const rm = require('rimraf');
3
3
  const path = require('path');
4
4
  const chalk = require('chalk');
5
5
  const webpack = require('webpack');
6
+ const {curConsoleTag} = require("./utils/akfunParams");
6
7
  const checkVersion = require('./check-versions');
7
8
  const projectConfig = require('./config/index'); // 引入当前项目配置文件
9
+ const defaultConfig = require('./config/default.config');
8
10
  const deepMergeConfig = require('./utils/deepMergeConfig');
9
11
 
10
12
  // 构建脚本:一般用于构建生产环境的代码
11
- module.exports = function (BuildType, akfunConfig) {
13
+ module.exports = function (BuildType, akfunConfig, _consoleTag) {
14
+ const consoleTag = _consoleTag || curConsoleTag;
12
15
  let config = projectConfig; // 默认使用执行命令目录下的配置数据
13
16
  if (akfunConfig) {
17
+ // 参数中的config配置优先级最高
14
18
  config = deepMergeConfig(defaultConfig, akfunConfig);
15
19
  }
16
20
  // 检查当前npm版本号是否匹配
17
21
  checkVersion();
18
- const spinner = ora('[akfun]开启AKFun构建能力...').start();
22
+ const spinner = ora(`${consoleTag}开始构建...`).start();
19
23
  // 引入生产环境配置信息
20
24
  let webpackConfig;
21
25
  // 根据BuildType判断是否引用专用于第三方功能包的webpack配置
22
26
  if (BuildType && BuildType === 'lib') {
23
- spinner.start('[akfun]开始构建第三方功能包...');
27
+ spinner.start(`${consoleTag}开始构建lib库...`);
24
28
  webpackConfig = require('./webpack/webpack.library.conf')(config);
25
29
  } else {
26
- spinner.start('[akfun]开始构建生产环境的代码...');
30
+ spinner.start(`${consoleTag}开始构建生产环境的代码...`);
27
31
  webpackConfig = require('./webpack/webpack.prod.conf')(config);
28
32
  }
29
33
 
package/src/build2esm.js CHANGED
@@ -1,8 +1,11 @@
1
1
  const ora = require('ora');
2
2
  const rollup = require('rollup');
3
- const config = require('./config/index'); // 引入当前项目配置文件
3
+ const projectConfig = require('./config/index'); // 引入当前项目配置文件
4
+ const defaultConfig = require('./config/default.config');
4
5
  const rollupConfig = require('./config/rollup.config'); // rollup的配置文件
5
6
  const { isArray, isObject } = require('./utils/typeof');
7
+ const {curConsoleTag } = require("./utils/akfunParams");
8
+ const deepMergeConfig = require('./utils/deepMergeConfig');
6
9
 
7
10
  async function build2esmFunc(options) {
8
11
  // create a bundle
@@ -24,8 +27,14 @@ async function build2esmFunc(options) {
24
27
  }
25
28
 
26
29
  // 构建脚本:一般用于构建生产环境的代码
27
- module.exports = function (fileName) {
28
- const spinner = ora('[akfun]开启esm lib库的构建能力...').start();
30
+ module.exports = function (fileName, akfunConfig, _consoleTag) {
31
+ const consoleTag = _consoleTag || curConsoleTag;
32
+ let config = projectConfig; // 默认使用执行命令目录下的配置数据
33
+ if (akfunConfig) {
34
+ // 参数中的config配置优先级最高
35
+ config = deepMergeConfig(defaultConfig, akfunConfig);
36
+ }
37
+ const spinner = ora(`${consoleTag}开启esm lib库的构建能力...`).start();
29
38
  const curRollupConfig = rollupConfig(fileName); // 默认配置
30
39
  const build2esm = config.build2esm; // 用户的项目配置
31
40
  if (build2esm && build2esm.input) {
@@ -35,6 +44,6 @@ module.exports = function (fileName) {
35
44
  curRollupConfig.output = build2esm.output;
36
45
  }
37
46
  build2esmFunc(curRollupConfig).then(() => {
38
- spinner.succeed('[akfun]esm lib库构建完成');
47
+ spinner.succeed(`${consoleTag}esm lib库构建完成`);
39
48
  });
40
49
  };
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  // 统一路径解析:
3
2
  const { resolve } = require('../utils/pathUtils');
4
3
 
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  // 统一路径解析:
3
2
  const { resolve } = require('../utils/pathUtils');
4
3
  const defaultAKFunConfig = require('./default.config');
package/src/dev-server.js CHANGED
@@ -11,16 +11,19 @@ const projectConfig = require('./config/index');
11
11
  const defaultConfig = require('./config/default.config');
12
12
  const getDevWebpackConfig = require('./webpack/webpack.dev.conf');
13
13
  const deepMergeConfig = require('./utils/deepMergeConfig');
14
+ const {curConsoleTag } = require("./utils/akfunParams");
14
15
 
15
16
  // 构建脚本:一般用于构建开发环境的代码(包含热更新、接口代理等功能)
16
- module.exports = function (akfunConfig) {
17
+ module.exports = function (akfunConfig, _consoleTag) {
18
+ const consoleTag = _consoleTag || curConsoleTag;
17
19
  let config = projectConfig; // 默认使用执行命令目录下的配置数据
18
20
  if (akfunConfig) {
21
+ // 参数中的config配置优先级最高
19
22
  config = deepMergeConfig(defaultConfig, akfunConfig);
20
23
  }
21
24
  // 检查当前npm版本号是否匹配
22
25
  checkVersion();
23
- const spinner = ora('[akfun]开启调试模式...').start();
26
+ const spinner = ora(`${consoleTag}开启调试模式...`).start();
24
27
  /**
25
28
  * 如果 Node 的环境无法判断当前是 dev / product 环境
26
29
  * 使用 config.dev.NODE_ENV 作为当前的环境
@@ -112,7 +115,7 @@ module.exports = function (akfunConfig) {
112
115
  console.log(`> Listening at ${uri}\n`);
113
116
  // 如果是开发环境,自动打开浏览器并跳到项目首页
114
117
  if (autoOpenBrowser && process.NODE_ENV === 'development') {
115
- spinner.succeed('[akfun]调试模式已开启!');
118
+ spinner.succeed(`${consoleTag}调试模式已开启!`);
116
119
  opn(uri);
117
120
  }
118
121
  server = app.listen(port);
@@ -22,7 +22,7 @@ module.exports = {
22
22
  },
23
23
  resolve: {
24
24
  // webpack的resolve配置
25
- extensions: ['.js', '.jsx', '.vue', 'json'], // 用于配置webpack在尝试过程中用到的后缀列表
25
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', 'json'], // 用于配置webpack在尝试过程中用到的后缀列表
26
26
  alias: {
27
27
  '@': resolve('src'),
28
28
  $components: resolve('src/components'),
@@ -31,6 +31,8 @@ module.exports = {
31
31
  $utils: resolve('src/utils')
32
32
  }
33
33
  },
34
+ createDeclaration: false, // 打包时是否创建ts声明文件
35
+ ignoreNodeModules: false, // 打包时是否忽略 node_modules
34
36
  externals: [], // 从输出的 bundle 中排除依赖
35
37
  template: resolve('src/index.html'), // 默认使用的页面模板
36
38
  sassResources: []
@@ -0,0 +1,12 @@
1
+ var consoleTag = '[akfun]'; // 输出标记
2
+
3
+ function setConsoleTag(newText) {
4
+ consoleTag = newText;
5
+ }
6
+
7
+ module.exports = {
8
+ get curConsoleTag() {
9
+ return consoleTag;
10
+ },
11
+ setConsoleTag
12
+ };
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * 用于获取当前项目配置文件
3
3
  */
4
- module.exports = (type) => {
4
+ module.exports = (type, akfunConfig) => {
5
5
  let curConfig = {};
6
6
  if (type === 'dev') {
7
- curConfig = require('../webpack/webpack.dev.conf')();
7
+ curConfig = require('../webpack/webpack.dev.conf')(akfunConfig);
8
8
  } else if (type === 'lib') {
9
- curConfig = require('../webpack/webpack.library.conf')();
9
+ curConfig = require('../webpack/webpack.library.conf')(akfunConfig);
10
10
  } else if (type === 'build') {
11
- curConfig = require('../webpack/webpack.prod.conf')();
11
+ curConfig = require('../webpack/webpack.prod.conf')(akfunConfig);
12
12
  } else if (type === 'base') {
13
- curConfig = require('../webpack/webpack.base.conf')();
13
+ curConfig = require('../webpack/webpack.base.conf')(akfunConfig);
14
14
  }
15
15
  return curConfig;
16
16
  };
@@ -3,9 +3,11 @@ const ora = require('ora');
3
3
  const gitclone = require('git-clone');
4
4
  const rm = require('rimraf').sync;
5
5
  const { resolveToCurrentRoot } = require('../utils/pathUtils');
6
+ const {curConsoleTag} = require("./akfunParams");
6
7
 
7
- function gitClone(gitUrl, dir, callback) {
8
- const spinner = ora('[akfun]正在加载项目模板...').start();
8
+ function _gitClone(gitUrl, dir, callback, _consoleTag) {
9
+ const consoleTag = _consoleTag || curConsoleTag;
10
+ const spinner = ora(`${consoleTag}正在加载项目模板...`).start();
9
11
  gitclone(
10
12
  gitUrl,
11
13
  resolveToCurrentRoot(dir),
@@ -15,7 +17,7 @@ function gitClone(gitUrl, dir, callback) {
15
17
  (err) => {
16
18
  if (err === undefined) {
17
19
  rm(resolveToCurrentRoot(path.resolve(dir, '.git')));
18
- spinner.succeed('[akfun]项目模板加载完成!');
20
+ spinner.succeed(`${consoleTag}项目模板加载完成!`);
19
21
  callback();
20
22
  } else {
21
23
  console.log(err);
@@ -24,4 +26,4 @@ function gitClone(gitUrl, dir, callback) {
24
26
  }
25
27
  );
26
28
  }
27
- module.exports = gitClone;
29
+ module.exports = _gitClone;
@@ -44,7 +44,9 @@ module.exports = (akfunConfig) => {
44
44
  'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
45
45
  }),
46
46
  new MiniCssExtractPlugin({
47
- filename: utils.assetsPath('index.css'),
47
+ // filename: utils.assetsPath('index.css'),
48
+ filename: "[name].css",
49
+ chunkFilename: "[id].css",
48
50
  ignoreOrder: false
49
51
  }),
50
52
  new OptimizeCSSPlugin({
@@ -11,6 +11,7 @@ const CompressionWebpackPlugin = require('compression-webpack-plugin');
11
11
  const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
12
12
  const ProgressBarPlugin = require('progress-bar-webpack-plugin');
13
13
  const nodeExternals = require('webpack-node-externals');
14
+ const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
14
15
 
15
16
  const utils = require('./loaderUtils');
16
17
  const { resolve } = require('../utils/pathUtils'); // 统一路径解析
@@ -176,6 +177,11 @@ module.exports = (akfunConfig) => {
176
177
  })
177
178
  );
178
179
  }
180
+
181
+ // 是否开启
182
+ if (curEnvConfig.openMonacoWebpackPlugin) {
183
+ webpackProdConfig.plugins.push(new MonacoWebpackPlugin());
184
+ }
179
185
 
180
186
  if (curEnvConfig.bundleAnalyzerReport) {
181
187
  webpackProdConfig.plugins.push(new BundleAnalyzerPlugin());