Skip to content
Share modules between webpack applications
Branch: master
Clone or download
MrFrankel
Latest commit f5218e8 Mar 7, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example-cli revert path Mar 5, 2019
example
.gitattributes first commit Feb 15, 2018
.gitignore
.npmignore
README.md
index.js
package-lock.json
package.json

README.md

npm npm MIT licensed

Share Loader

The share loader allows you to share modules between webpack builds via a global namespace

Install

npm i share-loader --save-dev

Or

yarn add share-loader --save-dev

Usage

webpack config of exposing app

module: {
  rules: [{
          test: /\.js?$/,
          use: [{
            loader: 'share-loader',
            options: {
              modules: [/@angular/, /@uirouter\/angular/],
              exclude: [/@angular\/material/],
              namespace: 'some-name-space'
            }
          }]
        }]
}

webpack config of consumer apps

const {Externals} = require('./share-loader');

externals: [
  Externals({
    namespace: 'some-name-space',
    modules: [/@angular/, /@uirouter\/angular/]
  })
],
output: {
  library: 'some-name-space',
  libraryTarget: 'umd'
}


Example

1. In the example folder, run npm install on each project,
2. Run npm run build:prod in the ext-app-1 root
2. Host the ext1.js file from ext-app-1 project in some localhost server
3. Change the <%path-to-server-host%> in the shell project app.state.ts
4. Run npm run serve:dev in the shell project root



Example-cli
1. In the example folder, run npm install on each project,
2. Run npm run ng run ext-app1:build-ext in the ext-app1 root
2. Host the main.js file from ext-app1 project in some localhost server
3. Change the <%path-to-server-host%> in the shell project app.state.ts
4. Run ng serve in the shell project root
5. You can also run ext-app1 in standalone mode with ng serve
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.