Skip to content

Instantly share code, notes, and snippets.

@maiha
Last active December 12, 2018 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maiha/0d2fb1e1e95ea2385204a77e688775c3 to your computer and use it in GitHub Desktop.
Save maiha/0d2fb1e1e95ea2385204a77e688775c3 to your computer and use it in GitHub Desktop.

merge multiple private libraies into one js

  • webpack-3.12.0

config

  entry: {
    'main.bundle.js': './src/assets/javascripts/main.js'
  },
  output: {
    filename: '[name]',
    path: path.resolve(__dirname, '../../public/dist'),
    publicPath: '/dist'
  },

private lib 1

function foo() {
}
module.exports = foo;

private lib 2

function bar() {
}
module.exports = bar;

main.js

import foo from './lib1.js'
import bar from './lib2.js'

if (!window.foo) { window.foo = foo; }
if (!window.bar) { window.bar = bar; }

consumer

<script src="/dist/main.bundle.js"></script>
<script>
  window.foo();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment