intentionally not using .babelrc
Last active
July 14, 2020 06:40
-
-
Save thisconnect/c5b3cb626953dd3b0001 to your computer and use it in GitHub Desktop.
rollup split lib and app
This file contains hidden or 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
import * as Lib from 'lib'; | |
console.log('APP'); | |
console.log(Lib); |
This file contains hidden or 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
// used as entry point to build the common lib | |
console.log('LIB ENTRY POINT'); | |
import { a, b } from 'lib'; | |
export default { a, b }; |
This file contains hidden or 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
{ | |
"name": "test-split-app-lib", | |
"version": "0.1.0", | |
"description": "", | |
"scripts": { | |
"start": "npm run build-app & npm run build-lib", | |
"build-app": "babel-node --presets es2015 rollup.app.js", | |
"build-lib": "babel-node --presets es2015 rollup.lib.js" | |
}, | |
"author": "Enrique Erne", | |
"license": "MIT", | |
"dependencies": {}, | |
"devDependencies": { | |
"babel-cli": "^6.3.17", | |
"babel-eslint": "^4.1.6", | |
"babel-preset-es2015-rollup": "^1.1.1", | |
"rollup": "^0.24.1", | |
"rollup-plugin-babel": "^2.3.9", | |
"rollup-plugin-commonjs": "^2.1.0", | |
"rollup-plugin-npm": "^1.2.0" | |
} | |
} |
This file contains hidden or 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
import { rollup } from 'rollup'; | |
import npm from 'rollup-plugin-npm'; | |
import commonjs from 'rollup-plugin-commonjs'; | |
import babel from 'rollup-plugin-babel'; | |
rollup({ | |
'entry': 'app.js', | |
'external': ['lib'], | |
'plugins': [ | |
npm({ 'jsnext': true, 'main': true/*, skip: ['lib']*/}), | |
commonjs(), | |
babel({ 'babelrc': false, 'presets': ['es2015-rollup'] }) | |
] | |
}) | |
.then( bundle => bundle.write({ | |
'banner': '/* APP */', | |
'dest': 'build/app.js', | |
'format': 'iife', | |
'globals': { | |
'lib': 'Lib' | |
}, | |
'sourceMap': true | |
}) ) | |
.catch( error => console.log(error) ); |
This file contains hidden or 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
import { rollup } from 'rollup'; | |
import npm from 'rollup-plugin-npm'; | |
import commonjs from 'rollup-plugin-commonjs'; | |
import babel from 'rollup-plugin-babel'; | |
// import uglify from 'rollup-plugin-uglify'; | |
rollup({ | |
'entry': 'lib.js', | |
'plugins': [ | |
babel({ 'babelrc': false, 'presets': ['es2015-rollup'] }), | |
npm({ 'jsnext': true, 'main': true}), | |
commonjs() | |
// uglify() | |
] | |
}) | |
.then( bundle => bundle.write({ | |
'dest': 'build/lib.js', | |
// 'exports': 'named', | |
'format': 'iife', | |
'moduleName': 'Lib', | |
'banner': '/* Lib */', | |
'sourceMap': true | |
}) ) | |
.catch( error => console.log(error) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it necessary to run
rollup.app.js
androllup.lib.js
insidebabel-node
?