qmzreact 1.0.13 → 1.0.14

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
@@ -1,92 +1,92 @@
1
- # buildreact
2
-
3
- 轻量级的 React 项目服务与构建工具,用于本地开发、构建与静态服务部署。
4
-
5
- ## 特性
6
- - 本地开发服务器(热重载)
7
- - 项目构建(生产优化)
8
- - 静态文件预览/发布
9
- - 可扩展的配置项与插件接口
10
-
11
- ## 环境要求
12
- - Node.js >= 12
13
- - npm 或 yarn
14
-
15
- ## 安装
16
- 在项目根目录运行(示例):
17
- ```bash
18
- # 使用 npm
19
- npm install --save-dev qmzreact
20
-
21
- # 或使用 yarn
22
- yarn add --dev qmzreact
23
- ```
24
-
25
- ## 使用(示例)
26
- 在 package.json 中添加脚本:
27
- ```json
28
- {
29
- "scripts": {
30
- "dev": "qmzreact dev",
31
- "build": "qmzreact build",
32
- "dll": "qmzreact dll",
33
- }
34
- }
35
- ```
36
-
37
- 常用命令:
38
- - npm run dev — 启动开发服务器(支持热重载)
39
- - npm run build — 进行生产构建(压缩、代码分割)
40
- - npm run dll — 启用dll时, 用于构建dll文件
41
-
42
- ## 配置
43
- 支持项目根目录下的配置文件:
44
- - build.config.js
45
- 示例配置:
46
- ```js
47
- module.exports = {
48
- port: 8888,
49
- publicPath: '/',
50
- // 构建输出目录
51
- buildDir: 'build',
52
- alias: {
53
- // 默认配置
54
- "@": path.resolve(__dirname, 'src')
55
- },
56
- // 代理配置
57
- proxy: {
58
- '/api': {
59
- target: 'http://localhost:8080',
60
- pathRewrite: { '^/api': '' }
61
- }
62
- }
63
- // 监听文件新增或删除 并重启服务,防止因为文件丢失而编译报错,默认只监听components 目录下的文件,如没有这个目录则不监听, 开启后,文件监听会占用大量cpu,请谨慎使用
64
- watch: ['./src/components'],
65
- // 是否启用 https服务
66
- isHttps: false,
67
- // 是否启用 dll
68
- dll: false,
69
- // 拆包,将第三方库单独打包,默认为{},为默认拆包,可自定义拆包,如:
70
- commonChunks: {
71
- "echarts": ["echarts", "zrender"],
72
- },
73
- // 是否启用 eslint
74
- eslint: false,
75
- // 排除eslint检查的文件
76
- eslintExclude: ['./src/oldCode'],
77
- // node 服务中间件函数
78
- nodeMiddleware: function(req, res){},
79
- // webpack配置
80
- cssLoaderOptions: {},
81
- postcssLoaderOptions: {},
82
- sassLoaderOptions: {},
83
- babelLoaderOptions: {},
84
-
85
- };
86
- ```
87
-
88
- ## 贡献
89
- 欢迎提交 issue 与 PR。请遵循代码风格并补充必要的测试与文档。
90
-
91
- ## 许可证
1
+ # buildreact
2
+
3
+ 轻量级的 React 项目服务与构建工具,用于本地开发、构建与静态服务部署。
4
+
5
+ ## 特性
6
+ - 本地开发服务器(热重载)
7
+ - 项目构建(生产优化)
8
+ - 静态文件预览/发布
9
+ - 可扩展的配置项与插件接口
10
+
11
+ ## 环境要求
12
+ - Node.js >= 12
13
+ - npm 或 yarn
14
+
15
+ ## 安装
16
+ 在项目根目录运行(示例):
17
+ ```bash
18
+ # 使用 npm
19
+ npm install --save-dev qmzreact
20
+
21
+ # 或使用 yarn
22
+ yarn add --dev qmzreact
23
+ ```
24
+
25
+ ## 使用(示例)
26
+ 在 package.json 中添加脚本:
27
+ ```json
28
+ {
29
+ "scripts": {
30
+ "dev": "qmzreact dev",
31
+ "build": "qmzreact build",
32
+ "dll": "qmzreact dll",
33
+ }
34
+ }
35
+ ```
36
+
37
+ 常用命令:
38
+ - npm run dev — 启动开发服务器(支持热重载)
39
+ - npm run build — 进行生产构建(压缩、代码分割)
40
+ - npm run dll — 启用dll时, 用于构建dll文件
41
+
42
+ ## 配置
43
+ 支持项目根目录下的配置文件:
44
+ - build.config.js
45
+ 示例配置:
46
+ ```js
47
+ module.exports = {
48
+ port: 8888,
49
+ publicPath: '/',
50
+ // 构建输出目录
51
+ buildDir: 'build',
52
+ alias: {
53
+ // 默认配置
54
+ "@": path.resolve(__dirname, 'src')
55
+ },
56
+ // 代理配置
57
+ proxy: {
58
+ '/api': {
59
+ target: 'http://localhost:8080',
60
+ pathRewrite: { '^/api': '' }
61
+ }
62
+ }
63
+ // 监听文件新增或删除 并重启服务,防止因为文件丢失而编译报错,默认只监听components 目录下的文件,如没有这个目录则不监听, 开启后,文件监听会占用大量cpu,请谨慎使用
64
+ watch: ['./src/components'],
65
+ // 是否启用 https服务
66
+ isHttps: false,
67
+ // 是否启用 dll
68
+ dll: false,
69
+ // 拆包,将第三方库单独打包,默认为{},为默认拆包,可自定义拆包,如:
70
+ commonChunks: {
71
+ "echarts": ["echarts", "zrender"],
72
+ },
73
+ // 是否启用 eslint
74
+ eslint: false,
75
+ // 排除eslint检查的文件
76
+ eslintExclude: ['./src/oldCode'],
77
+ // node 服务中间件函数
78
+ nodeMiddleware: function(req, res){},
79
+ // webpack配置
80
+ cssLoaderOptions: {},
81
+ postcssLoaderOptions: {},
82
+ sassLoaderOptions: {},
83
+ babelLoaderOptions: {},
84
+
85
+ };
86
+ ```
87
+
88
+ ## 贡献
89
+ 欢迎提交 issue 与 PR。请遵循代码风格并补充必要的测试与文档。
90
+
91
+ ## 许可证
92
92
  MIT(如需其它许可证,请在此处替换)
