Skip to content

Commit 9d18582

Browse files
authored
Merge pull request #9 from dcasia/220516
Enhance className match rules for React and add an example for React
2 parents a52459f + d3b2a41 commit 9d18582

26 files changed

+41798
-27
lines changed

examples/taro/react/.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

examples/taro/react/.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": ["taro/react"],
3+
"rules": {
4+
"react/jsx-uses-react": "off",
5+
"react/react-in-jsx-scope": "off"
6+
}
7+
}

examples/taro/react/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dist/
2+
deploy_versions/
3+
.temp/
4+
.rn_temp/
5+
node_modules/
6+
.DS_Store
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// babel-preset-taro 更多选项和默认值:
2+
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
3+
module.exports = {
4+
presets: [
5+
['taro', {
6+
framework: 'react',
7+
ts: true
8+
}]
9+
]
10+
}

examples/taro/react/config/dev.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
env: {
3+
NODE_ENV: '"development"'
4+
},
5+
defineConstants: {
6+
},
7+
mini: {},
8+
h5: {}
9+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
const config = {
3+
projectName: 'mp-tailwind-react',
4+
date: '2022-5-12',
5+
designWidth: 375,
6+
deviceRatio: {
7+
640: 2.34 / 2,
8+
750: 1,
9+
828: 1.81 / 2,
10+
375: 2
11+
},
12+
sourceRoot: 'src',
13+
outputRoot: 'dist',
14+
plugins: [
15+
['@dcasia/mini-program-tailwind-webpack-plugin/dist/taro', {
16+
}]
17+
],
18+
defineConstants: {
19+
},
20+
copy: {
21+
patterns: [
22+
],
23+
options: {
24+
}
25+
},
26+
framework: 'react',
27+
mini: {
28+
postcss: {
29+
pxtransform: {
30+
enable: true,
31+
config: {
32+
33+
}
34+
},
35+
url: {
36+
enable: true,
37+
config: {
38+
limit: 1024 // 设定转换尺寸上限
39+
}
40+
},
41+
cssModules: {
42+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
43+
config: {
44+
namingPattern: 'module', // 转换模式,取值为 global/module
45+
generateScopedName: '[name]__[local]___[hash:base64:5]'
46+
}
47+
}
48+
}
49+
},
50+
h5: {
51+
publicPath: '/',
52+
staticDirectory: 'static',
53+
postcss: {
54+
autoprefixer: {
55+
enable: true,
56+
config: {
57+
}
58+
},
59+
cssModules: {
60+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
61+
config: {
62+
namingPattern: 'module', // 转换模式,取值为 global/module
63+
generateScopedName: '[name]__[local]___[hash:base64:5]'
64+
}
65+
}
66+
}
67+
}
68+
}
69+
70+
module.exports = function (merge) {
71+
if (process.env.NODE_ENV === 'development') {
72+
return merge({}, config, require('./dev'))
73+
}
74+
return merge({}, config, require('./prod'))
75+
}

examples/taro/react/config/prod.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
env: {
3+
NODE_ENV: '"production"'
4+
},
5+
defineConstants: {
6+
},
7+
mini: {},
8+
h5: {
9+
/**
10+
* WebpackChain 插件配置
11+
* @docs https://github.com/neutrinojs/webpack-chain
12+
*/
13+
// webpackChain (chain) {
14+
// /**
15+
// * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。
16+
// * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer
17+
// */
18+
// chain.plugin('analyzer')
19+
// .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
20+
21+
// /**
22+
// * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。
23+
// * @docs https://github.com/chrisvfritz/prerender-spa-plugin
24+
// */
25+
// const path = require('path')
26+
// const Prerender = require('prerender-spa-plugin')
27+
// const staticDir = path.join(__dirname, '..', 'dist')
28+
// chain
29+
// .plugin('prerender')
30+
// .use(new Prerender({
31+
// staticDir,
32+
// routes: [ '/pages/index/index' ],
33+
// postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
34+
// }))
35+
// }
36+
}
37+
}

examples/taro/react/global.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference types="@tarojs/taro" />
2+
3+
declare module '*.png';
4+
declare module '*.gif';
5+
declare module '*.jpg';
6+
declare module '*.jpeg';
7+
declare module '*.svg';
8+
declare module '*.css';
9+
declare module '*.less';
10+
declare module '*.scss';
11+
declare module '*.sass';
12+
declare module '*.styl';
13+
14+
declare namespace NodeJS {
15+
interface ProcessEnv {
16+
TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
17+
}
18+
}

0 commit comments

Comments
 (0)