0

Rewriting an old application and slowly using webpack to wrap pieces as we go. To maintain compatibility with older pieces of the code base there are several functions that are on the global and need to remain accessible as such for some time. I've tried setting the output object library property and this works. However, I end up with my library containing three empty objects (for each entry point). I've looked into the expose-loader plugin and same result. I'm sure it's a lack of understanding on my part, still trying to work through the learning curve. Taken influence from many SO posts on the matter (https://stackoverflow.com/a/39166592/1893557)

 entry: {
        app: './app.js',
        mystc: './mystc/index.js',
        vendor: [
            // 'jquery',
            'angular',
            'angular-aria',
            'angular-animate',
            'angular-messages',
            'angular-sanitize',
            'angular-material',
            'angular-material-data-table',
            'moment',
            'bootstrap',
            'pikaday',
            'timepicker',
            'ng-infinite-scroll',
            'atrament',
            'node-waves',
            'cache-autocomplete'
        ]
    },
    output: {
        // path: __dirname + '/js',
        path: __dirname + '/js-webpack',
        filename: '[name].bundle.js',
        libraryTarget: 'var',
        library: ['GlobalAccess', "[name]"]
    },

enter image description here

In the image ^^^ you'll see the ouput for this config. What is inside the mystc entry point is:

require("./loadtesting");
require("./utilities");
require("./webnotifications");
require("./ajaxclient");
require("./Number");

These files point to many functions that have been exported in their respective files. So these functions are used in many pieces of the app and it would be nice to not have to go rename or fix all the functions being called in the code base for now.

Community
  • 1
  • 1
Brad Martin
  • 5,637
  • 4
  • 28
  • 44

2 Answers2

1

Explicitly declaring the files (modules) in an array for the entry object like this:

testGlobal: ['./home/ajaxclient', './home/loadcore'],

Now I can access the exported functions from the output.library

Brad Martin
  • 5,637
  • 4
  • 28
  • 44
  • After digging around some more, it's actually only exposing the exported functions in the last module in the array to the entry point. – Brad Martin Jan 30 '17 at 16:55
1

Inside ./mystc/index.js not only require-ing but it should be exported too

exports.loadtesting = require("./loadtesting");
exports.utilities = require("./utilities");
exports.webnotifications = require("./webnotifications");
exports.ajaxclient = require("./ajaxclient");
exports.Number = require("./Number");
Marek Maszay
  • 1,537
  • 1
  • 9
  • 11