Skip to content

Instantly share code, notes, and snippets.

@jstrimpel
Last active March 16, 2018 19:27
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 jstrimpel/cff7382a9e99f99a89b59cf31ff6047f to your computer and use it in GitHub Desktop.
Save jstrimpel/cff7382a9e99f99a89b59cf31ff6047f to your computer and use it in GitHub Desktop.
Is it possible to have separate build processes that generate bundles that define dependencies, which can be used by an application without having to expose globals and rely on aliases?

Is it possible to have separate build processes that generate bundles that define dependencies, which can be used by an application without having to expose globals and rely on aliases?

Requirement

There are two separate build processes:

  • Core: This builds a distribution of common core dependencies
  • Component: This externalizes anything in core build

Use Case

The following two files are entry points for two different build processes. The component entry webpack config defines core as an external.

Core build entry

// core.js
export default () => {
  console.log('i am core');
}

Component build entry

import core from 'core';
core();

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>Example</title>
  </head>
  <body>
  </body>
  <script type="text/javascript" src="./dist/core.js"></script>
  <script type="text/javascript" src="./dist/index.js"></script>
</html>

Issue

The example above throws because core is undefined. This is because core.js and index.js do not share a common build process. As such standard code splitting techniques, CommonsChunkPlugin, splitChunks, and Dll(Reference)Plugin solution do not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment