Webpack code spliting and map marker style fix

This commit is contained in:
Matteo Gheza 2020-10-07 22:49:51 +02:00
parent 235bbb788f
commit e0f5a75b2a
6 changed files with 46 additions and 21 deletions

View File

@ -7,6 +7,7 @@ init_class(false);
<title>Location picker example</title>
<script src="resources/dist/main.js"></script>
<script src="resources/dist/maps.js"></script>
</head>
<body>
<style>
@ -55,7 +56,7 @@ function load_map() {
}
});
var lc = new L.Control.CustomLocate({ flyTo: true, icon: "fa fa-map-marker-alt", drawCircle: false }).addTo(map);
var lc = new L.Control.CustomLocate({ icon: "fa fa-map-marker" }).addTo(map);
}
function chooseAddr(lat1, lng1, lat2, lng2, osm_type, lat, lng) {
@ -63,6 +64,7 @@ function chooseAddr(lat1, lng1, lat2, lng2, osm_type, lat, lng) {
var loc2 = new L.LatLng(lat2, lng2);
var bounds = new L.LatLngBounds(loc1, loc2);
console.log(lat1, lng1, lat2, lng2, osm_type);
set_marker(new L.LatLng(lat, lng));
if (feature) {
map.removeLayer(feature);
}
@ -75,7 +77,6 @@ function chooseAddr(lat1, lng1, lat2, lng2, osm_type, lat, lng) {
feature = L.polyline( [loc1, loc4, loc2, loc3, loc1], {color: 'red'}).addTo(map);
map.fitBounds(bounds);
}
set_marker(new L.LatLng(lat, lng));
}
function addr_search() {
@ -130,6 +131,13 @@ div#results {
color: black;
font-size: 75%;
}
.fa {
vertical-align: middle;
font-size: 25px;
}
.leaflet-pane.leaflet-shadow-pane {
display: none;
}
</style>
</body>
</html>

View File

@ -79,7 +79,7 @@ th, td {
<td><a href='tel:+" . $row['telefono'] . "'><i class='fa fa-phone'></i></a></td><td>";
$nome_url = urlencode($row['name']);
echo " <a href='https://api.whatsapp.com/send?phone=" . $row['telefono'] . "&text=ALLERTA IN CORSO.%20Mettiti%20in%20contatto%20con%20$nome_url'><i class='fab fa-whatsapp' style='color:green'></i></td>";
echo " <a href='https://api.whatsapp.com/send?phone=" . $row['telefono'] . "&text=ALLERTA IN CORSO.%20Mettiti%20in%20contatto%20con%20$nome_url'><i class='fa fa-whatsapp' style='color:green'></i></td>";
$services = $row['services'];
$minutes = $row['availability_minutes'];

View File

@ -0,0 +1,2 @@
$fa-font-path: "~font-awesome/fonts";
@import '~font-awesome/scss/font-awesome.scss';

View File

@ -1,23 +1,11 @@
jQuery = $;
window.$ = window.jQuery = $;
import 'bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
import '../node_modules/@fortawesome/fontawesome-free/css/all.css';
import '../node_modules/@fortawesome/fontawesome-free/js/all.js'; // thanks to https://medium.com/@bshelling/use-fontawesome-with-webpack-24f629d7b962 and https://stackoverflow.com/questions/52376720/how-to-make-font-awesome-5-work-with-webpack
import './font-awesome.scss';
import '../node_modules/bootstrap-cookie-alert/cookiealert.css'; // TODO: migrate to Bootstrap Italia
import pickadate from 'pickadate'
import L from 'leaflet';
import 'leaflet.locatecontrol';
import '../node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.css'
import '../node_modules/leaflet/dist/leaflet.css';
delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
iconRetinaUrl: 'resources/dist/marker-icon-2x.png',
iconUrl: 'resources/dist/marker-icon.png',
shadowUrl: 'resources/dist/marker-shadow.png',
});
$( document ).ready(function() {
// From https://github.com/Wruczek/Bootstrap-Cookie-Alert/blob/gh-pages/cookiealert.js
var cookieAlert = document.querySelector(".cookiealert");

View File

@ -0,0 +1,11 @@
import L from 'leaflet';
import 'leaflet.locatecontrol';
import '../node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.css'
import '../node_modules/leaflet/dist/leaflet.css';
delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
iconRetinaUrl: 'resources/dist/marker-icon-2x.png',
iconUrl: 'resources/dist/marker-icon.png',
shadowUrl: 'resources/dist/marker-shadow.png',
});

View File

@ -3,9 +3,12 @@ var webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry: './src/src.js',
entry: {
main: path.resolve(__dirname, './src/main.js'),
maps: path.resolve(__dirname, 'src/maps.js')
},
output: {
filename: 'main.js',
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
module: {
@ -33,7 +36,7 @@ module.exports = {
},
},
{
test: /\.(woff(2)?|ttf|eot|svg|png|jpg)(\?v=\d+\.\d+\.\d+)?$/,
test: /\.(gif|png|jpg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
@ -43,15 +46,28 @@ module.exports = {
}
}
]
},
{
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/', // where the fonts will go
publicPath: 'resources/dist/fonts' // override the default path
}
}]
}
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
popper: 'popper.js'
}),
],
optimization: {
mergeDuplicateChunks: true
},
};