Skip to content

Commit 703ae02

Browse files
mournerIvanSanchez
authored andcommitted
ES6 modules & Rollup (Leaflet#4989)
* WIP ES6 modules & rollup * WIP ES6 modules & rollup 2 * WIP ES6 modules & rollup 3 * WIP ES6 modules Browser * WIP ES6 module fixes * WIP ES6 modules: simpler browser exports * WIP ES6: refactor CRS/Projection modules, CRS obj -> CRS.Base * get rid of unnecessary index.js * WIP ES6 modules, dom events and stuff * Make linter happy, rollup to dist/ * revert to CRS namespace/class for now * WIP rollup: export more stuff * export controls * rollup: export Layer * rollup: export DomEvent * rollup: export more layer types * rollup: export Popup/Tooltip * WIP: ES6-ify marker, icon, domutil, draggable. * ES6-ify gridlayer, tilelayer. * ES6-ify: Tweak imports-exports, code is now runnable!! * ES6-ify: Fix scope in some DomUtils * ES6-ify: Path, fix Popup * ES6-ify: Lint & cleanup * ES6-ify map handlers, more linting * ES6-ify: Icon.Default namespacing * ES6-ify: Renderers, CircleMarker * ES6-ify: Circle, Polyline, LineUtil * ES6-ify: Polygon, Rectangle, LineUtil, PolyUtil, linting * ES6-ify: SVG.VML * ES6-ify: DomEvent.Pointer, DomEvent.DoubleTap * ES6-ify: Linting, make Karma play nice with Rollup * ES6-ify: More work on fixing bits breaking some unit tests. * ES6-ify: rollup the version number, fiddled with build scripts * ES6-ify: Fiddle with test scripts * ES6-ify: cleanup (refs to global L, imports from (DOM)Util), prevent cyclic loop on Map imports * ES6-ify: More cleanup of (DOM)Util/Browser/DomEvent imports * ES6ify: Use rollup's "legacy" option for ES3 (IE8) builds * ES6-ify: Clean up build scripts, fix CONTRIBUTING.md instructions * Typo * ES6-ify: minor fixes and lefovers after rebasing on top of 1.0.2 * ES6-ify: upgrade to rollup 0.38 for proper IE8 builds, fix L.SVG.VML * Make linter happy. * ES6: Fixing typos and sxrew-ups after big rebase * Fix symlink for debugging scripts * ES6: Cleanup old build scripts * ES6-ify: Update build system to include git rev in L.version * ES6-ify: re-enable unit tests replacing L.Path with L.Polyline * Export Path * ES6ify: cleanup old banner file * ES6-ify: whitespace in var declarations * ES6-ify: Export toTransformation as L.transformation * ES6-ify: cleanup L.transform exports * ES6-ify: "import Util" in Transformation and SVG.VML
1 parent 3ac37c2 commit 703ae02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3255
-3307
lines changed

CONTRIBUTING.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ To set up the Leaflet build system, install Node then run the following commands
7272
npm install -g jake
7373
npm install
7474
```
75-
76-
You can build minified Leaflet by running `jake` (it will be built from source in the `dist` folder).
77-
For a custom build with selected components, open `build/build.html` in the browser and follow the instructions from there.
75+
or, if you prefer [`yarn`](https://yarnpkg.com/) over `npm`:
76+
```
77+
yarn install -g jake
78+
yarn install
79+
```
7880

7981
### Making Changes to Leaflet Source
8082

@@ -96,6 +98,25 @@ Also, please make sure that you have [line endings configured properly](https://
9698

9799
Happy coding!
98100

101+
### Using RollupJS
102+
103+
The source javascript code for Leaflet is a few dozen files, in the `src/` directory.
104+
But normally, Leaflet is loaded in a web browser as just one javascript file.
105+
106+
In order to create this file, run `npm run-script rollup` or `yarn run rollup`.
107+
108+
You'll find `dist/leaflet-src.js` and `dist/leaflet.js`. The difference is that
109+
`dist/leaflet-src.js` has sourcemaps and it's not uglified, so it's better for
110+
development. `dist/leaflet.js` is uglified and thus is smaller, so it's better
111+
for deployment.
112+
113+
When developing (or bugfixing) core Leaflet functionalities, it's common to use
114+
the webpages in the `debug/` directory, and run the unit tests (`spec/index.html`)
115+
in a graphical browser. This requires regenerating the bundled files quickly.
116+
117+
In order to do so, run `npm run-script watch` or `yarn run rollup`. This will keep
118+
on rebuilding the bundles whenever any source file changes.
119+
99120
## Running the Tests
100121

101122
To run the tests from the command line,
@@ -158,7 +179,8 @@ code for every method, option or property there is a special code comment docume
158179
that feature. In order to edit the API documentation, just edit these comments in the
159180
source code.
160181

161-
In order to generate the documentation, just run
182+
In order to generate the documentation, make sure that the development dependencies
183+
are installed (run either `npm install` or `yarn install`), then just run
162184

163185
```
164186
jake docs

Jakefile.js

+51-16
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ To run the tests, run "jake test". To build the documentation, run "jake docs".
1212
For a custom build, open build/build.html in the browser and follow the instructions.
1313
*/
1414

15-
var build = require('./build/build.js'),
16-
buildDocs = require('./build/docs'),
17-
git = require('git-rev');
15+
var buildDocs = require('./build/docs'),
16+
git = require('git-rev-sync'),
17+
path = require('path');
1818

1919
function hint(msg, args) {
2020
return function () {
@@ -29,16 +29,14 @@ function hint(msg, args) {
2929

3030
// Returns the version string in package.json, plus a semver build metadata if
3131
// this is not an official release
32-
function calculateVersion(officialRelease, callback) {
32+
function calculateVersion(officialRelease) {
3333

3434
var version = require('./package.json').version;
3535

3636
if (officialRelease) {
37-
callback(version);
37+
return version;
3838
} else {
39-
git.short(function(str) {
40-
callback (version + '+' + str);
41-
});
39+
return version + '+' + git.short();
4240
}
4341
}
4442

@@ -48,16 +46,53 @@ task('lint', {async: true}, hint('Checking for JS errors...', 'src'));
4846
desc('Check Leaflet specs source for errors with ESLint');
4947
task('lintspec', {async: true}, hint('Checking for specs JS errors...', 'spec/suites'));
5048

51-
desc('Combine and compress Leaflet source files');
52-
task('build', {async: true}, function (compsBase32, buildName, officialRelease) {
53-
calculateVersion(officialRelease, function(v){
54-
build.build(complete, v, compsBase32, buildName);
55-
});
56-
});
57-
5849
desc('Run PhantomJS tests');
5950
task('test', ['lint', 'lintspec'], {async: true}, function () {
60-
build.test(complete);
51+
52+
var karma = require('karma'),
53+
testConfig = {configFile : path.join(__dirname, './spec/karma.conf.js')};
54+
55+
testConfig.browsers = ['PhantomJSCustom'];
56+
57+
function isArgv(optName) {
58+
return process.argv.indexOf(optName) !== -1;
59+
}
60+
61+
if (isArgv('--chrome')) {
62+
testConfig.browsers.push('Chrome');
63+
}
64+
if (isArgv('--safari')) {
65+
testConfig.browsers.push('Safari');
66+
}
67+
if (isArgv('--ff')) {
68+
testConfig.browsers.push('Firefox');
69+
}
70+
if (isArgv('--ie')) {
71+
testConfig.browsers.push('IE');
72+
}
73+
74+
if (isArgv('--cov')) {
75+
testConfig.preprocessors = {
76+
'src/**/*.js': 'coverage'
77+
};
78+
testConfig.coverageReporter = {
79+
type : 'html',
80+
dir : 'coverage/'
81+
};
82+
testConfig.reporters = ['coverage'];
83+
}
84+
85+
console.log('Running tests...');
86+
87+
var server = new karma.Server(testConfig, function(exitCode) {
88+
if (!exitCode) {
89+
console.log('\tTests ran successfully.\n');
90+
complete();
91+
} else {
92+
process.exit(exitCode);
93+
}
94+
});
95+
server.start();
6196
});
6297

6398
desc('Build documentation');

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dist/leaflet.css",
77
"dist/leaflet-src.js"
88
],
9-
"ignore": [
9+
"ignore": [
1010
".*",
1111
"CHANGELOG.json",
1212
"FAQ.md",

build/build.html

-227
This file was deleted.

0 commit comments

Comments
 (0)