Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taro): create template taro/react #6

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/lib/application/files/taro/.commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
extends: ['@commitlint/config-angular'],
rules: {
'subject-case': [
2,
'always',
['sentence-case', 'start-case', 'pascal-case', 'upper-case', 'lower-case']
],
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
'sample'
]
]
}
}
12 changes: 12 additions & 0 deletions src/lib/application/files/taro/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
7 changes: 7 additions & 0 deletions src/lib/application/files/taro/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["taro/react"],
"rules": {
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}
6 changes: 6 additions & 0 deletions src/lib/application/files/taro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/
deploy_versions/
.temp/
.rn_temp/
node_modules/
.DS_Store
5 changes: 5 additions & 0 deletions src/lib/application/files/taro/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'*.{js,jsx,ts,tsx}': ['eslint --fix', 'eslint'],
'**/*.ts?(x)': () => 'npm run build-types',
'*.json': ['prettier --write']
}
1 change: 1 addition & 0 deletions src/lib/application/files/taro/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron_mirror=https://npm.taobao.org/mirrors/electron/
91 changes: 91 additions & 0 deletions src/lib/application/files/taro/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* @returns {import('prettier')}
* @see https://prettier.io/docs/en/options.html
*/
module.exports = {
parser: 'babel',
semi: false,
singleQuote: true,
quoteProps: 'consistent',
trailingComma: 'none',
arrowParens: 'avoid',
rangeStart: 0,
rangeEnd: Infinity,
endOfLine: 'auto',
overrides: [
{
files:
'*.{babelrc,eslintrc,huskyrc,lintstagedrc,json,prettierrc,stylelintrc}',
options: {
parser: 'json'
}
},
{
files: '*.{ts,tsx}',
options: {
parser: 'typescript'
}
},
{
files: '*.{ejs,hbs,html}',
options: {
parser: 'html'
}
},
{
files: '*.vue',
options: {
parser: 'vue'
}
},
{
files: '*.md',
options: {
parser: 'markdown'
}
},
{
files: '*.mdx',
options: {
parser: 'mdx'
}
},
{
files: '*.css',
options: {
parser: 'css'
}
},
{
files: '*.less',
options: {
parser: 'less'
}
},
{
files: '*.scss',
options: {
parser: 'scss'
}
},
{
files: '*.yaml',
options: {
parser: 'yaml'
}
},
{
files: ['*.yml'],
options: {
singleQuote: false
}
},
{
files: ['*.json5'],
options: {
singleQuote: false,
quoteProps: 'preserve'
}
}
]
}
10 changes: 10 additions & 0 deletions src/lib/application/files/taro/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
presets: [
['taro', {
framework: 'react',
ts: true
}]
]
}
9 changes: 9 additions & 0 deletions src/lib/application/files/taro/config/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {
NODE_ENV: '"development"',
},
defineConstants: {},
mini: {},
h5: {},
plugins: ["@tarojs/plugin-react-devtools"],
};
70 changes: 70 additions & 0 deletions src/lib/application/files/taro/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const config = {
projectName: 'myapp',
date: '2022-2-22',
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
828: 1.81 / 2
},
sourceRoot: 'src',
outputRoot: 'dist',
plugins: [],
defineConstants: {
},
copy: {
patterns: [
],
options: {
}
},
framework: 'react',
mini: {
postcss: {
pxtransform: {
enable: true,
config: {

}
},
url: {
enable: true,
config: {
limit: 1024 // 设定转换尺寸上限
}
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
},
h5: {
publicPath: '/',
staticDirectory: 'static',
postcss: {
autoprefixer: {
enable: true,
config: {
}
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
}
}

module.exports = function (merge) {
if (process.env.NODE_ENV === 'development') {
return merge({}, config, require('./dev'))
}
return merge({}, config, require('./prod'))
}
37 changes: 37 additions & 0 deletions src/lib/application/files/taro/config/prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
env: {
NODE_ENV: '"production"'
},
defineConstants: {
},
mini: {},
h5: {
/**
* WebpackChain 插件配置
* @docs https://github.com/neutrinojs/webpack-chain
*/
// webpackChain (chain) {
// /**
// * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。
// * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer
// */
// chain.plugin('analyzer')
// .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])

// /**
// * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。
// * @docs https://github.com/chrisvfritz/prerender-spa-plugin
// */
// const path = require('path')
// const Prerender = require('prerender-spa-plugin')
// const staticDir = path.join(__dirname, '..', 'dist')
// chain
// .plugin('prerender')
// .use(new Prerender({
// staticDir,
// routes: [ '/pages/index/index' ],
// postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
// }))
// }
}
}
18 changes: 18 additions & 0 deletions src/lib/application/files/taro/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference types="@tarojs/taro" />

declare module '*.png';
declare module '*.gif';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.svg';
declare module '*.css';
declare module '*.less';
declare module '*.scss';
declare module '*.sass';
declare module '*.styl';

declare namespace NodeJS {
interface ProcessEnv {
TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
}
}
Empty file.
69 changes: 60 additions & 9 deletions src/lib/application/files/taro/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,65 @@
{
"name": "<%= name %>",
"version": "<%= version %>",
"description": "<%= description %>",
"name": "myapp",
"version": "1.0.0",
"private": true,
"description": "",
"templateInfo": {
"name": "default",
"typescript": true,
"css": "sass"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build:weapp": "taro build --type weapp",
"build:swan": "taro build --type swan",
"build:alipay": "taro build --type alipay",
"build:tt": "taro build --type tt",
"build:h5": "taro build --type h5",
"build:rn": "taro build --type rn",
"build:qq": "taro build --type qq",
"build:jd": "taro build --type jd",
"build:quickapp": "taro build --type quickapp",
"dev:weapp": "npm run build:weapp -- --watch",
"dev:swan": "npm run build:swan -- --watch",
"dev:alipay": "npm run build:alipay -- --watch",
"dev:tt": "npm run build:tt -- --watch",
"dev:h5": "npm run build:h5 -- --watch",
"dev:rn": "npm run build:rn -- --watch",
"dev:qq": "npm run build:qq -- --watch",
"dev:jd": "npm run build:jd -- --watch",
"dev:quickapp": "npm run build:quickapp -- --watch"
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"author": "",
"dependencies": {
"@babel/runtime": "^7.7.7",
"@tarojs/components": "3.4.2",
"@tarojs/plugin-framework-react": "3.4.2",
"@tarojs/react": "3.4.2",
"@tarojs/runtime": "3.4.2",
"@tarojs/taro": "3.4.2",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
"keywords": [],
"author": "<%= author %>",
"license": "UNLICENSED",
"dependencies": {},
"devDependencies": {}
"devDependencies": {
"@babel/core": "^7.8.0",
"@tarojs/mini-runner": "3.4.2",
"@tarojs/plugin-react-devtools": "^3.4.2",
"@tarojs/webpack-runner": "3.4.2",
"@types/react": "^17.0.2",
"@types/webpack-env": "^1.13.6",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"babel-preset-taro": "3.4.2",
"eslint": "^6.8.0",
"eslint-config-taro": "3.4.2",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-react-hooks": "^4.2.0",
"stylelint": "^14.4.0",
"typescript": "^4.1.0"
}
}
13 changes: 13 additions & 0 deletions src/lib/application/files/taro/project.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"miniprogramRoot": "./dist",
"projectname": "myapp",
"description": "",
"appid": "touristappid",
"setting": {
"urlCheck": true,
"es6": false,
"postcss": false,
"minified": false
},
"compileType": "miniprogram"
}