package/bin/qmzreact.js CHANGED
@@ -1,30 +1,30 @@
1
- #!/usr/bin/env node
2
-
3
- const { startService, buildPack, buildDll } = require('../index');
4
-
5
- const command = process.argv[2];
6
-
7
- async function run() {
8
- try {
9
- switch (command) {
10
- case 'dev':
11
- // 如果是异步的,加 await
12
- startService();
13
- break;
14
- case 'build':
15
- buildPack();
16
- break;
17
- case 'dll':
18
- buildDll();
19
- break;
20
- default:
21
- console.log('未知命令...');
22
- process.exit(1);
23
- }
24
- } catch (error) {
25
- console.error('执行出错:', error);
26
- process.exit(1);
27
- }
28
- }
29
-
1
+ #!/usr/bin/env node
2
+
3
+ const { startService, buildPack, buildDll } = require('../index');
4
+
5
+ const command = process.argv[2];
6
+
7
+ async function run() {
8
+ try {
9
+ switch (command) {
10
+ case 'dev':
11
+ // 如果是异步的,加 await
12
+ startService();
13
+ break;
14
+ case 'build':
15
+ buildPack();
16
+ break;
17
+ case 'dll':
18
+ buildDll();
19
+ break;
20
+ default:
21
+ console.log('未知命令...');
22
+ process.exit(1);
23
+ }
24
+ } catch (error) {
25
+ console.error('执行出错:', error);
26
+ process.exit(1);
27
+ }
28
+ }
29
+
30
30
  run();
