Skip to content

Commit

Permalink
feat(project): support bundle dts (#1796)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jul 14, 2021
1 parent 2369c00 commit 5f8c187
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 35 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"rollup-plugin-inject-process-env": "^1.3.1",
"rollup-plugin-dts": "^2.0.0",
"semver": "^7.3.5",
"semver-regex": "^2.0.0",
"showdown": "^1.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/docs/api/models/Form.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ interface deleteValuesIn {

FormPathPattern API 参考 [FormPath](/api/entry/form-path#formpathpattern)

### deleteIntialValuesIn
### deleteInitialValuesIn

#### 描述

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ test('deleteValuesIn/deleteInitialValuesIn', () => {
expect(form.values.aa).toEqual(123)
expect(form.values.bb).toEqual(123)
form.deleteValuesIn('aa')
form.deleteIntialValuesIn('bb')
form.deleteInitialValuesIn('bb')
expect(form.existValuesIn('aa')).toBeFalsy()
expect(form.existInitialValuesIn('bb')).toBeFalsy()
})
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Form<ValueType extends object = any> {
setPattern: batch,
setDisplay: batch,
setState: batch,
deleteIntialValuesIn: batch,
deleteInitialValuesIn: batch,
deleteValuesIn: batch,
setSubmitting: batch,
setValidating: batch,
Expand Down Expand Up @@ -450,7 +450,7 @@ export class Form<ValueType extends object = any> {
})
}

deleteIntialValuesIn = (pattern: FormPathPattern) => {
deleteInitialValuesIn = (pattern: FormPathPattern) => {
untracked(() => {
FormPath.deleteIn(this.initialValues, pattern)
})
Expand Down
92 changes: 61 additions & 31 deletions scripts/rollup.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import resolve from 'rollup-plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import externalGlobals from 'rollup-plugin-external-globals'
import injectProcessEnv from 'rollup-plugin-inject-process-env'
import dts from 'rollup-plugin-dts'
import { terser } from 'rollup-plugin-terser'

const presets = () => {
Expand Down Expand Up @@ -62,6 +63,20 @@ const createEnvPlugin = (env) => {
}

const inputFilePath = path.join(process.cwd(), 'src/index.ts')

const bundleDtsPackages = [
'formily.core',
'formily.react',
'formily.vue',
'formily.validator',
'formily.shared',
'formily.path',
'formily.json-schema',
'formily.reactive',
'formily.reactive-react',
'formily.reactive-vue',
]

export const removeImportStyleFromInputFilePlugin = () => ({
name: 'remove-import-style-from-input-file',
transform(code, id) {
Expand All @@ -74,38 +89,53 @@ export const removeImportStyleFromInputFilePlugin = () => ({
},
})

export default (filename, targetName, ...plugins) => [
{
input: 'src/index.ts',
output: {
format: 'umd',
file: `dist/${filename}.umd.development.js`,
name: targetName,
sourcemap: true,
amd: {
id: filename,
export default (filename, targetName, ...plugins) => {
const base = [
{
input: 'src/index.ts',
output: {
format: 'umd',
file: `dist/${filename}.umd.development.js`,
name: targetName,
sourcemap: true,
amd: {
id: filename,
},
},
external: ['react', 'react-dom', 'react-is'],
plugins: [...presets(), ...plugins, createEnvPlugin('development')],
},
external: ['react', 'react-dom', 'react-is'],
plugins: [...presets(), ...plugins, createEnvPlugin('development')],
},
{
input: 'src/index.ts',
output: {
format: 'umd',
file: `dist/${filename}.umd.production.js`,
name: targetName,
sourcemap: true,
amd: {
id: filename,
{
input: 'src/index.ts',
output: {
format: 'umd',
file: `dist/${filename}.umd.production.js`,
name: targetName,
sourcemap: true,
amd: {
id: filename,
},
},
external: ['react', 'react-dom', 'react-is'],
plugins: [
...presets(),
terser(),
...plugins,
createEnvPlugin('production'),
],
},
external: ['react', 'react-dom', 'react-is'],
plugins: [
...presets(),
terser(),
...plugins,
createEnvPlugin('production'),
],
},
]
]

if (bundleDtsPackages.includes(filename)) {
base.push({
input: 'esm/index.d.ts',
output: {
format: 'es',
file: `dist/${filename}.d.ts`,
},
plugins: [dts(), ...plugins],
})
}

return base
}
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16342,6 +16342,15 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^3.0.0"
inherits "^2.0.1"

rollup-plugin-dts@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-2.0.1.tgz#333f50a637e199a073d490b198746f3c6bd07701"
integrity sha512-y38NSXIY37YExCumbGBTL5dXg7pL7XD+Kbe98iEHWFN9yiKJf7t4kKBOkml5ylUDjQIXBnNClGDeRktc1T5dmA==
dependencies:
magic-string "^0.25.7"
optionalDependencies:
"@babel/code-frame" "^7.10.4"

rollup-plugin-external-globals@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-external-globals/-/rollup-plugin-external-globals-0.6.1.tgz#861c260b5727144e0fd1b424b103f9f0282fc365"
Expand Down

0 comments on commit 5f8c187

Please sign in to comment.