Skip to content

Commit

Permalink
build(rollup): refactor build srcipt with rollup (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib authored Dec 15, 2023
1 parent f283dad commit 47de9b3
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 3,780 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:

- uses: actions/checkout@v1

- name: Use Node.js 14.x
- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 18.x

- name: yarn install, yarn test:coverage
run: |
Expand Down
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line no-var
declare var __DEV__: boolean;
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"performance:sample": "cd test/performance && NODE_ENV='production' ts-node sample.ts",
"performance:array-object": "cd test/performance && NODE_ENV='production' ts-node array-object.ts",
"performance": "yarn build && yarn perf && yarn performance:basic && yarn performance:set-map && yarn performance:big-object && yarn performance:sample && yarn performance:array-object",
"build": "tsdx build --format esm,cjs,umd && cp dist/mutative.esm.js dist/mutative.esm.mjs",
"build": "yarn clean && rollup --config --bundleConfigAsCjs",
"build:doc": "rimraf docs && typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts --readme none",
"commit": "yarn git-cz",
"size": "size-limit",
Expand Down Expand Up @@ -78,6 +78,11 @@
},
"homepage": "https://github.com/unadlib/mutative#readme",
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@size-limit/esbuild": "^8.2.6",
"@size-limit/esbuild-why": "^8.2.6",
"@size-limit/preset-small-lib": "^8.1.0",
Expand Down Expand Up @@ -109,13 +114,12 @@
"quickchart-js": "^3.1.2",
"redux": "^4.2.0",
"rimraf": "^3.0.2",
"rollup": "^2.70.1",
"rollup": "^4.9.0",
"rollup-plugin-terser": "^7.0.0",
"seamless-immutable": "^7.1.4",
"size-limit": "^8.1.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"tsdx": "^0.14.1",
"tslib": "^2.6.2",
"typedoc": "^0.24.4",
"typedoc-plugin-markdown": "^3.15.1",
Expand Down
102 changes: 102 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* eslint-disable import/no-extraneous-dependencies */
import fs from 'fs';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import pkg from './package.json';

export default [
{
input: 'src/index.ts',
output: [
{
format: 'cjs',
file: 'dist/mutative.cjs.production.min.js',
sourcemap: true,
plugins: [terser()],
},
{
format: 'umd',
name: pkg.name
.split('-')
.map(([s, ...rest]) => [s.toUpperCase(), ...rest].join(''))
.join(''),
file: pkg.unpkg,
sourcemap: true,
plugins: [terser()],
},
],
plugins: [
resolve(),
commonjs(),
typescript({
declaration: true,
declarationDir: 'dist',
}),
replace({
__DEV__: 'false',
preventAssignment: true,
}),
],
},
{
input: 'src/index.ts',
output: [
{
format: 'cjs',
file: 'dist/mutative.cjs.development.js',
sourcemap: true,
},
{
format: 'es',
file: 'dist/mutative.esm.js',
sourcemap: true,
},
{
format: 'es',
file: 'dist/mutative.esm.mjs',
sourcemap: true,
},
{
format: 'umd',
name: pkg.name
.split('-')
.map(([s, ...rest]) => [s.toUpperCase(), ...rest].join(''))
.join(''),
file: pkg.unpkg.replace('.production.min.js', '.development.js'),
sourcemap: true,
},
],
plugins: [
resolve(),
commonjs(),
typescript({
declaration: true,
declarationDir: 'dist',
}),
replace({
__DEV__: 'true',
preventAssignment: true,
}),
{
name: 'create-cjs-index',
buildEnd: () => {
fs.writeFileSync(
'dist/index.js',
`
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./mutative.cjs.production.min.js')
} else {
module.exports = require('./mutative.cjs.development.js')
}
`
);
},
},
],
},
];
Loading

0 comments on commit 47de9b3

Please sign in to comment.