package/conf/build.js CHANGED
@@ -1,31 +1,31 @@
1
- // https://github.com/shelljs/shelljs
2
- require('shelljs/global')
3
- module.exports = function buildPackage() {
4
- env.NODE_ENV = 'production'
5
- var path = require('path')
6
- var config = require('./config')
7
- var ora = require('ora')
8
- var webpack = require('webpack')
9
- var webpackConfig = require('./config/webpack.prod.conf')
10
- var spinner = ora('building for production...')
11
- spinner.start()
12
- var assetsRoot = path.resolve(config.build.assetsRoot)
13
-
14
- rm('-rf', assetsRoot) // 删除 assetsRoot(dist) 目录下的文件及目录, 忽略不存在的目录
15
- mkdir('-p', assetsRoot) // 若路径中的某些目录尚不存在, 系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录
16
- cp('-R', 'public/*', assetsRoot) // 复制目录及目录内的所有项目
17
-
18
- // webpack 打包
19
- webpack(webpackConfig, function (err, stats) {
20
- spinner.stop()
21
- if (err) throw err
22
- process.stdout.write(stats.toString({
23
- colors: true,
24
- modules: false,
25
- children: false,
26
- chunks: false,
27
- chunkModules: false
28
- }) + '\n')
29
- })
30
- }
31
-
1
+ // https://github.com/shelljs/shelljs
2
+ require('shelljs/global')
3
+ module.exports = function buildPackage() {
4
+ env.NODE_ENV = 'production'
5
+ var path = require('path')
6
+ var config = require('./config')
7
+ var ora = require('ora')
8
+ var webpack = require('webpack')
9
+ var webpackConfig = require('./config/webpack.prod.conf')
10
+ var spinner = ora('building for production...')
11
+ spinner.start()
12
+ var assetsRoot = path.resolve(config.build.assetsRoot)
13
+
14
+ rm('-rf', assetsRoot) // 删除 assetsRoot(dist) 目录下的文件及目录, 忽略不存在的目录
15
+ mkdir('-p', assetsRoot) // 若路径中的某些目录尚不存在, 系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录
16
+ cp('-R', 'public/*', assetsRoot) // 复制目录及目录内的所有项目
17
+
18
+ // webpack 打包
19
+ webpack(webpackConfig, function (err, stats) {
20
+ spinner.stop()
21
+ if (err) throw err
22
+ process.stdout.write(stats.toString({
23
+ colors: true,
24
+ modules: false,
25
+ children: false,
26
+ chunks: false,
27
+ chunkModules: false
28
+ }) + '\n')
29
+ })
30
+ }
31
+
@@ -1,34 +1,34 @@
1
- var webpack = require('webpack')
2
- var path = require('path')
3
- var config = require('./index')
4
- module.exports = {
5
- chunks: 'all',
6
- maxInitialRequests: 10,
7
- minSize: 50000,
8
- minChunks: 4,
9
- cacheGroups: {
10
- vendor: {
11
- test: /[\\/]node_modules[\\/]/,
12
- minChunks: 2,
13
- name(module) {
14
- const test = module.context.match(
15
- /[\\/]node_modules[\\/](.*?)([\\/]|$)/,
16
- )
17
- const packageName = test && test[1] || '';
18
- let chunkName = null;
19
- const chunks = config.build.assetsChunks || {};
20
- Object.entries(chunks).forEach(([name, key]) => {
21
- key.forEach(k => {
22
- if (packageName.includes(k)) {
23
- chunkName = name
24
- }
25
- })
26
- })
27
- return chunkName;
28
- },
29
- },
30
- default: {
31
- name: 'vendor_common'
32
- }
33
- },
1
+ var webpack = require('webpack')
2
+ var path = require('path')
3
+ var config = require('./index')
4
+ module.exports = {
5
+ chunks: 'all',
6
+ maxInitialRequests: 10,
7
+ minSize: 50000,
8
+ minChunks: 4,
9
+ cacheGroups: {
10
+ vendor: {
11
+ test: /[\\/]node_modules[\\/]/,
12
+ minChunks: 2,
13
+ name(module) {
14
+ const test = module.context.match(
15
+ /[\\/]node_modules[\\/](.*?)([\\/]|$)/,
16
+ )
17
+ const packageName = test && test[1] || '';
18
+ let chunkName = null;
19
+ const chunks = config.build.assetsChunks || {};
20
+ Object.entries(chunks).forEach(([name, key]) => {
21
+ key.forEach(k => {
22
+ if (packageName.includes(k)) {
23
+ chunkName = name
24
+ }
25
+ })
26
+ })
27
+ return chunkName;
28
+ },
29
+ },
30
+ default: {
31
+ name: 'vendor_common'
32
+ }
33
+ },
34
34
  }
@@ -1,56 +1,56 @@
1
- var path = require('path');
2
- var { processConfig, webpackConfig, utils } = require('../options');
3
- var dllChunks = Array.isArray(processConfig.dll.chunks) ? processConfig.dll.chunks : [];
4
- var commonChunks = utils.isObj(processConfig.commonChunks) ? processConfig.commonChunks : {};
5
- var proxy = utils.isObj(processConfig.proxy) ? processConfig.proxy : {};
6
- var proxyTable = {};
7
- for (let key in proxy) {
8
- proxyTable[key] = {
9
- target: proxy[key].target,
10
- changeOrigin: true,
11
- pathRewrite: proxy[key].pathRewrite || { [`^${key}`]: '' },
12
- secure: false,
13
- }
14
- };
15
-
16
-
17
- module.exports = {
18
- build: {
19
- assetsRoot: processConfig.outpath,
20
- assetsPublicPath: processConfig.publicPath,
21
- assetsDllChunks: {
22
- ['react-vendor']: ['react', 'react-dom', 'react-router', 'react-router-dom', ...dllChunks],
23
- },
24
- assetsChunks: commonChunks,
25
- cachesDllDirectory: {
26
- type: 'filesystem',
27
- name: 'build_production',
28
- // 开启压缩
29
- compression: 'gzip',
30
- buildDependencies: {
31
- config: [
32
- './build.config.js',
33
- ...processConfig.cacheBuildDependencies
34
- ]
35
- }
36
- },
37
- },
38
- dev: {
39
- port: processConfig.port,
40
- eslint: processConfig.eslint,
41
- assetsDllOutPath: processConfig.dll.outpath,
42
- assetsPublicPath: processConfig.publicPath,
43
- cachesDllDirectory: {
44
- type: 'filesystem',
45
- name: 'local_development',
46
- buildDependencies: {
47
- config: [
48
- './build.config.js',
49
- ...processConfig.cacheBuildDependencies
50
- ]
51
- }
52
- },
53
- proxyTable,
54
- cssSourceMap: false
55
- }
56
- }
1
+ var path = require('path');
2
+ var { processConfig, webpackConfig, utils } = require('../options');
3
+ var dllChunks = Array.isArray(processConfig.dll.chunks) ? processConfig.dll.chunks : [];
4
+ var commonChunks = utils.isObj(processConfig.commonChunks) ? processConfig.commonChunks : {};
5
+ var proxy = utils.isObj(processConfig.proxy) ? processConfig.proxy : {};
6
+ var proxyTable = {};
7
+ for (let key in proxy) {
8
+ proxyTable[key] = {
9
+ target: proxy[key].target,
10
+ changeOrigin: true,
11
+ pathRewrite: proxy[key].pathRewrite || { [`^${key}`]: '' },
12
+ secure: false,
13
+ }
14
+ };
15
+
16
+
17
+ module.exports = {
18
+ build: {
19
+ assetsRoot: processConfig.outpath,
20
+ assetsPublicPath: processConfig.publicPath,
21
+ assetsDllChunks: {
22
+ ['react-vendor']: ['react', 'react-dom', 'react-router', 'react-router-dom', ...dllChunks],
23
+ },
24
+ assetsChunks: commonChunks,
25
+ cachesDllDirectory: {
26
+ type: 'filesystem',
27
+ name: 'build_production',
28
+ // 开启压缩
29
+ compression: 'gzip',
30
+ buildDependencies: {
31
+ config: [
32
+ './build.config.js',
33
+ ...processConfig.cacheBuildDependencies
34
+ ]
35
+ }
36
+ },
37
+ },
38
+ dev: {
39
+ port: processConfig.port,
40
+ eslint: processConfig.eslint,
41
+ assetsDllOutPath: processConfig.dll.outpath,
42
+ assetsPublicPath: processConfig.publicPath,
43
+ cachesDllDirectory: {
44
+ type: 'filesystem',
45
+ name: 'local_development',
46
+ buildDependencies: {
47
+ config: [
48
+ './build.config.js',
49
+ ...processConfig.cacheBuildDependencies
50
+ ]
51
+ }
52
+ },
53
+ proxyTable,
54
+ cssSourceMap: false
55
+ }
56
+ }