From d188cc5ede25c4f4f2bf23f95e782d32a1c2df0d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 1 Feb 2018 10:42:54 -0500 Subject: [PATCH] add pkg.module (#6021) * add pkg.module version * get tests to pass * export noConflict --- build/rollup-config.js | 35 +++++++++++++++++++++++++++-------- package.json | 1 + spec/karma.conf.js | 12 +++++++++++- src/Leaflet.js | 11 ----------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/build/rollup-config.js b/build/rollup-config.js index e4ffb2ff3..54f28562f 100644 --- a/build/rollup-config.js +++ b/build/rollup-config.js @@ -3,8 +3,9 @@ import rollupGitVersion from 'rollup-plugin-git-version' import json from 'rollup-plugin-json' import gitRev from 'git-rev-sync' +import pkg from '../package.json' -let version = require('../package.json').version; +let {version} = pkg; let release; // Skip the git branch+rev in the banner when doing a release build @@ -23,15 +24,33 @@ const banner = `/* @preserve */ `; +const outro = `var oldL = window.L; +exports.noConflict = function() { + window.L = oldL; + return this; +} + +// Always export us to window global (see #2364) +window.L = exports;`; + export default { input: 'src/Leaflet.js', - output: { - file: 'dist/leaflet-src.js', - format: 'umd', - name: 'L', - banner: banner, - sourcemap: true - }, + output: [ + { + file: pkg.main, + format: 'umd', + name: 'L', + banner: banner, + outro: outro, + sourcemap: true + }, + { + file: pkg.module, + format: 'es', + banner: banner, + sourcemap: true + } + ], legacy: true, // Needed to create files loadable by IE8 plugins: [ release ? json() : rollupGitVersion() diff --git a/package.json b/package.json index ba662839f..8121fa244 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "uglify-js": "~3.0.26" }, "main": "dist/leaflet-src.js", + "module": "dist/leaflet-src.esm.js", "style": "dist/leaflet.css", "files": [ "dist", diff --git a/spec/karma.conf.js b/spec/karma.conf.js index ea5aa8ebf..b6a25fff7 100644 --- a/spec/karma.conf.js +++ b/spec/karma.conf.js @@ -1,5 +1,14 @@ var json = require('rollup-plugin-json'); +const outro = `var oldL = window.L; +exports.noConflict = function() { + window.L = oldL; + return this; +} + +// Always export us to window global (see #2364) +window.L = exports;`; + // Karma configuration module.exports = function (config) { @@ -50,7 +59,8 @@ module.exports = function (config) { json() ], format: 'umd', - name: 'L' + name: 'L', + outro: outro }, // test results reporter to use diff --git a/src/Leaflet.js b/src/Leaflet.js index 1337f07e6..2b1845027 100644 --- a/src/Leaflet.js +++ b/src/Leaflet.js @@ -23,16 +23,5 @@ export * from './layer/index'; // map export * from './map/index'; -// misc - -var oldL = window.L; -export function noConflict() { - window.L = oldL; - return this; -} - -// Always export us to window global (see #2364) -window.L = exports; - import {freeze} from './core/Util'; Object.freeze = freeze;