@tarojs/rn-runner 3.5.0-beta.2 → 3.5.0-beta.5
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/.eslintrc.js +2 -1
- package/__tests__/__snapshots__/components.spec.ts.snap +523 -0
- package/__tests__/build.spec.ts +3 -3
- package/__tests__/components.spec.ts +103 -0
- package/__tests__/config.spec.ts +1 -1
- package/__tests__/global.d.ts +11 -0
- package/__tests__/mock/build_testdata.ts +58 -0
- package/__tests__/mock/{build_testdata.js → components_testdata.ts} +4 -9
- package/__tests__/mock/config/index.js +1 -0
- package/__tests__/mock/src/app.config.ts +13 -0
- package/__tests__/mock/src/app.scss +0 -0
- package/__tests__/mock/src/app.tsx +15 -0
- package/__tests__/mock/src/components/cell/index.scss +25 -0
- package/__tests__/mock/src/components/cell/index.tsx +38 -0
- package/__tests__/mock/src/components/navbar/icon_back.webp +0 -0
- package/__tests__/mock/src/components/navbar/index.scss +29 -0
- package/__tests__/mock/src/components/navbar/index.tsx +36 -0
- package/__tests__/mock/src/components/navbar/resolver.rn.ts +1 -0
- package/__tests__/mock/src/components/navbar/resolver.ts +1 -0
- package/__tests__/mock/src/components/svg/index.tsx +6 -0
- package/__tests__/mock/src/components/svg/rollup-logo.svg +3 -0
- package/__tests__/mock/src/utils/dynamicImport/index.ts +3 -0
- package/__tests__/mock/src/utils/namedExport/index.js +2 -0
- package/__tests__/mock/src/utils/requireLodash/index.ts +5 -0
- package/__tests__/mock/src/utils/requireReactNative/index.js +2 -0
- package/__tests__/tsconfig.json +8 -0
- package/dist/config/build-component.js +162 -0
- package/dist/config/build-component.js.map +1 -0
- package/dist/config/config-holder.js +1 -1
- package/dist/config/config-holder.js.map +1 -1
- package/dist/config/index.js +4 -4
- package/dist/config/index.js.map +1 -1
- package/dist/config/terminal-reporter.js +3 -3
- package/dist/config/terminal-reporter.js.map +1 -1
- package/dist/index.js +26 -19
- package/dist/index.js.map +1 -1
- package/index.js +1 -0
- package/jest.config.js +3 -30
- package/package.json +38 -25
- package/src/config/build-component.ts +171 -0
- package/src/config/config-holder.ts +2 -1
- package/src/config/index.ts +15 -14
- package/src/config/terminal-reporter.ts +3 -3
- package/src/index.ts +33 -22
- package/src/types/index.ts +33 -33
- package/tsconfig.json +3 -5
package/__tests__/build.spec.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import build from '../
|
|
1
|
+
import build from '../src/index'
|
|
2
2
|
import { appPath, config, configNoWatch } from './mock/build_testdata'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const outputBundle = require('metro/src/shared/output/bundle')
|
|
5
5
|
|
|
6
6
|
describe('init', () => {
|
|
7
|
-
jest.spyOn(
|
|
7
|
+
jest.spyOn(outputBundle, 'build').mockImplementation(() => {
|
|
8
8
|
return 'ok'
|
|
9
9
|
})
|
|
10
10
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as path from 'path'
|
|
2
|
+
|
|
3
|
+
import runner from '../dist/index'
|
|
4
|
+
import { build } from '../src/config/build-component'
|
|
5
|
+
import { appPath, config } from './mock/components_testdata'
|
|
6
|
+
|
|
7
|
+
const getCode = (result) => result.output.map(chunk => chunk.code)
|
|
8
|
+
|
|
9
|
+
describe('build_components', () => {
|
|
10
|
+
const spy = jest.spyOn(process, 'cwd')
|
|
11
|
+
spy.mockReturnValue(path.resolve(__dirname, '', 'mock'))
|
|
12
|
+
// metro runServer 容易超时
|
|
13
|
+
jest.setTimeout(300000)
|
|
14
|
+
|
|
15
|
+
it('single component', async () => {
|
|
16
|
+
const result = await runner(appPath, {
|
|
17
|
+
...config,
|
|
18
|
+
nativeComponents: {
|
|
19
|
+
external: ['react', 'react-native', /@tarojs\/components-rn/, /@babel\/runtime/],
|
|
20
|
+
output: 'dist/single'
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('nativeComponents not set', async () => {
|
|
27
|
+
const result = await runner(appPath, {
|
|
28
|
+
...config
|
|
29
|
+
})
|
|
30
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('multiple components', async () => {
|
|
34
|
+
const result = await build(config, {
|
|
35
|
+
input: ['components/cell/index', 'components/navbar/index'],
|
|
36
|
+
sourceRootPath: path.resolve(__dirname, './mock/src'),
|
|
37
|
+
output: path.resolve(__dirname, './mock/dist/multiple'),
|
|
38
|
+
external: ['react', 'react-native', /@tarojs\/components-rn/, /@tarojs\/taro-rn/, /@babel\/runtime/],
|
|
39
|
+
externalResolve: () => {}
|
|
40
|
+
})
|
|
41
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('modify rollup config', async () => {
|
|
45
|
+
const result = await build(config, {
|
|
46
|
+
input: ['components/cell/index', 'components/navbar/index'],
|
|
47
|
+
sourceRootPath: path.resolve(__dirname, './mock/src'),
|
|
48
|
+
modifyRollupConfig: config => {
|
|
49
|
+
const { input, ...others } = config
|
|
50
|
+
return {
|
|
51
|
+
...others,
|
|
52
|
+
input: Object.entries(input as Record<string, string>).reduce(
|
|
53
|
+
(pre, cur) => Object.assign(pre, { [cur[0].replace('components/', '')]: cur[1] }),
|
|
54
|
+
{}
|
|
55
|
+
),
|
|
56
|
+
output: { dir: path.resolve(__dirname, './mock/dist/modify-config') }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('svg transform', async () => {
|
|
64
|
+
const result = await build(config, {
|
|
65
|
+
input: ['components/svg/index'],
|
|
66
|
+
sourceRootPath: path.resolve(__dirname, './mock/src'),
|
|
67
|
+
output: path.resolve(__dirname, './mock/dist/svg'),
|
|
68
|
+
external: ['react', 'react-native', /@tarojs\/components-rn/, /@tarojs\/taro-rn/, /@babel\/runtime/],
|
|
69
|
+
externalResolve: () => {}
|
|
70
|
+
})
|
|
71
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('named export', async () => {
|
|
75
|
+
const result = await build(config, {
|
|
76
|
+
input: ['utils/namedExport/index'],
|
|
77
|
+
sourceRootPath: path.resolve(__dirname, './mock/src'),
|
|
78
|
+
externalResolve: () => {},
|
|
79
|
+
output: path.resolve(__dirname, './mock/dist/named-export')
|
|
80
|
+
})
|
|
81
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('dynamic require', async () => {
|
|
85
|
+
const result = await build(config, {
|
|
86
|
+
input: ['utils/dynamicImport/index'],
|
|
87
|
+
sourceRootPath: path.resolve(__dirname, './mock/src'),
|
|
88
|
+
externalResolve: () => {},
|
|
89
|
+
output: path.resolve(__dirname, './mock/dist/dynamic-import')
|
|
90
|
+
})
|
|
91
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('require react-native component', async () => {
|
|
95
|
+
const result = await build(config, {
|
|
96
|
+
input: ['utils/requireReactNative/index'],
|
|
97
|
+
sourceRootPath: path.resolve(__dirname, './mock/src'),
|
|
98
|
+
externalResolve: () => {},
|
|
99
|
+
output: path.resolve(__dirname, './mock/dist/require-native')
|
|
100
|
+
})
|
|
101
|
+
expect(getCode(result)).toMatchSnapshot()
|
|
102
|
+
})
|
|
103
|
+
})
|
package/__tests__/config.spec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getRNConfigBabelPlugin, getRNConfigEntry, getRNConfigOutput, getRNConfigTransformer } from '../
|
|
1
|
+
import { getRNConfigBabelPlugin, getRNConfigEntry, getRNConfigOutput, getRNConfigTransformer } from '../src/config/config-holder'
|
|
2
2
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare module '*.png';
|
|
2
|
+
declare module '*.gif';
|
|
3
|
+
declare module '*.jpg';
|
|
4
|
+
declare module '*.jpeg';
|
|
5
|
+
declare module '*.webp';
|
|
6
|
+
declare module '*.svg';
|
|
7
|
+
declare module '*.css';
|
|
8
|
+
declare module '*.less';
|
|
9
|
+
declare module '*.scss';
|
|
10
|
+
declare module '*.sass';
|
|
11
|
+
declare module '*.styl';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
export const appPath = path.resolve(__dirname, '../../../..', '')
|
|
4
|
+
|
|
5
|
+
export const config = {
|
|
6
|
+
entry: 'app',
|
|
7
|
+
copy: { patterns: [], options: {} },
|
|
8
|
+
sourceRoot: 'src',
|
|
9
|
+
outputRoot: 'dist',
|
|
10
|
+
platform: 'rn',
|
|
11
|
+
framework: 'react',
|
|
12
|
+
baseLevel: undefined,
|
|
13
|
+
csso: undefined,
|
|
14
|
+
sass: { options: {}, additionalData: '' },
|
|
15
|
+
uglify: undefined,
|
|
16
|
+
plugins: [],
|
|
17
|
+
projectName: 'taroRnInit',
|
|
18
|
+
env: { NODE_ENV: '"development"' },
|
|
19
|
+
defineConstants: { __TEST__: '"RN测试静态常量"' },
|
|
20
|
+
designWidth: 750,
|
|
21
|
+
deviceRatio: { 640: 1.17, 750: 1, 828: 0.905 },
|
|
22
|
+
terser: undefined,
|
|
23
|
+
appName: '',
|
|
24
|
+
output:
|
|
25
|
+
{
|
|
26
|
+
android: 'androidbundle/index.bundle',
|
|
27
|
+
ios: 'iosbundle/main.bundle'
|
|
28
|
+
},
|
|
29
|
+
postcss:
|
|
30
|
+
{
|
|
31
|
+
options: {},
|
|
32
|
+
scalable: true,
|
|
33
|
+
pxtransform: { enable: true, config: {} }
|
|
34
|
+
},
|
|
35
|
+
less: { options: {}, additionalData: '' },
|
|
36
|
+
stylus: { options: {}, additionalData: '' },
|
|
37
|
+
EXPLORER_PATH: 'src',
|
|
38
|
+
EXPLORER_SHELL: 'yarn run wb-bundle',
|
|
39
|
+
sourceDir: '',
|
|
40
|
+
isWatch: true,
|
|
41
|
+
mode: 'development',
|
|
42
|
+
modifyWebpackChain: [],
|
|
43
|
+
modifyBuildAssets: [],
|
|
44
|
+
modifyMiniConfigs: [],
|
|
45
|
+
onBuildFinish: [],
|
|
46
|
+
nodeModulesPath:
|
|
47
|
+
path.resolve(__dirname, '../../../..', 'node_modules'),
|
|
48
|
+
deviceType: 'android',
|
|
49
|
+
port: undefined,
|
|
50
|
+
buildAdapter: 'rn',
|
|
51
|
+
globalObject: 'global',
|
|
52
|
+
resetCache: true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const configNoWatch = {
|
|
56
|
+
...config,
|
|
57
|
+
isWatch: false
|
|
58
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
|
|
3
|
-
const appPath = path.resolve(__dirname, '
|
|
3
|
+
const appPath = path.resolve(__dirname, '.', '')
|
|
4
4
|
|
|
5
5
|
const config = {
|
|
6
6
|
entry: 'app',
|
|
@@ -48,16 +48,11 @@ const config = {
|
|
|
48
48
|
deviceType: 'android',
|
|
49
49
|
port: undefined,
|
|
50
50
|
buildAdapter: 'rn',
|
|
51
|
-
globalObject: 'global'
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const configNoWatch = {
|
|
55
|
-
...config,
|
|
56
|
-
isWatch: false
|
|
51
|
+
globalObject: 'global',
|
|
52
|
+
isBuildNativeComp: true
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
export {
|
|
60
|
-
appPath,
|
|
61
56
|
config,
|
|
62
|
-
|
|
57
|
+
appPath
|
|
63
58
|
}
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { Component } from 'react'
|
|
2
|
+
import { View } from '@tarojs/components'
|
|
3
|
+
import './app.scss'
|
|
4
|
+
|
|
5
|
+
class App extends Component {
|
|
6
|
+
props: any
|
|
7
|
+
|
|
8
|
+
render () {
|
|
9
|
+
return (
|
|
10
|
+
<View>{this.props.children}</View>
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default App
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.cellGroup {
|
|
2
|
+
background-color: white;
|
|
3
|
+
border-radius: 20px;
|
|
4
|
+
}
|
|
5
|
+
.cellItem {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: row;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
padding-left: 30px;
|
|
10
|
+
padding-right: 30px;
|
|
11
|
+
height: 98px;
|
|
12
|
+
|
|
13
|
+
&--care {
|
|
14
|
+
height: 128px;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
.cellItem__title {
|
|
18
|
+
// font-size: 28px;
|
|
19
|
+
color: #333;
|
|
20
|
+
font-weight: bold;
|
|
21
|
+
}
|
|
22
|
+
.cellItem__line {
|
|
23
|
+
height: 1px;
|
|
24
|
+
background-color: #f4f4f4;
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View, Text } from '@tarojs/components'
|
|
3
|
+
import taro from '@tarojs/taro'
|
|
4
|
+
import './index.scss'
|
|
5
|
+
|
|
6
|
+
console.log({taro})
|
|
7
|
+
interface Props {
|
|
8
|
+
className?: string,
|
|
9
|
+
style?: any,
|
|
10
|
+
children?: any
|
|
11
|
+
title?: string
|
|
12
|
+
}
|
|
13
|
+
function Cell ({ children, style }: Props) {
|
|
14
|
+
const childs = Array.isArray(children) ? children : [children]
|
|
15
|
+
return (
|
|
16
|
+
<View className={'cellGroup'} style={{ ...style }}>
|
|
17
|
+
{
|
|
18
|
+
childs.map((it, i) => (
|
|
19
|
+
[it].concat(i === children.length - 1 ? [] : <View key={`line-${i}`} className="cellItem__line"></View>)
|
|
20
|
+
))
|
|
21
|
+
}
|
|
22
|
+
</View>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
function Item ({ title, children, style }: Props) {
|
|
26
|
+
return <View className={'cellItem'} style={{ ...style }}>
|
|
27
|
+
<Text className="cellItem__title">
|
|
28
|
+
{title}
|
|
29
|
+
</Text>
|
|
30
|
+
<View className="cellItem__content">
|
|
31
|
+
{children}
|
|
32
|
+
</View>
|
|
33
|
+
</View>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Cell.Item = Item
|
|
37
|
+
|
|
38
|
+
export default Cell
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
.navbar {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: row;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
align-items: center;
|
|
6
|
+
width: 750px;
|
|
7
|
+
height: 100px;
|
|
8
|
+
background-color: white;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.navbar-title {
|
|
12
|
+
&-text {
|
|
13
|
+
font-size: 38px;
|
|
14
|
+
color: #000;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.icon-back {
|
|
19
|
+
width: 38px;
|
|
20
|
+
height: 38px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.navbar-leftElement, .navbar-rightElement {
|
|
24
|
+
width: 100px;
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: row;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
align-items: center;
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import Taro from '@tarojs/taro'
|
|
3
|
+
import { View, Text, Image } from '@tarojs/components'
|
|
4
|
+
import iconBack from './icon_back.webp'
|
|
5
|
+
import './index.scss'
|
|
6
|
+
import 'src/components/navbar/resolver'
|
|
7
|
+
|
|
8
|
+
console.log('isRn', process.env.TARO_ENV === 'rn')
|
|
9
|
+
export default function Navbar (props: Props) {
|
|
10
|
+
const { title, rightElement } = props
|
|
11
|
+
const back = () => Taro.navigateBack()
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<View className='navbar'>
|
|
15
|
+
<View className='navbar-leftElement'>
|
|
16
|
+
<Image className='icon-back' src={iconBack} onClick={back}></Image>
|
|
17
|
+
</View>
|
|
18
|
+
<View className='navbar-title'>
|
|
19
|
+
{
|
|
20
|
+
typeof (title) === 'string'
|
|
21
|
+
? <Text className='navbar-title-text'>{title}</Text>
|
|
22
|
+
: title
|
|
23
|
+
}
|
|
24
|
+
</View>
|
|
25
|
+
<View className='navbar-rightElement'>
|
|
26
|
+
{rightElement}
|
|
27
|
+
</View>
|
|
28
|
+
</View>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Props = {
|
|
33
|
+
title: string | any,
|
|
34
|
+
rightElement?: any,
|
|
35
|
+
back?: () => void,
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('rn resolve')
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('default resolve')
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.build = void 0;
|
|
24
|
+
const plugin_babel_1 = require("@rollup/plugin-babel");
|
|
25
|
+
const commonjs = require("@rollup/plugin-commonjs");
|
|
26
|
+
const json = require("@rollup/plugin-json");
|
|
27
|
+
const plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
|
|
28
|
+
const pluginReplace = require("@rollup/plugin-replace");
|
|
29
|
+
const helper_1 = require("@tarojs/helper");
|
|
30
|
+
const rn_style_transformer_1 = require("@tarojs/rn-style-transformer");
|
|
31
|
+
const rn_supporter_1 = require("@tarojs/rn-supporter");
|
|
32
|
+
const rn_transformer_1 = require("@tarojs/rn-transformer");
|
|
33
|
+
const jsx = require("acorn-jsx");
|
|
34
|
+
const path = require("path");
|
|
35
|
+
const rollup_1 = require("rollup");
|
|
36
|
+
const clear = require("rollup-plugin-clear");
|
|
37
|
+
const rollup_plugin_image_file_1 = require("rollup-plugin-image-file");
|
|
38
|
+
const DEFAULT_CONFIG = {
|
|
39
|
+
external: [/^react(\/.*)?$/, /^react-native(\/.*)?$/, /^@react-native/],
|
|
40
|
+
output: 'dist',
|
|
41
|
+
externalResolve: importee => (likeDependent(importee) ? importee : null),
|
|
42
|
+
sourceRootPath: process.cwd(),
|
|
43
|
+
modifyRollupConfig: config => config
|
|
44
|
+
};
|
|
45
|
+
const build = (projectConfig, componentConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const mergedConfig = (0, helper_1.recursiveMerge)(Object.assign({}, DEFAULT_CONFIG), componentConfig);
|
|
47
|
+
const { input, external, output, externalResolve, sourceRootPath, modifyRollupConfig } = mergedConfig;
|
|
48
|
+
const getInputOption = () => {
|
|
49
|
+
const components = Array.isArray(input) ? input : [input];
|
|
50
|
+
const inputOptions = components.reduce((pre, cur) => {
|
|
51
|
+
let absolutePath = cur;
|
|
52
|
+
if (!path.isAbsolute(cur)) {
|
|
53
|
+
absolutePath = path.resolve(sourceRootPath, cur);
|
|
54
|
+
}
|
|
55
|
+
const realPath = (0, rn_supporter_1.resolveExtFile)({ originModulePath: absolutePath }, absolutePath);
|
|
56
|
+
const relativePath = path
|
|
57
|
+
.relative(sourceRootPath, realPath)
|
|
58
|
+
.replace(/\.(js|ts|jsx|tsx)$/, '')
|
|
59
|
+
.replace(/\.{1,}\//g, '');
|
|
60
|
+
return Object.assign(Object.assign({}, pre), { [relativePath]: realPath });
|
|
61
|
+
}, {});
|
|
62
|
+
if (components.length === 1) {
|
|
63
|
+
return {
|
|
64
|
+
index: Object.values(inputOptions)[0]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return inputOptions;
|
|
68
|
+
};
|
|
69
|
+
const getExternal = () => {
|
|
70
|
+
if (typeof external === 'function') {
|
|
71
|
+
return external(DEFAULT_CONFIG.external);
|
|
72
|
+
}
|
|
73
|
+
const _external = Array.isArray(external) ? external : [external];
|
|
74
|
+
return _external.filter(Boolean).map(item => {
|
|
75
|
+
if (item.test)
|
|
76
|
+
return item;
|
|
77
|
+
const match = item.match(/^\/(.+)\/$/);
|
|
78
|
+
return match ? new RegExp(match[1]) : item;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const rollupOptions = {
|
|
82
|
+
input: getInputOption(),
|
|
83
|
+
output: {
|
|
84
|
+
format: 'es',
|
|
85
|
+
dir: output
|
|
86
|
+
},
|
|
87
|
+
external: getExternal(),
|
|
88
|
+
// @ts-ignore react native 相关的一些库中可能包含 jsx 语法
|
|
89
|
+
acornInjectPlugins: [jsx()],
|
|
90
|
+
plugins: [
|
|
91
|
+
clear({ targets: [output] }),
|
|
92
|
+
// TODO: 使用 react-native-svg-transformer 处理
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
(0, rollup_plugin_image_file_1.default)({
|
|
95
|
+
extensions: ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.svg', '.svgx']
|
|
96
|
+
}),
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
json(),
|
|
99
|
+
(0, rn_supporter_1.rollupResolver)({
|
|
100
|
+
externalResolve
|
|
101
|
+
}),
|
|
102
|
+
(0, plugin_node_resolve_1.default)({
|
|
103
|
+
extensions: ['.mjs', '.js', '.json', '.node', '.ts', '.tsx']
|
|
104
|
+
}),
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
pluginReplace({
|
|
107
|
+
'process.env.NODE_ENV': JSON.stringify('production')
|
|
108
|
+
}),
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
commonjs(),
|
|
111
|
+
(0, plugin_babel_1.default)({
|
|
112
|
+
babelHelpers: 'runtime',
|
|
113
|
+
presets: [
|
|
114
|
+
[
|
|
115
|
+
'babel-preset-taro',
|
|
116
|
+
{
|
|
117
|
+
framework: 'react',
|
|
118
|
+
ts: true,
|
|
119
|
+
reactJsxRuntime: projectConfig.reactJsxRuntime || 'automatic',
|
|
120
|
+
disableImportExportTransform: true
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
],
|
|
124
|
+
extensions: ['js', 'ts', 'jsx', 'tsx']
|
|
125
|
+
}),
|
|
126
|
+
(0, rn_style_transformer_1.rollupTransform)({ config: projectConfig })
|
|
127
|
+
]
|
|
128
|
+
};
|
|
129
|
+
const newRollupOptions = modifyRollupConfig(rollupOptions, {
|
|
130
|
+
taroResolver: rn_supporter_1.rollupResolver,
|
|
131
|
+
styleTransformer: rn_style_transformer_1.rollupTransform
|
|
132
|
+
});
|
|
133
|
+
const { output: outputOptions } = newRollupOptions, inputOptions = __rest(newRollupOptions, ["output"]);
|
|
134
|
+
let bundle;
|
|
135
|
+
try {
|
|
136
|
+
bundle = yield (0, rollup_1.rollup)(inputOptions);
|
|
137
|
+
const result = yield bundle.write(outputOptions);
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error(error);
|
|
142
|
+
}
|
|
143
|
+
if (bundle) {
|
|
144
|
+
yield bundle.close();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
exports.build = build;
|
|
148
|
+
function likeDependent(str) {
|
|
149
|
+
return !str.match(/^\.?\.\//) && !path.isAbsolute(str);
|
|
150
|
+
}
|
|
151
|
+
function default_1(projectPath, config) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const { sourceRoot, entry, nativeComponents } = config;
|
|
154
|
+
const appPath = path.join(projectPath, sourceRoot, entry);
|
|
155
|
+
const appConfig = (0, rn_transformer_1.getAppConfig)(appPath);
|
|
156
|
+
const { output = DEFAULT_CONFIG.output } = nativeComponents || {};
|
|
157
|
+
const componentConfig = Object.assign(Object.assign({}, nativeComponents), { input: appConfig === null || appConfig === void 0 ? void 0 : appConfig.components, output: path.join(projectPath, output), sourceRootPath: path.join(projectPath, sourceRoot) });
|
|
158
|
+
return (0, exports.build)(config, componentConfig);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
exports.default = default_1;
|
|
162
|
+
//# sourceMappingURL=build-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-component.js","sourceRoot":"","sources":["../../src/config/build-component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAwC;AACxC,oDAAmD;AACnD,4CAA2C;AAC3C,qEAAqD;AACrD,wDAAuD;AACvD,2CAA+C;AAC/C,uEAAkF;AAClF,uDAAqF;AACrF,2DAAqD;AACrD,iCAAgC;AAChC,6BAA4B;AAC5B,mCAA8C;AAC9C,6CAA4C;AAC5C,uEAA4C;AAgB5C,MAAM,cAAc,GAGhB;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defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getRNConfigTransformer = exports.getRNConfigOutput = exports.getRNConfigEntry = exports.getRNConfigBabelPlugin = exports.getRNConfig = exports.getConfig = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
let config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-holder.js","sourceRoot":"","sources":["../../src/config/config-holder.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;
|
|
1
|
+
{"version":3,"file":"config-holder.js","sourceRoot":"","sources":["../../src/config/config-holder.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;AAI9B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,IAAI,MAAc,CAAA;AAClB,IAAI,QAAkB,CAAA;AAEtB,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,IAAI,MAAM;QAAE,OAAO,MAAM,CAAA;IACzB,MAAM,QAAQ,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAA;IACnD,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC3B,MAAM,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,cAAK,CAAC,CAAA;QACxD,OAAO,MAAM,CAAA;KACd;SAAM;QACL,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACxB,MAAM,GAAG,EAAE,CAAA;QACX,OAAO,MAAM,CAAA;KACd;AACH,CAAC,CAAA;AAiDQ,8BAAS;AA/ClB,MAAM,WAAW,GAAG,GAAG,EAAE;IACvB,SAAS,EAAE,CAAA;IACX,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAC7B,IAAI,MAAM,CAAC,EAAE,EAAE;QACb,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAA;KACrB;SAAM;QACL,QAAQ,GAAG,E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