I am using WebPack 4 to build my TypeScript applications.
One of my modules uses the moment-timezone
library, for example...
import * as moment from 'moment-timezone';
$('#label-locale').text(moment.locale());
and this works as expected.
To make better use of caching, I would like to reference moment
and moment-timezone
from a Content Delivery Network (CDN) and have added the following to my HTML
page:
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data.min.js"></script>
I also modified the webpack.config.js
as follows:
module.exports = {
externals: {
'jquery': 'jQuery',
'moment': 'moment-timezone'
}
};
Now, when I run my code, I get the following error:
ReferenceError: timezone is not defined
I am new to WebPack and have tried things like adding 'timezone': 'moment-timezone'
to the externals
without success.
Any help/direction would be very much appreciated.