Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use inline SVGs and refresh CSS #8884

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions build/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @flow
/* eslint-disable import/no-commonjs */

require('@mapbox/flow-remove-types/register');

const fs = require('fs');

function loadFile(module, filename) {
const content = fs.readFileSync(filename, 'utf8');
module._compile(`module.exports = ${JSON.stringify(content)};`, filename);
}

// $FlowFixMe: Flow doesn't know about require.extensions
require.extensions['.svg'] = loadFile;

// $FlowFixMe: Flow doesn't know about require.extensions
require.extensions['.glsl'] = loadFile;
15 changes: 13 additions & 2 deletions build/rollup_plugins.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

/* eslint-disable flowtype/require-valid-file-annotation */
import flowRemoveTypes from '@mapbox/flow-remove-types';
import buble from 'rollup-plugin-buble';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import unassert from 'rollup-plugin-unassert';
import json from 'rollup-plugin-json';
import { terser } from 'rollup-plugin-terser';
import svgo from 'rollup-plugin-svgo';
import {terser} from 'rollup-plugin-terser';
import minifyStyleSpec from './rollup_plugin_minify_style_spec';
import { createFilter } from 'rollup-pluginutils';
import {createFilter} from 'rollup-pluginutils';

// Common set of plugins/transformations shared across different rollup
// builds (main mapboxgl bundle, style-spec package, benchmarks bundle)
Expand All @@ -17,6 +19,15 @@ export const plugins = (minified, production) => [
minifyStyleSpec(),
json(),
glsl('./src/shaders/*.glsl', production),
svgo({
plugins: [{
removeViewBox: false
}, {
removeDimensions: false
}, {
cleanupIDs: false
}]
}),
buble({transforms: {dangerousForOf: true}, objectAssign: "Object.assign"}),
minified ? terser() : false,
production ? unassert() : false,
Expand Down
2 changes: 1 addition & 1 deletion build/run-node
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

node -r @mapbox/flow-remove-types/register -r esm ${@}
node -r ./build/loader -r esm ${@}
2 changes: 1 addition & 1 deletion build/run-tap
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ else
arg="${@}"
fi

node_modules/.bin/tap --node-arg -r --node-arg @mapbox/flow-remove-types/register --node-arg -r --node-arg esm $arg --node-arg
node_modules/.bin/tap --node-arg -r --node-arg ./build/loader --node-arg -r --node-arg esm $arg --node-arg
1 change: 1 addition & 0 deletions debug/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
}
}));
map.addControl(new mapboxgl.ScaleControl());
map.addControl(new mapboxgl.FullscreenControl());

map.on('load', function() {
map.addSource('geojson', {
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@mapbox/mapbox-gl-test-suite": "file:test/integration",
"@octokit/rest": "^16.30.1",
"address": "^1.1.2",
"autoprefixer": "^9.6.5",
"babel-eslint": "^10.0.1",
"benchmark": "^2.1.4",
"browserify": "^16.2.3",
Expand Down Expand Up @@ -73,7 +74,7 @@
"pirates": "^4.0.1",
"pngjs": "^3.4.0",
"postcss-cli": "^6.1.2",
"postcss-inline-svg": "^3.1.1",
"postcss-nested": "^4.1.2",
"pretty-bytes": "^5.1.0",
"puppeteer": "^1.18.0",
"qrcode-terminal": "^0.12.0",
Expand All @@ -87,6 +88,7 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-svgo": "^1.1.0",
"rollup-plugin-terser": "^5.1.2",
"rollup-plugin-unassert": "^0.3.0",
"sinon": "^7.3.2",
Expand All @@ -100,7 +102,6 @@
"testem": "^2.17.0"
},
"browser": {
"./src/shaders/index.js": "./src/shaders/shaders.js",
"./src/util/window.js": "./src/util/browser/window.js",
"./src/util/web_worker.js": "./src/util/browser/web_worker.js"
},
Expand Down Expand Up @@ -132,8 +133,8 @@
"test-suite-clean": "find test/integration/{render,query, expressions}-tests -mindepth 2 -type d -exec test -e \"{}/actual.png\" \\; -not \\( -exec test -e \"{}/style.json\" \\; \\) -print | xargs -t rm -r",
"test-unit": "build/run-tap --reporter classic --no-coverage test/unit",
"test-build": "build/run-tap --no-coverage test/build/**/*.test.js",
"test-render": "node --max-old-space-size=2048 test/render.test.js",
"test-query-node": "node test/query.test.js",
"test-render": "build/run-node --max-old-space-size=2048 test/render.test.js",
"test-query-node": "build/run-node test/query.test.js",
"watch-query": "testem -f test/integration/testem.js",
"test-query": "testem ci -f test/integration/testem.js -R xunit > test/integration/query-tests/test-results.xml",
"test-expressions": "build/run-node test/expression.test.js",
Expand Down
9 changes: 7 additions & 2 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-disable import/no-commonjs */
module.exports = {
plugins: [
require('postcss-inline-svg'),
require('postcss-nested'),
require('autoprefixer')({
overrideBrowserslist: [ 'defaults', 'IE 11' ]
}),
require('cssnano')
]
}
};
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable flowtype/require-valid-file-annotation */
import fs from 'fs';
import sourcemaps from 'rollup-plugin-sourcemaps';
import {plugins} from './build/rollup_plugins';
Expand Down
Loading