qmzreact 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -45,10 +45,10 @@ yarn add --dev qmzreact
45
45
  示例配置:
46
46
  ```js
47
47
  module.exports = {
48
- port: 3000,
48
+ port: 8888,
49
49
  publicPath: '/',
50
50
  // 构建输出目录
51
- buildDir: 'dist',
51
+ buildDir: 'build',
52
52
  alias: {
53
53
  // 默认配置
54
54
  "@": path.resolve(__dirname, 'src')
@@ -60,12 +60,13 @@ module.exports = {
60
60
  pathRewrite: { '^/api': '' }
61
61
  }
62
62
  }
63
+ // 监听文件新增或删除 并重启服务,防止因为文件丢失而编译报错,默认只监听components 目录下的文件,如没有这个目录则不监听, 开启后,文件监听会占用大量cpu,请谨慎使用
63
64
  watch: ['./src/components'],
64
65
  // 是否启用 https服务
65
66
  isHttps: false,
66
67
  // 是否启用 dll
67
68
  dll: false,
68
- // 拆包
69
+ // 拆包,将第三方库单独打包,默认为{},为默认拆包,可自定义拆包,如:
69
70
  commonChunks: {
70
71
  "echarts": ["echarts", "zrender"],
71
72
  },
@@ -29,7 +29,8 @@ module.exports = {
29
29
  compression: 'gzip',
30
30
  buildDependencies: {
31
31
  config: [
32
- './build.config.js'
32
+ './build.config.js',
33
+ ...processConfig.cacheBuildDependencies
33
34
  ]
34
35
  }
35
36
  },
@@ -44,7 +45,8 @@ module.exports = {
44
45
  name: 'local_development',
45
46
  buildDependencies: {
46
47
  config: [
47
- './build.config.js'
48
+ './build.config.js',
49
+ ...processConfig.cacheBuildDependencies
48
50
  ]
49
51
  }
50
52
  },
@@ -1,8 +1,19 @@
1
- var path = require('path')
2
- var devMode = process.env.NODE_ENV !== 'production'
3
- var MiniCssExtractPlugin = require('mini-css-extract-plugin')
1
+ var path = require('path');
2
+ var fs = require('fs');
3
+ var devMode = process.env.NODE_ENV !== 'production';
4
+ var MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
5
  var { merge } = require('webpack-merge');
5
- var { utils, processConfig } = require('../options')
6
+ var { utils, processConfig } = require('../options');
7
+ var sassGlobalStyles = '';
8
+ processConfig.sassGlobalStyles.forEach((item) => {
9
+ return sassGlobalStyles += `@import "${item}";`;
10
+ });
11
+ try {
12
+ fs.accessSync(utils.rootPath('src/global.scss'), fs.constants.F_OK);
13
+ sassGlobalStyles += `@import "@/global.scss";`;
14
+ } catch (err) {
15
+ // console.log(err);
16
+ };
6
17
  module.exports = [
7
18
  {
8
19
  test: /\.t|jsx?$/,
@@ -59,7 +70,18 @@ module.exports = [
59
70
  }, processConfig.babelLoaderOptions)
60
71
  }
61
72
  ],
62
- exclude: /node_modules/,
73
+ exclude: (modulePath) => {
74
+ // 定义你"强制需要编译"的模块列表
75
+ const includeModules = processConfig.compileDependencies;
76
+ if (modulePath.includes('node_modules')) {
77
+ // 检查当前路径是否包含这些包名
78
+ const shouldInclude = includeModules.some(name =>
79
+ modulePath.includes(`node_modules${path.sep}${name}${path.sep}`));
80
+ return !shouldInclude;
81
+ } else {
82
+ return false;
83
+ }
84
+ }
63
85
  },
64
86
  {
65
87
  test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
@@ -122,7 +144,7 @@ module.exports = [
122
144
  {
123
145
  loader: "sass-loader",
124
146
  options: merge({
125
- additionalData: `@import "@/global.scss";`,
147
+ additionalData: sassGlobalStyles,
126
148
  implementation: require('sass'),
127
149
  sassOptions: {
128
150
  fiber: false,
package/conf/options.js CHANGED
@@ -7,7 +7,9 @@ var argvPort = argvs.indexOf('--port') > -1 ? argvs[argvs.indexOf('--port') + 1]
7
7
  var {
8
8
  watch, port, dll, commonChunks, proxy, eslint, entry,
9
9
  nodeMiddleware, publicPath, buildDir, eslintExclude, alias,
10
- cssLoaderOptions, postcssLoaderOptions, sassLoaderOptions, babelLoaderOptions,
10
+ cssLoaderOptions, postcssLoaderOptions, sassLoaderOptions,
11
+ babelLoaderOptions, cacheBuildDependencies, compileDependencies,
12
+ sassGlobalStyles,
11
13
  ...webpackConfig
12
14
  } = userConfig;
13
15
 
@@ -34,7 +36,10 @@ exports.processConfig = {
34
36
  cssLoaderOptions: utils.isObj(cssLoaderOptions) ? cssLoaderOptions : {},
35
37
  postcssLoaderOptions: utils.isObj(postcssLoaderOptions) ? postcssLoaderOptions : {},
36
38
  sassLoaderOptions: utils.isObj(sassLoaderOptions) ? sassLoaderOptions : {},
37
- babelLoaderOptions: utils.isObj(babelLoaderOptions) ? babelLoaderOptions : {}
39
+ babelLoaderOptions: utils.isObj(babelLoaderOptions) ? babelLoaderOptions : {},
40
+ cacheBuildDependencies: Array.isArray(cacheBuildDependencies) ? cacheBuildDependencies : [],
41
+ compileDependencies: Array.isArray(compileDependencies) ? compileDependencies : [],
42
+ sassGlobalStyles: Array.isArray(sassGlobalStyles) ? sassGlobalStyles : [],
38
43
  };
39
44
 
40
45
  exports.webpackConfig = merge({}, webpackConfig);
@@ -1,6 +1,7 @@
1
1
  var { spawn, exec, execSync } = require('child_process');
2
2
  var ora = require('ora');
3
3
  var path = require('path');
4
+ var chalk = require('chalk');
4
5
  var { utils, processConfig } = require('./options');
5
6
  var childProcess;
6
7
 
@@ -28,9 +29,19 @@ if (Array.isArray(processConfig.watch) && processConfig.watch.length > 0) {
28
29
  * 启动服务
29
30
  */
30
31
  module.exports = function startServer() {
31
- var spinner = ora('Starting dev server...');
32
+ var spinner = ora('Starting dev server... \n');
32
33
  spinner.start();
33
- childProcess = spawn('node', ['--max_old_space_size=4096', path.join(__dirname, './dev-server.js'), ...process.argv.slice(2)]);
34
+ childProcess = spawn(
35
+ 'node',
36
+ ['--max_old_space_size=4096', path.join(__dirname, './dev-server.js'), ...process.argv.slice(2)],
37
+ {
38
+ env: Object.assign({}, process.env, {
39
+ NODE_ENV: 'development', // 根据需要修改或添加其它环境变量
40
+ // EXAMPLE_VAR: 'value'
41
+ }),
42
+ stdio: 'pipe'
43
+ }
44
+ );
34
45
 
35
46
  // 监听子进程输出
36
47
  childProcess.stdout.on('data', (data) => {
@@ -46,15 +57,15 @@ module.exports = function startServer() {
46
57
  const m = str.match(/(\d{1,3})%/);
47
58
  if (m) {
48
59
  const pct = m[1];
49
- spinner.text = `Building ${pct}%`;
60
+ spinner.text = `Building ${chalk.green.bold(pct + '%')} `;
50
61
  if (pct === '100' || str.includes('100%')) {
51
- spinner.succeed('Build 100%');
62
+ spinner.succeed(chalk.green.bold('Build 100%'));
52
63
  if (spinner.isSpinning) spinner.stop();
53
64
  }
54
65
  return;
55
66
  }
56
67
  if (str.includes('100%')) {
57
- spinner.succeed('Build 100%');
68
+ spinner.succeed(chalk.green.bold('Build 100%'));
58
69
  if (spinner.isSpinning) spinner.stop();
59
70
  }
60
71
  // 捕获错误等信息并显示
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmzreact",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "前端react本地启动服务和打包工具",
5
5
  "author": {
6
6
  "name": "qmz",