Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/plugin-dva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.11.1](https://github.com/umijs/plugins/compare/@umijs/plugin-dva@0.11.0...@umijs/plugin-dva@0.11.1) (2021-04-09)

### Bug Fixes

- **dva:** dva model import undefined when from umi ([#523](https://github.com/umijs/plugins/issues/523)) ([1d8fb78](https://github.com/umijs/plugins/commit/1d8fb78e6ccda237307867bb0954fb840c95f930))

# [0.11.0](https://github.com/umijs/plugins/compare/@umijs/plugin-dva@0.10.0...@umijs/plugin-dva@0.11.0) (2021-03-26)

### Features

- improve dva log ([#562](https://github.com/umijs/plugins/issues/562)) ([4d84817](https://github.com/umijs/plugins/commit/4d84817a041fd259afb6a8c7f6abfac16e7925e5))

# [0.10.0](https://github.com/umijs/plugins/compare/@umijs/plugin-dva@0.9.1...@umijs/plugin-dva@0.10.0) (2021-01-13)

### Features
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dva/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@umijs/plugin-dva",
"version": "0.10.0",
"version": "0.11.1",
"description": "@umijs/plugin-dva",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
20 changes: 18 additions & 2 deletions packages/plugin-dva/src/dva.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import dva from 'dva';
// @ts-ignore
import createLoading from '{{{ dvaLoadingPkgPath }}}';
import { plugin, history } from '../core/umiExports';
{{ ^LazyLoad }}
{{{ RegisterModelImports }}}
{{ /LazyLoad }}
{{ #dvaImmer }}
import dvaImmer, { enableES5 } from '{{{ dvaImmerPath }}}';
{{ /dvaImmer }}

let app:any = null;

export function _onCreate(options = {}) {
export {{ #LazyLoad }}async {{ /LazyLoad }}function _onCreate(options = {}) {
const runtimeDva = plugin.applyPlugins({
key: 'dva',
type: ApplyPluginsType.modify,
initialValue: {},
});
{{ #LazyLoad }}
{{{ RegisterModelImports }}}
{{ /LazyLoad }}
app = dva({
history,
{{{ ExtendDvaConfig }}}
Expand Down Expand Up @@ -49,7 +54,13 @@ export class _DvaContainer extends Component {
super(props);
// run only in client, avoid override server _onCreate()
if (typeof window !== 'undefined') {
_onCreate();
_onCreate()
{{ #LazyLoad }}
.then(() => {
// force update
this.forceUpdate();
});
{{ /LazyLoad }}
}
}

Expand All @@ -70,6 +81,11 @@ export class _DvaContainer extends Component {

render() {
const app = getApp();
{{ #LazyLoad }}
if (!app) {
return null;
}
{{ /LazyLoad }}
app.router(() => this.props.children);
return app.start()();
}
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-dva/src/fixtures/lazyLoad/.umirc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

export default {
routes: [
{ path: '/', component: 'index' },
],
dva: {
lazyLoad: true,
},
plugins: [
require.resolve('../../'),
],
}
9 changes: 9 additions & 0 deletions packages/plugin-dva/src/fixtures/lazyLoad/models/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { data } from '../utils'

export default {
state: {
desc: 'foo',
count: 0,
data,
},
}
7 changes: 7 additions & 0 deletions packages/plugin-dva/src/fixtures/lazyLoad/pages/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

.normal {
}

.title {
background: rgb(196, 242, 121);
}
15 changes: 15 additions & 0 deletions packages/plugin-dva/src/fixtures/lazyLoad/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import styles from './index.less';
import { connect } from 'dva';

export const data = {};

export default connect(state => ({
foo: state.foo,
}))((props) => {
return (
<div>
<h1 className={styles.title}>Page index { props.foo.desc } { props.foo.count }</h1>
</div>
);
})
1 change: 1 addition & 0 deletions packages/plugin-dva/src/fixtures/lazyLoad/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { data } from './pages/index';
10 changes: 10 additions & 0 deletions packages/plugin-dva/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ test('with-immer', async () => {
'<div><h1 class="title">Page index foo 1</h1><button>add</button></div>',
);
});

test('lazyLoad', async () => {
const cwd = join(fixtures, 'lazyLoad');
await generateTmp({ cwd });
const { container } = render({ cwd });
await utils.delay(100);
expect(container.innerHTML).toEqual(
'<div><h1 class="title">Page index foo 0</h1></div>',
);
});
13 changes: 11 additions & 2 deletions packages/plugin-dva/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export default (api: IApi) => {
schema(joi) {
return joi.object({
disableModelsReExport: joi.boolean(),
lazyLoad: joi
.boolean()
.description(
'lazy load dva model avoiding the import modules from umi undefined',
),
extraModels: joi.array().items(joi.string()),
hmr: joi.boolean(),
immer: joi.alternatives(joi.boolean(), joi.object()),
Expand Down Expand Up @@ -107,11 +112,15 @@ export default (api: IApi) => {
dvaImmerES5:
lodash.isPlainObject(api.config.dva?.immer) &&
api.config.dva?.immer.enableES5,
LazyLoad: api.config.dva?.lazyLoad,
RegisterModelImports: models
.map((path, index) => {
return `import Model${lodash.upperFirst(
const modelName = `Model${lodash.upperFirst(
lodash.camelCase(basename(path, extname(path))),
)}${index} from '${path}';`;
)}${index}`;
return api.config.dva?.lazyLoad
? `const ${modelName} = (await import('${path}')).default;`
: `import ${modelName} from '${path}';`;
})
.join('\r\n'),
RegisterModels: models
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-esbuild/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.2.0](https://github.com/umijs/plugins/compare/@umijs/plugin-esbuild@1.1.1...@umijs/plugin-esbuild@1.2.0) (2021-04-09)

### Features

- **esbuild:** exposes minify pure config ([#575](https://github.com/umijs/plugins/issues/575)) ([ed7f688](https://github.com/umijs/plugins/commit/ed7f688da63e343c330211147d74916c510c504a))

## [1.1.1](https://github.com/umijs/plugins/compare/@umijs/plugin-esbuild@1.1.0...@umijs/plugin-esbuild@1.1.1) (2021-03-26)

### Bug Fixes

- **esbuild:** minify exposes target config for es5 projects ([#571](https://github.com/umijs/plugins/issues/571)) ([cb93b3a](https://github.com/umijs/plugins/commit/cb93b3a969d9f94c808eda8e02828f347cc2eca0))

## [1.0.3](https://github.com/umijs/plugins/compare/@umijs/plugin-esbuild@1.0.2...@umijs/plugin-esbuild@1.0.3) (2020-12-15)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@umijs/plugin-esbuild",
"version": "1.1.0",
"version": "1.2.0",
"description": "@umijs/plugin-esbuild",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
22 changes: 22 additions & 0 deletions packages/plugin-esbuild/src/fixtures/es5/.umirc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

export default {
nodeModulesTransform: {
type: 'none',
},
targets: {
ie: 11,
},
history: {
type: 'memory',
options: {
initialEntries: ['/'],
},
},
mountElementId: '',
routes: [
{ path: '/', component: 'index' },
],
esbuild: {
target: 'es5',
},
}
3 changes: 3 additions & 0 deletions packages/plugin-esbuild/src/fixtures/es5/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

export default () => <div>Hello</div>
export default () => {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
}
36 changes: 35 additions & 1 deletion packages/plugin-esbuild/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { join } from 'path';
import { existsSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import { Service } from 'umi';

const fixtures = join(__dirname, 'fixtures');

jest.setTimeout(300000);

describe('normal build', () => {
let err: any;
const cwd = join(fixtures, 'normal');
Expand All @@ -27,6 +29,38 @@ describe('normal build', () => {
it('normal', () => {
expect(err).toBeFalsy();
expect(existsSync(join(cwd, 'dist', 'umi.js'))).toBeTruthy();
expect(readFileSync(join(cwd, 'dist', 'umi.js'), 'utf8')).toContain(
'new TypeError(`Invalid attempt to spread non-iterable',
);
});
});

describe('es5 build', () => {
let err: any;
const cwd = join(fixtures, 'es5');
beforeAll(async () => {
const service = new Service({
cwd,
env: 'production',
plugins: [require.resolve('./index.ts')],
});
let err;
try {
await service.run({
name: 'build',
});
} catch (e) {
console.error('es5 build error', e);
err = true;
}
});

it('es5', () => {
expect(err).toBeFalsy();
expect(existsSync(join(cwd, 'dist', 'umi.js'))).toBeTruthy();
expect(readFileSync(join(cwd, 'dist', 'umi.js'), 'utf8')).toContain(
'new TypeError("Invalid attempt to spread non-iterable',
);
});
});

Expand Down
12 changes: 10 additions & 2 deletions packages/plugin-esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@ export default (api: IApi) => {
key: 'esbuild',
config: {
schema(joi) {
return joi.object();
return joi.object({
target: joi.alternatives(
joi.string(),
joi.array().items(joi.string()),
),
});
},
},
enableBy: api.EnableBy.config,
});

api.modifyBundleConfig((memo, { type }) => {
if (memo.optimization) {
const { target = 'es2015', pure } = api.config.esbuild || {};
const optsMap = {
[BundlerConfigType.csr]: {
target: 'es2015',
minify: true,
target,
pure,
},
[BundlerConfigType.ssr]: {
target: 'node10',
minify: true,
pure,
},
};
const opts = optsMap[type] || optsMap[BundlerConfigType.csr];
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-helmet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.2](https://github.com/umijs/plugins/compare/@umijs/plugin-helmet@1.1.1...@umijs/plugin-helmet@1.1.2) (2021-03-26)

### Bug Fixes

- **ssr:** 修复 SSR 下 helmet 无法添加<link>的问题 ([#561](https://github.com/umijs/plugins/issues/561)) ([8072710](https://github.com/umijs/plugins/commit/8072710bb433a109eb01f9d4e56059ff18270592))

## [1.1.1](https://github.com/umijs/plugins/compare/@umijs/plugin-helmet@1.1.0...@umijs/plugin-helmet@1.1.1) (2020-08-27)

**Note:** Version bump only for package @umijs/plugin-helmet
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-helmet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@umijs/plugin-helmet",
"version": "1.1.1",
"version": "1.1.2",
"description": "@umijs/plugin-helmet",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-helmet/src/templates/runtime.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (process.env.__IS_SERVER) {
$('head').append(meta);
}
if (link) {
$('link').append(link);
$('head').append(link);
}
if (Object.keys(htmlAttributes)) {
Object.keys(htmlAttributes).forEach(attrKey => {
Expand Down
29 changes: 12 additions & 17 deletions packages/plugin-locale/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.10.10](https://github.com/umijs/plugins/compare/@umijs/plugin-locale@0.10.9...@umijs/plugin-locale@0.10.10) (2021-03-19)
# [0.11.0](https://github.com/umijs/plugins/compare/@umijs/plugin-locale@0.10.10...@umijs/plugin-locale@0.11.0) (2021-04-09)

**Note:** Version bump only for package @umijs/plugin-locale
### Bug Fixes

- to solve the problem that FormattedMessage report [React Intl] Missing message error, it was encountered in the situation when calling addLocale to add/merge translation key-value pairs which were fetched from backend server for current language. ([#573](https://github.com/umijs/plugins/issues/573)) ([e6f5625](https://github.com/umijs/plugins/commit/e6f56255b5df987030dd29468fa67d992036fb78))

### Features

- **locale:** add 8px margin between icon and label for SelectLang ([#557](https://github.com/umijs/plugins/issues/557)) ([ff99186](https://github.com/umijs/plugins/commit/ff991860d6ce5308d64eca5129583cceec587ea1))

## [0.10.10](https://github.com/umijs/plugins/compare/@umijs/plugin-locale@0.10.9...@umijs/plugin-locale@0.10.10) (2021-03-19)

## [0.10.9](https://github.com/umijs/plugins/compare/@umijs/plugin-locale@0.10.8...@umijs/plugin-locale@0.10.9) (2021-03-04)
**Note:** Version bump only for package @umijs/plugin-locale

## [0.10.9](https://github.com/umijs/plugins/compare/@umijs/plugin-locale@0.10.8...@umijs/plugin-locale@0.10.9) (2021-03-04)

### Bug Fixes

* useLayoutEffect will be warning in ssr mode ([#533](https://github.com/umijs/plugins/issues/533)) ([2b2c169](https://github.com/umijs/plugins/commit/2b2c16996fd228ecab411d916f8ab255d1982416))
* when has runtimeLocale.setLocale setLocale not work ([#543](https://github.com/umijs/plugins/issues/543)) ([afc144c](https://github.com/umijs/plugins/commit/afc144c282d0156626432ce167dcf9ac3023ca98))




- useLayoutEffect will be warning in ssr mode ([#533](https://github.com/umijs/plugins/issues/533)) ([2b2c169](https://github.com/umijs/plugins/commit/2b2c16996fd228ecab411d916f8ab255d1982416))
- when has runtimeLocale.setLocale setLocale not work ([#543](https://github.com/umijs/plugins/issues/543)) ([afc144c](https://github.com/umijs/plugins/commit/afc144c282d0156626432ce167dcf9ac3023ca98))

## [0.10.8](https://github.com/umijs/plugins/compare/@umijs/plugin-locale@0.10.7...@umijs/plugin-locale@0.10.8) (2021-01-19)


### Bug Fixes

* **locale:** unused return statement ([#513](https://github.com/umijs/plugins/issues/513)) ([05251df](https://github.com/umijs/plugins/commit/05251df6e33a58084fcd5b7d36d8e0cb60f7f07e))




- **locale:** unused return statement ([#513](https://github.com/umijs/plugins/issues/513)) ([05251df](https://github.com/umijs/plugins/commit/05251df6e33a58084fcd5b7d36d8e0cb60f7f07e))

## [0.10.7](https://github.com/umijs/plugins/compare/@umijs/plugin-locale@0.10.6...@umijs/plugin-locale@0.10.7) (2021-01-13)

Expand Down
Loading