neo-cmp-cli 1.0.0
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 +236 -0
- package/bin/neo.js +2 -0
- package/package.json +74 -0
- package/src/config/default.config.js +136 -0
- package/src/config/index.js +9 -0
- package/src/initData/defaultTemplate.html +13 -0
- package/src/initData/neo.config.js +99 -0
- package/src/module/index.js +244 -0
- package/src/module/inspect.js +40 -0
- package/src/module/main.js +109 -0
- package/src/module/neoInit.js +44 -0
- package/src/module/neoInitByCopy.js +37 -0
- package/src/oss/publish2oss.js +218 -0
- package/src/plugins/README.md +2 -0
- package/src/template/react-custom-widget-template/.editorconfig +10 -0
- package/src/template/react-custom-widget-template/.prettierrc.js +12 -0
- package/src/template/react-custom-widget-template/README.md +51 -0
- package/src/template/react-custom-widget-template/commitlint.config.js +59 -0
- package/src/template/react-custom-widget-template/neo.config.js +112 -0
- package/src/template/react-custom-widget-template/package.json +56 -0
- package/src/template/react-custom-widget-template/public/css/base.css +283 -0
- package/src/template/react-custom-widget-template/public/scripts/app/bluebird.js +6679 -0
- package/src/template/react-custom-widget-template/public/template.html +13 -0
- package/src/template/react-custom-widget-template/src/assets/css/common.scss +127 -0
- package/src/template/react-custom-widget-template/src/assets/css/mixin.scss +47 -0
- package/src/template/react-custom-widget-template/src/components/info-card/index.jsx +45 -0
- package/src/template/react-custom-widget-template/src/components/info-card/model.js +81 -0
- package/src/template/react-custom-widget-template/src/components/info-card/register.js +4 -0
- package/src/template/react-custom-widget-template/src/components/info-card/style.scss +67 -0
- package/src/template/react-custom-widget-template/src/preview.js +5 -0
- package/src/template/react-ts-custom-widget-template/.editorconfig +10 -0
- package/src/template/react-ts-custom-widget-template/.prettierrc.js +12 -0
- package/src/template/react-ts-custom-widget-template/README.md +53 -0
- package/src/template/react-ts-custom-widget-template/commitlint.config.js +59 -0
- package/src/template/react-ts-custom-widget-template/neo.config.js +106 -0
- package/src/template/react-ts-custom-widget-template/package.json +59 -0
- package/src/template/react-ts-custom-widget-template/public/css/base.css +283 -0
- package/src/template/react-ts-custom-widget-template/public/scripts/app/bluebird.js +6679 -0
- package/src/template/react-ts-custom-widget-template/public/template.html +13 -0
- package/src/template/react-ts-custom-widget-template/src/assets/css/common.scss +127 -0
- package/src/template/react-ts-custom-widget-template/src/assets/css/mixin.scss +47 -0
- package/src/template/react-ts-custom-widget-template/src/components/info-card/index.tsx +70 -0
- package/src/template/react-ts-custom-widget-template/src/components/info-card/plugin.ts +80 -0
- package/src/template/react-ts-custom-widget-template/src/components/info-card/register.ts +5 -0
- package/src/template/react-ts-custom-widget-template/src/components/info-card/style.scss +105 -0
- package/src/template/react-ts-custom-widget-template/src/components/list-widget/README.md +2 -0
- package/src/template/react-ts-custom-widget-template/src/components/list-widget/index.tsx +208 -0
- package/src/template/react-ts-custom-widget-template/src/components/list-widget/model.ts +92 -0
- package/src/template/react-ts-custom-widget-template/src/components/list-widget/register.ts +5 -0
- package/src/template/react-ts-custom-widget-template/src/components/list-widget/style.scss +350 -0
- package/src/template/react-ts-custom-widget-template/src/preview.tsx +37 -0
- package/src/template/react-ts-custom-widget-template/tsconfig.json +68 -0
- package/src/template/vue2-neo-custom-widget/.editorconfig +10 -0
- package/src/template/vue2-neo-custom-widget/.prettierrc.js +12 -0
- package/src/template/vue2-neo-custom-widget/README.md +52 -0
- package/src/template/vue2-neo-custom-widget/commitlint.config.js +59 -0
- package/src/template/vue2-neo-custom-widget/neo.config.js +122 -0
- package/src/template/vue2-neo-custom-widget/package.json +59 -0
- package/src/template/vue2-neo-custom-widget/public/css/base.css +283 -0
- package/src/template/vue2-neo-custom-widget/public/scripts/app/bluebird.js +6679 -0
- package/src/template/vue2-neo-custom-widget/public/template.html +13 -0
- package/src/template/vue2-neo-custom-widget/src/assets/css/common.scss +126 -0
- package/src/template/vue2-neo-custom-widget/src/assets/css/mixin.scss +47 -0
- package/src/template/vue2-neo-custom-widget/src/preview.js +9 -0
- package/src/template/vue2-neo-custom-widget/src/widgets/info-card/index.vue +131 -0
- package/src/template/vue2-neo-custom-widget/src/widgets/info-card/plugin.js +81 -0
- package/src/template/vue2-neo-custom-widget/src/widgets/info-card/register.js +8 -0
- package/src/utils/getConfigObj.js +18 -0
- package/src/utils/getEntries.js +54 -0
- package/src/utils/neoConfigInit.js +13 -0
- package/src/utils/neoParams.js +12 -0
- package/src/utils/pathUtils.js +23 -0
- package/src/utils/projectNameValidator.js +76 -0
- package/src/utils/replaceInFiles.js +47 -0
- package/src/utils/replaceInPackage.js +134 -0
- package/test/demo.js +3 -0
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
## Neo 自定义组件开发工具
|
|
2
|
+
neo-cmp-cli 是 Neo 自定义组件开发工具,基于 [AKFun](https://github.com/wibetter/akfun) 的工程能力,提供模板创建、编译构建、预览调试、多技术栈支持与一键发布。
|
|
3
|
+
|
|
4
|
+
### 主要特性
|
|
5
|
+
- **零配置**: 内置默认配置,开箱可用;
|
|
6
|
+
- **多技术栈**: 支持 Vue2、React、React+TypeScript 自定义组件的调试、构建与发布;
|
|
7
|
+
- **多构建场景**: 本地预览(含热更新/代理)、外链调试、库构建(UMD/ESM);
|
|
8
|
+
- **灵活可配**: 支持 构建入口、别名、代理、SASS 注入、ESLint/StyleLint、Babel/Loader/Plugin 扩展等配置;
|
|
9
|
+
- **样式与规范**: 内置 Autoprefixer、Sass、PostCSS、ESLint、StyleLint;
|
|
10
|
+
- **参数替换**: 支持基于 [params-replace-loader](https://www.npmjs.com/package/params-replace-loader) 的环境变量批量替换;
|
|
11
|
+
- **一键发布**: 内置发布到 OSS 的能力,支持自定义对象存储配置。
|
|
12
|
+
|
|
13
|
+
### 模板类型(neo init 可选)
|
|
14
|
+
- **React 模板**: [react-custom-widget-template](https://github.com/wibetter/react-custom-widget-template)
|
|
15
|
+
- **React + TS 模板**: [react-ts-custom-widget-template](https://github.com/wibetter/react-ts-custom-widget-template)
|
|
16
|
+
- **Vue2 模板**: [vue2-neo-custom-widget](https://github.com/wibetter/vue2-neo-custom-widget)
|
|
17
|
+
|
|
18
|
+
## 快速开始
|
|
19
|
+
|
|
20
|
+
### 方法一:全局安装
|
|
21
|
+
1) 安装
|
|
22
|
+
```bash
|
|
23
|
+
yarn global add neo-cmp-cli
|
|
24
|
+
# 或
|
|
25
|
+
npm i -g neo-cmp-cli
|
|
26
|
+
```
|
|
27
|
+
2) 创建项目(默认 React+TS,可用 -t 指定模板,--name 指定项目名)
|
|
28
|
+
```bash
|
|
29
|
+
neo init -t=react&ts
|
|
30
|
+
```
|
|
31
|
+
3) 安装依赖并运行
|
|
32
|
+
```bash
|
|
33
|
+
# 预览自定义组件内容
|
|
34
|
+
npm run preview
|
|
35
|
+
|
|
36
|
+
# 外链调试(在平台线上预览与调试)
|
|
37
|
+
npm run linkDebug
|
|
38
|
+
|
|
39
|
+
# 构建库产物(默认输出到 dist)
|
|
40
|
+
npm run build2lib
|
|
41
|
+
|
|
42
|
+
# 构建并发布到 OSS(确保 package.json 的 name 唯一、version 不重复)
|
|
43
|
+
npm run publish2oss
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 方法二:在现有项目中使用
|
|
47
|
+
1) 安装到当前项目
|
|
48
|
+
```bash
|
|
49
|
+
yarn add neo-cmp-cli --dev
|
|
50
|
+
# 或
|
|
51
|
+
npm i neo-cmp-cli --save-dev
|
|
52
|
+
```
|
|
53
|
+
2) 在 package.json 添加脚本
|
|
54
|
+
```bash
|
|
55
|
+
"preview": "neo preview",
|
|
56
|
+
"linkDebug": "neo linkDebug",
|
|
57
|
+
"build2lib": "neo build2lib"
|
|
58
|
+
```
|
|
59
|
+
3) 初始化配置文件
|
|
60
|
+
```bash
|
|
61
|
+
neo config init
|
|
62
|
+
```
|
|
63
|
+
4) 开发调试
|
|
64
|
+
```bash
|
|
65
|
+
npm run preview
|
|
66
|
+
npm run linkDebug
|
|
67
|
+
npm run build2lib
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 常用命令
|
|
71
|
+
- **neo init**: 交互式创建项目(支持 -t、--name)。
|
|
72
|
+
- **neo preview**: 本地预览自定义组件内容,默认支持热更新与接口代理。
|
|
73
|
+
- **neo linkDebug**: 外链调试模式,在平台端页面设计器中联调组件。
|
|
74
|
+
- **neo build2lib**: 产出 UMD/ESM 库文件(可配置)。
|
|
75
|
+
- **neo publish2oss**: 构建并上传到对象存储(可自定义配置)。
|
|
76
|
+
|
|
77
|
+
## 配置说明(neo.config.js)
|
|
78
|
+
neo-cmp-cli 默认提供完整配置;如需自定义,使用 `neo config init` 生成 `neo.config.js` 并按需修改。
|
|
79
|
+
以下为常用配置示例(片段可自由组合)。
|
|
80
|
+
|
|
81
|
+
### 1) 基础规范与检查
|
|
82
|
+
```bash
|
|
83
|
+
module.exports = {
|
|
84
|
+
settings: {
|
|
85
|
+
enableESLint: true, // 是否开启ESLint,默认开启ESLint检测代码格式
|
|
86
|
+
enableESLintFix: false, // 是否ESLint自动修正代码格式
|
|
87
|
+
enableStyleLint: true, // 是否开启StyleLint,默认开启ESLint检测代码格式
|
|
88
|
+
enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2) 构建入口(优先级:preview/linkDebug/build2lib.entry > webpack.entry)
|
|
94
|
+
```bash
|
|
95
|
+
module.exports = {
|
|
96
|
+
webpack: {
|
|
97
|
+
entry: { index: './src/index.js' },
|
|
98
|
+
},
|
|
99
|
+
preview: { entry: {} },
|
|
100
|
+
linkDebug: { entry: {} },
|
|
101
|
+
build2lib: { entry: {} },
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
备注1: 当未配置 entry 时,cli 会自动根据 src/components 目录自动生成 entry 配置;
|
|
105
|
+
备注2: 详细配置方法请查看 Webpack 官网 ([关于entry的配置方法](https://www.webpackjs.com/configuration/entry-context/#entry))。
|
|
106
|
+
|
|
107
|
+
### 3) 解析配置(extensions/alias)
|
|
108
|
+
```bash
|
|
109
|
+
module.exports = {
|
|
110
|
+
webpack: {
|
|
111
|
+
resolve: {
|
|
112
|
+
extensions: ['.js', '.jsx', '.vue', 'json'],
|
|
113
|
+
alias: {},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
备注1: extensions 的详细配置方法请查看Webpack官网 ([关于resolve-extensions的配置方法](https://www.webpackjs.com/configuration/resolve/#resolve-extensions));
|
|
119
|
+
备注2: alias 的详细配置方法请查看 Webpack 官网 ([关于resolve-alias的配置方法](https://www.webpackjs.com/configuration/resolve/#resolve-alias))。
|
|
120
|
+
|
|
121
|
+
### 4) 页面模板与样式资源
|
|
122
|
+
```bash
|
|
123
|
+
module.exports = {
|
|
124
|
+
webpack: {
|
|
125
|
+
template: '', // 自定义页面模板路径
|
|
126
|
+
sassResources: [], // sassResources 中添加的 样式文件会作为项目的公共SASS内容(变量、mixin、function等)
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 5) 依赖打包策略(忽略 node_modules)
|
|
132
|
+
```bash
|
|
133
|
+
module.exports = {
|
|
134
|
+
webpack: {
|
|
135
|
+
ignoreNodeModules: true, // 打包时是否忽略 node_modules,默认为false
|
|
136
|
+
allowList: [], // 用于配置会注入bundle中的依赖包(ignoreNodeModules 为 true 时生效)
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 6) TypeScript 声明文件与工程目录
|
|
142
|
+
```bash
|
|
143
|
+
module.exports = {
|
|
144
|
+
webpack: {
|
|
145
|
+
createDeclaration: false, // 可选择是否生成ts声明文件,默认为false
|
|
146
|
+
projectDir: ['./src'], // 构建项目中,设置生效的目录(可同时设置多个目录),用于提高前端工程执行效率。可以不配置,默认为['./src']
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 7) 环境变量替换(params-replace-loader)
|
|
152
|
+
```bash
|
|
153
|
+
module.exports = {
|
|
154
|
+
envParams: {
|
|
155
|
+
common: { '#version#': '20250822.1' },
|
|
156
|
+
local: {
|
|
157
|
+
'#dataApiBase#': 'http://localhost:1024',
|
|
158
|
+
'#assetsPublicPath#': 'http://localhost:1024',
|
|
159
|
+
'#routeBasePath#': '/',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 8) 本地开发代理与 HTTPS
|
|
166
|
+
```bash
|
|
167
|
+
module.exports = {
|
|
168
|
+
preview: {
|
|
169
|
+
proxyTable: {},
|
|
170
|
+
https: false,
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
备注1: [关于proxyTable的配置方法](https://www.webpackjs.com/configuration/dev-server/#devserver-proxy);
|
|
175
|
+
备注2: 启用 HTTPS 后,若浏览器提示不安全,可在 Chrome 地址栏打开 `chrome://flags/#allow-insecure-localhost` 并设置为 Enabled。
|
|
176
|
+
|
|
177
|
+
### 9) 库构建(UMD/ESM)
|
|
178
|
+
```bash
|
|
179
|
+
module.exports = {
|
|
180
|
+
build2lib: {
|
|
181
|
+
NODE_ENV: 'production',
|
|
182
|
+
libraryName: '',
|
|
183
|
+
assetsRoot: resolve('dist'),
|
|
184
|
+
assetsPublicPath: '/',
|
|
185
|
+
assetsSubDirectory: '',
|
|
186
|
+
productionSourceMap: false,
|
|
187
|
+
productionGzip: false,
|
|
188
|
+
productionGzipExtensions: ['js', 'css', 'json'],
|
|
189
|
+
bundleAnalyzerReport: false,
|
|
190
|
+
ignoreNodeModules: true,
|
|
191
|
+
allowList: [],
|
|
192
|
+
},
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 10) 自定义 Loader / Plugin / Babel Plugins
|
|
197
|
+
```bash
|
|
198
|
+
module.exports = {
|
|
199
|
+
webpack: {
|
|
200
|
+
moduleRules: [], // 用于添加自定义 loaders
|
|
201
|
+
plugins: [], // 用于添加自定义 plugins
|
|
202
|
+
babelPlugins: [ // 用于添加自定义 Babel plugins
|
|
203
|
+
[
|
|
204
|
+
'component',
|
|
205
|
+
{ libraryName: 'element-ui', styleLibraryName: 'theme-chalk' },
|
|
206
|
+
],
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
备注: 以上自定义 babelPlugins 用于实现 [element-ui 组件按需引入](https://element.eleme.cn/#/zh-CN/component/quickstart#an-xu-yin-ru)。
|
|
212
|
+
|
|
213
|
+
也支持以函数形式动态调整内置 Babel Plugins:
|
|
214
|
+
```bash
|
|
215
|
+
module.exports = {
|
|
216
|
+
webpack: {
|
|
217
|
+
babelPlugins: (curBabelPlugins) => {
|
|
218
|
+
curBabelPlugins.push(/* your plugin */)
|
|
219
|
+
return curBabelPlugins
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## 多页面与模板
|
|
226
|
+
- **多页面入口**: 当 `entry` 仅配置一个且对应文件不存在时,会自动从 `src/pages` 扫描以 `.ts/.tsx/.js/.jsx` 结尾的文件作为入口,匹配同名 HTML 作为模板。
|
|
227
|
+
- **模板选择**: 优先使用 `./src/index.html`;不存在时使用内置默认模板。多页面时若存在同名 HTML,将其作为页面模板。
|
|
228
|
+
|
|
229
|
+
## 发布到对象存储(OSS)
|
|
230
|
+
执行 `npm run publish2oss` 即可构建并上传到对象存储。发布前请确保:
|
|
231
|
+
- **package.json 的 name 唯一**
|
|
232
|
+
- **version 不重复**
|
|
233
|
+
- 已按需配置对象存储参数(支持自定义)
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
如需更多细节与高级用法,请参考模板项目与源码注释。
|
package/bin/neo.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "neo-cmp-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"neo-cli",
|
|
7
|
+
"自定义组件开发工具"
|
|
8
|
+
],
|
|
9
|
+
"author": "wibetter",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bin": {
|
|
12
|
+
"neo": "./bin/neo.js"
|
|
13
|
+
},
|
|
14
|
+
"main": "src/module/main.js",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"neo": "neo",
|
|
17
|
+
"dev": "node ./test/demo.js",
|
|
18
|
+
"format": "prettier --write \"src/**/**/*.{js,jsx,vue,tsx,ts,scss,less,json}\""
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin/*",
|
|
22
|
+
"src/*",
|
|
23
|
+
"test/*"
|
|
24
|
+
],
|
|
25
|
+
"husky": {
|
|
26
|
+
"hooks": {
|
|
27
|
+
"pre-commit": "lint-staged",
|
|
28
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"lint-staged": {
|
|
32
|
+
"src/**/**/*.{js,jsx,ts,tsx,vue,css,less,scss,json}": [
|
|
33
|
+
"prettier --write"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://git@github.com:wibetter/neo-cmp-cli.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/wibetter/neo-cmp-cli/issues"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"akfun": "^5.1.10",
|
|
45
|
+
"chalk": "^4.0.0",
|
|
46
|
+
"deepmerge": "^4.2.2",
|
|
47
|
+
"figlet": "^1.2.0",
|
|
48
|
+
"fs-extra": "^10.1.0",
|
|
49
|
+
"inquirer": "^7.3.3",
|
|
50
|
+
"ora": "^4.0.4",
|
|
51
|
+
"webpack-sources": "^3.2.3",
|
|
52
|
+
"yargs": "^12.0.2",
|
|
53
|
+
"lodash": "^4.17.21"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@commitlint/cli": "^8.3.5",
|
|
57
|
+
"@commitlint/config-conventional": "^9.1.1",
|
|
58
|
+
"husky": "^4.2.5",
|
|
59
|
+
"lint-staged": "^10.2.9",
|
|
60
|
+
"prettier": "^2.0.5"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">= 10.13.0",
|
|
64
|
+
"npm": ">= 6.4.1"
|
|
65
|
+
},
|
|
66
|
+
"browserslist": [
|
|
67
|
+
"> 1%",
|
|
68
|
+
"last 2 versions",
|
|
69
|
+
"not ie <= 8",
|
|
70
|
+
"iOS >= 8",
|
|
71
|
+
"Firefox >= 20",
|
|
72
|
+
"Android > 4.4"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// 统一路径解析:
|
|
3
|
+
const { resolve } = require('akfun');
|
|
4
|
+
const path = require('path'); // 以命令执行目录为根目录
|
|
5
|
+
|
|
6
|
+
// 当前neo的路径解析(用于获取neo-cmp-cli本身的文件地址)
|
|
7
|
+
function resolveByDirname(dir) {
|
|
8
|
+
return path.resolve(__dirname, dir);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 脚手架赋予当前项目的默认配置
|
|
13
|
+
*/
|
|
14
|
+
const defaultNEOConfig = {
|
|
15
|
+
settings: {
|
|
16
|
+
enableESLint: false, // 是否开启ESLint,默认开启ESLint检测代码格式
|
|
17
|
+
enableESLintFix: false, // 是否ESLint自动修正代码格式
|
|
18
|
+
enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
|
|
19
|
+
enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
|
|
20
|
+
},
|
|
21
|
+
webpack: {
|
|
22
|
+
resolve: {
|
|
23
|
+
// webpack的resolve配置
|
|
24
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.min.js', '.json'], // 用于配置webpack在尝试过程中用到的后缀列表
|
|
25
|
+
alias: {
|
|
26
|
+
'@': resolve('src')
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
createDeclaration: false, // 打包时是否创建ts声明文件
|
|
30
|
+
ignoreNodeModules: false, // 打包时是否忽略 node_modules
|
|
31
|
+
allowList: [], // ignoreNodeModules为true时生效
|
|
32
|
+
externals: [], // 从输出的 bundle 中排除依赖
|
|
33
|
+
projectDir: ['src'],
|
|
34
|
+
template: resolveByDirname('../initData/defaultTemplate.html'), // 默认使用neo-widget提供的页面模板(会启动页面设计器)
|
|
35
|
+
sassResources: []
|
|
36
|
+
},
|
|
37
|
+
envParams: {
|
|
38
|
+
// 项目系统环境变量
|
|
39
|
+
common: {
|
|
40
|
+
// 通用参数
|
|
41
|
+
'#version#': '20221229.1'
|
|
42
|
+
},
|
|
43
|
+
local: {
|
|
44
|
+
// 本地开发环境
|
|
45
|
+
'#dataApiBase#': 'http://localhost:1024', // 数据接口根地址
|
|
46
|
+
'#assetsPublicPath#': 'http://localhost:1024', // 静态资源根地址
|
|
47
|
+
'#routeBasePath#': '/' // 路由根地址
|
|
48
|
+
},
|
|
49
|
+
online: {
|
|
50
|
+
// 线上正式环境配置参数
|
|
51
|
+
'#dataApiBase#': '/', // 数据接口根地址 "//xxx.cn/"格式
|
|
52
|
+
'#assetsPublicPath#': '', // 静态资源根地址 "//xxx.cn/_spa/projectName"格式
|
|
53
|
+
'#routeBasePath#': '/' // 路由根地址 "/_spa/projectName/"格式
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
dev: {
|
|
57
|
+
// 用于开启本地调试模式的相关配置信息
|
|
58
|
+
NODE_ENV: 'development',
|
|
59
|
+
port: 80, // 设置基础端口,如果被占用则自动寻找可用端口
|
|
60
|
+
autoOpenBrowser: true,
|
|
61
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
62
|
+
assetsSubDirectory: '',
|
|
63
|
+
hostname: 'localhost',
|
|
64
|
+
proxyTable: {},
|
|
65
|
+
/** CSS Sourcemaps off by default because relative paths are "buggy"
|
|
66
|
+
* with this option, according to the CSS-Loader README
|
|
67
|
+
* (https://github.com/webpack/css-loader#sourcemaps)
|
|
68
|
+
* In our experience, they generally work as expected,
|
|
69
|
+
* just be aware of this issue when enabling this option.
|
|
70
|
+
*/
|
|
71
|
+
cssSourceMap: true
|
|
72
|
+
},
|
|
73
|
+
build: {
|
|
74
|
+
// 用于构建生产环境代码的相关配置信息
|
|
75
|
+
NODE_ENV: 'production', // production 模式,会启动UglifyJsPlugin服务
|
|
76
|
+
assetsRoot: resolve('dist'), // 编译完成的文件存放路径
|
|
77
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
78
|
+
assetsSubDirectory: '', // 资源引用二级路径
|
|
79
|
+
productionSourceMap: false,
|
|
80
|
+
// closeHtmlWebpackPlugin: true, // 可用于控制不生成html文件
|
|
81
|
+
// Gzip off by default as many popular public hosts such as
|
|
82
|
+
// Surge or Netlify already gzip all public assets for you.
|
|
83
|
+
// Before setting to `true`, make sure to:
|
|
84
|
+
// npm install --save-dev compression-webpack-plugin
|
|
85
|
+
productionGzip: false,
|
|
86
|
+
productionGzipExtensions: ['js', 'css', 'json'],
|
|
87
|
+
// Run the build command with an extra argument to
|
|
88
|
+
// View the bundle analyzer report after build finishes:
|
|
89
|
+
// `npm run build --report`
|
|
90
|
+
// Set to `true` or `false` to always turn it on or off
|
|
91
|
+
bundleAnalyzerReport: false
|
|
92
|
+
},
|
|
93
|
+
build2lib: {
|
|
94
|
+
// 用于构建第三方功能包的配置文件
|
|
95
|
+
NODE_ENV: 'production',
|
|
96
|
+
libraryName: '', // 构建第三方功能包时最后导出的引用变量名
|
|
97
|
+
assetsRoot: resolve('dist'), // 编译完成的文件存放路径
|
|
98
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
99
|
+
assetsSubDirectory: '', // 资源引用二级路径
|
|
100
|
+
productionSourceMap: false,
|
|
101
|
+
productionGzip: false,
|
|
102
|
+
productionGzipExtensions: ['js', 'css', 'json'],
|
|
103
|
+
bundleAnalyzerReport: false
|
|
104
|
+
},
|
|
105
|
+
linkDebug: {
|
|
106
|
+
// 用于开启本地调试模式的相关配置信息
|
|
107
|
+
NODE_ENV: 'development',
|
|
108
|
+
closeHtmlWebpackPlugin: true,
|
|
109
|
+
autoOpenBrowser: false,
|
|
110
|
+
cssExtract: false,
|
|
111
|
+
consoleInfo: '当前自定义组件可用外链地址'
|
|
112
|
+
},
|
|
113
|
+
publish2oss: {
|
|
114
|
+
output: {
|
|
115
|
+
filename: '[name].js',
|
|
116
|
+
library: {
|
|
117
|
+
type: 'var', // webpack 5 中生成 IIFE 格式的 type 配置
|
|
118
|
+
export: 'default'
|
|
119
|
+
},
|
|
120
|
+
globalObject: 'this' // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
|
|
121
|
+
},
|
|
122
|
+
cssExtract: false, // 不额外提取css文件
|
|
123
|
+
ossType: 'ali', // oss类型:ali、baidu
|
|
124
|
+
ossConfig: {
|
|
125
|
+
endpoint: 'https://oss-cn-beijing.aliyuncs.com',
|
|
126
|
+
// 个人阿里云子账户(neo-cmp-cli),有流量限制,请勿滥用
|
|
127
|
+
AccessKeyId: 'LTAI5tS47y9L4fAPLXNoEzxS',
|
|
128
|
+
AccessKeySecret: '8qz2GxxJJe44K5NRmLAAzIVJnbcYAU',
|
|
129
|
+
bucket: 'neo-widgets' // 存储桶名称
|
|
130
|
+
},
|
|
131
|
+
assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// 备注:数组类型则直接覆盖
|
|
136
|
+
module.exports = defaultNEOConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 统一路径解析:
|
|
2
|
+
const { resolve, getConfigObj, deepMergeConfig } = require('akfun');
|
|
3
|
+
const defaultNEOConfig = require('./default.config');
|
|
4
|
+
|
|
5
|
+
// 从项目根目录获取当前项目的配置文件
|
|
6
|
+
const curProjectConfig = getConfigObj(resolve('neo.config.js'));
|
|
7
|
+
|
|
8
|
+
// 备注:数组类型则直接覆盖
|
|
9
|
+
module.exports = deepMergeConfig(defaultNEOConfig, curProjectConfig);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<html lang="en">
|
|
2
|
+
<head>
|
|
3
|
+
<meta charset="UTF-8">
|
|
4
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
5
|
+
<meta name="format-detection" content="telephone=no"/>
|
|
6
|
+
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,width=device-width,viewport-fit=cover">
|
|
7
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
8
|
+
<title>neo-widget Demo</title>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
// 统一路径解析
|
|
6
|
+
function resolve(dir) {
|
|
7
|
+
return path.resolve(__dirname, dir);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 包括生产和开发的环境配置信息
|
|
11
|
+
module.exports = {
|
|
12
|
+
settings: {
|
|
13
|
+
enableESLint: false, // 调试模式是否开启ESLint,默认关闭ESLint检测代码格式
|
|
14
|
+
enableESLintFix: false, // 是否自动修正代码格式,默认不自动修正
|
|
15
|
+
enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
|
|
16
|
+
enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
|
|
17
|
+
},
|
|
18
|
+
webpack: {
|
|
19
|
+
entry: {
|
|
20
|
+
// webpack构建入口(优先级低于于dev、build和build2lib中的entry配置)
|
|
21
|
+
index: './src/index.js'
|
|
22
|
+
},
|
|
23
|
+
resolve: {
|
|
24
|
+
// webpack的resolve配置
|
|
25
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.min.js', 'json'], // 用于配置webpack在尝试过程中用到的后缀列表
|
|
26
|
+
alias: {
|
|
27
|
+
'@': resolve('src')
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
createDeclaration: false, // 打包时是否创建ts声明文件
|
|
31
|
+
ignoreNodeModules: false, // 打包时是否忽略 node_modules
|
|
32
|
+
allowList: [], // ignoreNodeModules为true时生效
|
|
33
|
+
externals: [], // 从输出的 bundle 中排除依赖
|
|
34
|
+
projectDir: ['src'],
|
|
35
|
+
sassResources: []
|
|
36
|
+
},
|
|
37
|
+
envParams: {
|
|
38
|
+
// 项目系统环境变量
|
|
39
|
+
common: {
|
|
40
|
+
// 通用参数
|
|
41
|
+
'#version#': '20200810.1'
|
|
42
|
+
},
|
|
43
|
+
local: {
|
|
44
|
+
// 本地开发环境
|
|
45
|
+
'#dataApiBase#': 'http://localhost:1024', // 数据接口根地址
|
|
46
|
+
'#assetsPublicPath#': 'http://localhost:1024', // 静态资源根地址
|
|
47
|
+
'#routeBasePath#': '/' // 路由根地址
|
|
48
|
+
},
|
|
49
|
+
online: {
|
|
50
|
+
// 线上正式环境配置参数
|
|
51
|
+
'#dataApiBase#': '/', // 数据接口根地址 "//xxx.cn/"格式
|
|
52
|
+
'#assetsPublicPath#': '', // 静态资源根地址 "//xxx.cn/_spa/projectName"格式
|
|
53
|
+
'#routeBasePath#': '/' // 路由根地址 "/_spa/projectName/"格式
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
build: {
|
|
57
|
+
entry: {
|
|
58
|
+
index: './src/index.js'
|
|
59
|
+
},
|
|
60
|
+
// 用于构建生产环境代码的相关配置信息
|
|
61
|
+
NODE_ENV: 'production', // production 模式,会启动UglifyJsPlugin服务
|
|
62
|
+
assetsRoot: resolve('dist'), // 编译完成的文件存放路径
|
|
63
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
64
|
+
assetsSubDirectory: '', // 资源引用二级路径
|
|
65
|
+
productionSourceMap: false,
|
|
66
|
+
// Gzip off by default as many popular public hosts such as
|
|
67
|
+
// Surge or Netlify already gzip all public assets for you.
|
|
68
|
+
// Before setting to `true`, make sure to:
|
|
69
|
+
// npm install --save-dev compression-webpack-plugin
|
|
70
|
+
productionGzip: false,
|
|
71
|
+
productionGzipExtensions: ['js', 'css', 'json'],
|
|
72
|
+
// Run the build command with an extra argument to
|
|
73
|
+
// View the bundle analyzer report after build finishes:
|
|
74
|
+
// `npm run build --report`
|
|
75
|
+
// Set to `true` or `false` to always turn it on or off
|
|
76
|
+
bundleAnalyzerReport: false
|
|
77
|
+
},
|
|
78
|
+
build2lib: {
|
|
79
|
+
entry: {
|
|
80
|
+
index: './src/index.js'
|
|
81
|
+
},
|
|
82
|
+
// 用于构建第三方功能包的配置文件
|
|
83
|
+
NODE_ENV: 'production',
|
|
84
|
+
libraryName: '', // 构建第三方功能包时最后导出的引用变量名
|
|
85
|
+
assetsRoot: resolve('dist'), // 编译完成的文件存放路径
|
|
86
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
87
|
+
assetsSubDirectory: '', // 资源引用二级路径
|
|
88
|
+
ignoreNodeModules: true, // 打包时是否忽略 node_modules
|
|
89
|
+
allowList: [], // ignoreNodeModules为true时生效
|
|
90
|
+
productionSourceMap: false,
|
|
91
|
+
productionGzip: false,
|
|
92
|
+
productionGzipExtensions: ['js', 'css', 'json'],
|
|
93
|
+
bundleAnalyzerReport: false
|
|
94
|
+
},
|
|
95
|
+
build2esm: {
|
|
96
|
+
input: resolve('src/main.js'),
|
|
97
|
+
fileName: 'index'
|
|
98
|
+
}
|
|
99
|
+
};
|