Skip to content

Commit

Permalink
chore: update module-tools and build config (#114)
Browse files Browse the repository at this point in the history
* chore: update build tools and config

* chore: update common/config

1. change target: es5 -> es2015
2. add config type definitions
  • Loading branch information
targeral authored Jun 8, 2023
1 parent 00b1d5d commit 1b6f119
Show file tree
Hide file tree
Showing 64 changed files with 8,667 additions and 6,846 deletions.
11 changes: 11 additions & 0 deletions .changeset/giant-crabs-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@modern-js-reduck/plugin-auto-actions': patch
'@modern-js-reduck/plugin-devtools': patch
'@modern-js-reduck/plugin-effects': patch
'@modern-js-reduck/plugin-immutable': patch
'@modern-js-reduck/react': patch
'@modern-js-reduck/store': patch
---

chore: update build tools and build config, reduck product size.
chore: 更新构建工具和配置,减少产物体积
38 changes: 19 additions & 19 deletions common/config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/**
* @typedef {import('@modern-js/module-tools').ModuleUserConfig} ModuleUserConfig
*/

/**
* @type {ModuleUserConfig}
*/
module.exports = {
tools: {
babel: config => {
const { presets } = config;
for (const preset of presets) {
if (
preset[0].includes('@babel/preset-env') &&
preset[1].modules !== 'commonjs' // exclude dist for node directory
) {
preset[1] = {
targets: {
esmodules: true,
},
// Use the equivalent of `babel-preset-modules`
bugfixes: true,
modules: false,
loose: true,
};
}
buildPreset({ preset }) {
return preset['modern-js-universal'].filter(config => {
// remove esm code that run in node environment.
return !config.outDir.includes('esm-node');
}).map(config => {
// check es5 config, instead of es2015
if (config.target === 'es5') {
config.target = 'es2015';
}
},
return config;
});
},
testing: {
jest: {
collectCoverage: true,
collectCoverageFrom: [
Expand Down
7 changes: 7 additions & 0 deletions common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "common",
"private": true,
"devDependencies": {
"@modern-js/module-tools": "2.21.1"
}
}
5 changes: 5 additions & 0 deletions modern.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const monorepoTools = require('@modern-js/monorepo-tools').default;

module.exports = {
plugins: [monorepoTools()],
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"ignorePatterns": [
"dist",
"lcov-report",
"examples"
"examples",
"common"
]
},
"eslintIgnore": [
Expand All @@ -70,8 +71,9 @@
"@commitlint/cli": "^17.0.0",
"@commitlint/config-conventional": "^17.0.0",
"@modern-js-reduck/scripts": "workspace:*",
"@modern-js/monorepo-tools": "^1.19.0",
"@modern-js/tsconfig": "^1.19.0",
"@modern-js/monorepo-tools": "2.21.1",
"@modern-js/tsconfig": "2.21.1",
"@modern-js/eslint-config": "2.21.1",
"husky": "^8.0.0",
"lint-staged": "^11.2.6",
"webpack": "^5.54.0"
Expand Down
10 changes: 9 additions & 1 deletion packages/plugins/auto-actions/modern.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const {
default: moduleTools,
defineConfig,
} = require('@modern-js/module-tools');
const test = require('@modern-js/plugin-testing').default;
const config = require('../../../common/config');

module.exports = config;
module.exports = defineConfig({
plugins: [moduleTools(), test()],
...config,
});
13 changes: 6 additions & 7 deletions packages/plugins/auto-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
],
"jsnext:source": "./src/index.ts",
"types": "./dist/types/index.d.ts",
"main": "./dist/js/node/index.js",
"module": "./dist/js/treeshaking/index.js",
"jsnext:modern": "./dist/js/modern/index.js",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
"homepage": "https://modernjs.dev",
"bugs": "https://github.com/modern-js-dev/reduck/issues",
Expand All @@ -24,7 +23,7 @@
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"default": "./dist/js/treeshaking/index.js"
"default": "./dist/esm/index.js"
}
},
"scripts": {
Expand All @@ -35,12 +34,12 @@
"test": "modern test"
},
"dependencies": {
"@babel/runtime": "^7"
"@swc/helpers": "0.5.1"
},
"devDependencies": {
"@modern-js-reduck/store": "workspace:*",
"@modern-js/module-tools": "^1.7.1",
"@modern-js/plugin-testing": "^1.6.0",
"@modern-js/module-tools": "2.21.1",
"@modern-js/plugin-testing": "2.21.1",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"typescript": "^4",
Expand Down
6 changes: 6 additions & 0 deletions packages/plugins/auto-actions/tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: '@modern-js',
parserOptions: {
project: require.resolve('./tsconfig.json'),
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStore, model } from '@modern-js-reduck/store';
import plugin from '..';
import plugin from '../src';

const testModel = model('name').define({
state: [1, 2, 3],
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/auto-actions/tests/modern-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@modern-js/module-tools/types" />
/// <reference types="@modern-js/plugin-testing/type" />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStore, model } from '@modern-js-reduck/store';
import plugin from '..';
import plugin from '../src';

const testModel = model('name').define({
state: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStore, model } from '@modern-js-reduck/store';
import plugin from '..';
import plugin from '../src';

const testModel = model('name').define({
state: 0,
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/auto-actions/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "../"
},
"include": ["**/*"]
}
10 changes: 9 additions & 1 deletion packages/plugins/devtools/modern.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const {
default: moduleTools,
defineConfig,
} = require('@modern-js/module-tools');
const test = require('@modern-js/plugin-testing').default;
const config = require('../../../common/config');

module.exports = config;
module.exports = defineConfig({
plugins: [moduleTools(), test()],
...config,
});
13 changes: 6 additions & 7 deletions packages/plugins/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
],
"jsnext:source": "./src/index.ts",
"types": "./dist/types/index.d.ts",
"main": "./dist/js/node/index.js",
"module": "./dist/js/treeshaking/index.js",
"jsnext:modern": "./dist/js/modern/index.js",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
"homepage": "https://modernjs.dev",
"bugs": "https://github.com/modern-js-dev/reduck/issues",
Expand All @@ -24,7 +23,7 @@
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"default": "./dist/js/treeshaking/index.js"
"default": "./dist/esm/index.js"
}
},
"scripts": {
Expand All @@ -35,14 +34,14 @@
"test": "modern test --passWithNoTests"
},
"dependencies": {
"@babel/runtime": "^7",
"@swc/helpers": "0.5.1",
"@redux-devtools/extension": "^3.2.2",
"redux": "^4.1.1"
},
"devDependencies": {
"@modern-js-reduck/store": "workspace:*",
"@modern-js/module-tools": "^1.7.1",
"@modern-js/plugin-testing": "^1.6.0",
"@modern-js/module-tools": "2.21.1",
"@modern-js/plugin-testing": "2.21.1",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"typescript": "^4",
Expand Down
10 changes: 9 additions & 1 deletion packages/plugins/effects/modern.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const {
default: moduleTools,
defineConfig,
} = require('@modern-js/module-tools');
const test = require('@modern-js/plugin-testing').default;
const config = require('../../../common/config');

module.exports = config;
module.exports = defineConfig({
plugins: [moduleTools(), test()],
...config,
});
13 changes: 6 additions & 7 deletions packages/plugins/effects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
],
"jsnext:source": "./src/index.ts",
"types": "./dist/types/index.d.ts",
"main": "./dist/js/node/index.js",
"module": "./dist/js/treeshaking/index.js",
"jsnext:modern": "./dist/js/modern/index.js",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
"homepage": "https://modernjs.dev",
"bugs": "https://github.com/modern-js-dev/reduck/issues",
Expand All @@ -24,7 +23,7 @@
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"default": "./dist/js/treeshaking/index.js"
"default": "./dist/esm/index.js"
}
},
"scripts": {
Expand All @@ -35,14 +34,14 @@
"test": "modern test"
},
"dependencies": {
"@babel/runtime": "^7",
"@swc/helpers": "0.5.1",
"redux": "^4.1.1",
"redux-promise-middleware": "^6.1.2"
},
"devDependencies": {
"@modern-js-reduck/store": "workspace:*",
"@modern-js/module-tools": "^1.7.1",
"@modern-js/plugin-testing": "^1.6.0",
"@modern-js/module-tools": "2.21.1",
"@modern-js/plugin-testing": "2.21.1",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/redux-logger": "^3.0.9",
Expand Down
6 changes: 6 additions & 0 deletions packages/plugins/effects/tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: '@modern-js',
parserOptions: {
project: require.resolve('./tsconfig.json'),
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStore, model } from '@modern-js-reduck/store';
import logger from 'redux-logger';
import { plugin } from '..';
import { plugin } from '../src';
import handleEffect from '@/utils/handleEffect';

jest.setTimeout(500000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStore, model } from '@modern-js-reduck/store';
import logger from 'redux-logger';
import { plugin } from '..';
import { plugin } from '../src';

const todoModel = model('todo').define((_, { use }) => ({
state: {
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/effects/tests/modern-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@modern-js/module-tools/types" />
/// <reference types="@modern-js/plugin-testing/type" />
7 changes: 7 additions & 0 deletions packages/plugins/effects/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "../"
},
"include": ["**/*"]
}
10 changes: 9 additions & 1 deletion packages/plugins/immer/modern.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const {
default: moduleTools,
defineConfig,
} = require('@modern-js/module-tools');
const test = require('@modern-js/plugin-testing').default;
const config = require('../../../common/config');

module.exports = config;
module.exports = defineConfig({
plugins: [moduleTools(), test()],
...config,
});
13 changes: 6 additions & 7 deletions packages/plugins/immer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
],
"jsnext:source": "./src/index.ts",
"types": "./dist/types/index.d.ts",
"main": "./dist/js/node/index.js",
"module": "./dist/js/treeshaking/index.js",
"jsnext:modern": "./dist/js/modern/index.js",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
"homepage": "https://modernjs.dev",
"bugs": "https://github.com/modern-js-dev/reduck/issues",
Expand All @@ -24,7 +23,7 @@
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"default": "./dist/js/treeshaking/index.js"
"default": "./dist/esm/index.js"
}
},
"scripts": {
Expand All @@ -35,13 +34,13 @@
"test": "modern test"
},
"dependencies": {
"@babel/runtime": "^7",
"@swc/helpers": "0.5.1",
"immer": "^9.0.5"
},
"devDependencies": {
"@modern-js-reduck/store": "workspace:*",
"@modern-js/module-tools": "^1.7.1",
"@modern-js/plugin-testing": "^1.6.0",
"@modern-js/module-tools": "2.21.1",
"@modern-js/plugin-testing": "2.21.1",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"typescript": "^4",
Expand Down
6 changes: 6 additions & 0 deletions packages/plugins/immer/tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: '@modern-js',
parserOptions: {
project: require.resolve('./tsconfig.json'),
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
import { model, createStore } from '@modern-js-reduck/store';
import immerPlugin from '..';
import immerPlugin from '../src';

const count = model('count').define({
state: {
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/immer/tests/modern-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@modern-js/module-tools/types" />
/// <reference types="@modern-js/plugin-testing/type" />
7 changes: 7 additions & 0 deletions packages/plugins/immer/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "../"
},
"include": ["**/*"]
}
Loading

0 comments on commit 1b6f119

Please sign in to comment.