@@ -2,6 +2,7 @@ const spawn = require("cross-spawn");
22const validate = require ( "validate-npm-package-name" ) ;
33const serializePackage = require ( "./utils/serializePackage" ) ;
44const serializeTSConfig = require ( "./utils/serializeTSConfig" ) ;
5+ const serializeRollupConfig = require ( "./utils/serializeRollupConfig" ) ;
56const prompts = require ( "./prompts" ) ;
67
78module . exports = {
@@ -35,7 +36,6 @@ module.exports = {
3536 description : this . answers . description ,
3637 version : "0.0.1" ,
3738 main : "lib/index.js" ,
38- module : "lib/index.es.js" ,
3939 types : "lib/index.d.ts" ,
4040 files : [ "lib" ] ,
4141 publishConfig : { access : "public" } ,
@@ -44,10 +44,7 @@ module.exports = {
4444 contributors : [ ] ,
4545 repository : "" ,
4646 license : "MIT" ,
47- scripts : [
48- { build : "rm -rf ./lib/** && tsx" } ,
49- { watch : "tsc -- --watch" }
50- ] ,
47+ scripts : [ { build : "rollup -c" } , { watch : "rollup -cw" } ] ,
5148 dependencies : [ ] ,
5249 devDependencies : [
5350 { "@babel/cli" : "^7.2.3" } ,
@@ -67,11 +64,73 @@ module.exports = {
6764 { "tslint-react" : "^3.6.0" } ,
6865 { typescript : "^3.3.3333" } ,
6966 { react : "*" } ,
70- { "react-dom" : "*" }
67+ { "react-dom" : "*" } ,
68+ { rollup : "^1.27.5" } ,
69+ { "rollup-plugin-babel-minify" : "^9.1.1" } ,
70+ { "rollup-plugin-cleanup" : "^3.1.1" } ,
71+ { "rollup-plugin-commonjs" : "^10.1.0" } ,
72+ { "rollup-plugin-delete" : "^1.1.0" } ,
73+ { "rollup-plugin-progress" : "^1.1.1" } ,
74+ { "rollup-plugin-typescript2" : "^0.25.2" }
7175 ] ,
7276 peerDependencies : [ { react : "*" } , { "react-dom" : "*" } ]
7377 } ;
7478
79+ const rollupConfig = {
80+ input : "./src/index.tsx" ,
81+ output : [ ] ,
82+ plugins : [
83+ `progress({clearLines: false})` ,
84+ `del({targets: [
85+ "lib/*"
86+ ]})` ,
87+ `commonjs({
88+ namedExports: {}
89+ })` ,
90+ `typescript()` ,
91+ `minify()` ,
92+ `cleanup()`
93+ ] ,
94+ external : [
95+ "...Object.keys(pkg.dependencies || {})" ,
96+ "...Object.keys(pkg.peerDependencies || {})"
97+ ]
98+ } ;
99+
100+ if ( this . answers . umd ) {
101+ if ( ! this . answers . umd_name || ! this . answers . umd_name . trim ( ) ) {
102+ console . error (
103+ this
104+ . chalk `{red No global UMD name defined while UMD module build is enabled}`
105+ ) ;
106+ process . exit ( 1 ) ;
107+ }
108+ const umdOutput = `{
109+ file: pkg.main,
110+ format: "umd",
111+ name: "${ this . answers . umd_name } ",
112+ globals: {
113+ react: "React"
114+ }
115+ }` ;
116+ rollupConfig . output . push ( umdOutput ) ;
117+ } else {
118+ const cjsOutput = `{
119+ file: pkg.main,
120+ format: "cjs"
121+ }` ;
122+ rollupConfig . output . push ( cjsOutput ) ;
123+ }
124+
125+ if ( this . answers . es ) {
126+ package . module = "lib/index.es.js" ;
127+ const esOutput = `{
128+ file: pkg.module,
129+ format: "es"
130+ }` ;
131+ rollupConfig . output . push ( esOutput ) ;
132+ }
133+
75134 if ( this . answers . tests ) {
76135 tsconfig . includes . push ( "./__tests__" ) ;
77136 package . scripts . push ( { test : "jest" } ) ;
@@ -144,6 +203,7 @@ module.exports = {
144203 return {
145204 tsconfig : serializeTSConfig ( tsconfig ) ,
146205 package : serializePackage ( package ) ,
206+ rollupConfig : serializeRollupConfig ( rollupConfig ) ,
147207 pmRun
148208 } ;
149209 } ,
@@ -184,6 +244,7 @@ module.exports = {
184244 babelrc : ".babelrc" ,
185245 travis_yml : ".travis.yml" ,
186246 jest_config_js : "jest.config.js" ,
247+ rollup_config_js : "rollup.config.js" ,
187248 releaserc : ".releaserc" ,
188249 _package_json : "package.json" ,
189250 _tsconfig_json : "tsconfig.json" ,
0 commit comments