-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(rollup): refactor build srcipt with rollup
- Loading branch information
Showing
6 changed files
with
416 additions
and
3,780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
// eslint-disable-next-line no-var | ||
declare var __DEV__: boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
` | ||
); | ||
}, | ||
}, | ||
], | ||
}, | ||
]; |
Oops, something went wrong.