Skip to content

Instantly share code, notes, and snippets.

@thisconnect
Last active July 14, 2020 06:40

Revisions

  1. tcme revised this gist Jan 17, 2016. 4 changed files with 16 additions and 4 deletions.
    4 changes: 3 additions & 1 deletion app.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    import * as Lib from 'lib';

    console.log('APP');
    console.log(Lib);
    console.log(Lib);

    console.log(Lib.capitalize('hello world'));
    8 changes: 8 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <!doctype html>
    <title>test split lib and app</title>
    <meta charset="utf-8">

    <main></main>

    <script src="build/lib.js"></script>
    <script src="build/app.js"></script>
    4 changes: 2 additions & 2 deletions lib.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // used as entry point to build the common lib
    console.log('LIB ENTRY POINT');

    import { a, b } from 'lib';
    import capitalize from 'string-capitalize';

    export default { a, b };
    export default { capitalize };
    4 changes: 3 additions & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,9 @@
    },
    "author": "Enrique Erne",
    "license": "MIT",
    "dependencies": {},
    "dependencies": {
    "string-capitalize": "^1.0.1"
    },
    "devDependencies": {
    "babel-cli": "^6.3.17",
    "babel-eslint": "^4.1.6",
  2. tcme revised this gist Jan 17, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,6 @@
    intentionally not using .babelrc

    ```
    npm i
    npm start
    ```
  3. tcme revised this gist Jan 17, 2016. No changes.
  4. tcme created this gist Jan 17, 2016.
    4 changes: 4 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    import * as Lib from 'lib';

    console.log('APP');
    console.log(Lib);
    6 changes: 6 additions & 0 deletions lib.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    // used as entry point to build the common lib
    console.log('LIB ENTRY POINT');

    import { a, b } from 'lib';

    export default { a, b };
    22 changes: 22 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    {
    "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"
    }
    }
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    intentionally not using .babelrc
    24 changes: 24 additions & 0 deletions rollup.app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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) );
    24 changes: 24 additions & 0 deletions rollup.lib.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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) );