2017-02-09 11:45:42 +00:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const copyPlugin = require("copy-webpack-plugin");
|
2017-02-09 17:48:36 +00:00
|
|
|
const duplicatePlugin = require("./webpack-duplicates");
|
2017-02-09 11:45:42 +00:00
|
|
|
const htmlPlugin = require("html-webpack-plugin");
|
|
|
|
const ngAnnotatePlugin = require("ng-annotate-webpack-plugin");
|
2017-02-09 18:58:48 +00:00
|
|
|
const path = require("path");
|
2017-02-09 11:45:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
const depLoaders = {
|
2017-02-09 18:58:48 +00:00
|
|
|
jquery: "expose-loader?jQuery",
|
2017-04-28 00:17:30 +00:00
|
|
|
angular: "exports-loader?window.angular",
|
|
|
|
"leaflet.elevation": [
|
|
|
|
"imports-loader?d3=d3",
|
|
|
|
"string-replace-loader?search=L.Browser.touch&replace=L.Browser.mobile" // https://github.com/MrMufflon/Leaflet.Elevation/issues/67
|
|
|
|
]
|
2017-02-09 11:45:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add imports to these modules, as they don't specify their imports properly
|
|
|
|
const addDeps = {
|
|
|
|
"angular-ui-sortable": [ "jquery-ui", "jquery-ui/ui/widgets/sortable" ],
|
|
|
|
|
|
|
|
// Until https://github.com/webpack-contrib/css-loader/issues/51 is resolved we have to include CSS files by hand
|
|
|
|
bootstrap: [ "bootstrap/dist/css/bootstrap.css", "bootstrap/dist/css/bootstrap-theme.css" ],
|
|
|
|
"leaflet-simple-graticule": [ "leaflet-simple-graticule/L.SimpleGraticule.css" ],
|
|
|
|
"bootstrap-touchspin": [ "bootstrap-touchspin/dist/jquery.bootstrap-touchspin.css" ],
|
|
|
|
leaflet: [ "leaflet/dist/leaflet.css" ],
|
2017-02-26 15:26:22 +00:00
|
|
|
"leaflet.locatecontrol": [ "leaflet.locatecontrol/dist/L.Control.Locate.css" ],
|
2017-04-28 00:17:30 +00:00
|
|
|
"leaflet.markercluster": [ "leaflet.markercluster/dist/MarkerCluster.css", "leaflet.markercluster/dist/MarkerCluster.Default.css" ],
|
2017-05-27 20:25:01 +00:00
|
|
|
"leaflet.elevation": [ require.resolve("leaflet.elevation/dist/Leaflet.Elevation-0.0.2.css") ],
|
2017-05-27 22:24:40 +00:00
|
|
|
"leaflet-mouse-position": [ "leaflet-mouse-position/src/L.Control.MousePosition.css" ],
|
|
|
|
"leaflet-graphicscale": [ "leaflet-graphicscale/src/Leaflet.GraphicScale.scss" ]
|
2017-02-09 11:45:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for(let i in addDeps) {
|
|
|
|
let thisDep = `imports-loader?${addDeps[i].map((dep, i) => `fmImport${i}=${dep}`).join(",")}`;
|
|
|
|
if(depLoaders[i]) {
|
|
|
|
depLoaders[i] = [thisDep, ...(Array.isArray(depLoaders[i]) ? depLoaders[i] : [ depLoaders[i] ])];
|
|
|
|
} else {
|
|
|
|
depLoaders[i] = thisDep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2017-03-01 19:02:57 +00:00
|
|
|
entry: {
|
|
|
|
index: __dirname + "/index/index.js",
|
|
|
|
table: __dirname + "/table/table.js"
|
|
|
|
},
|
2017-02-09 11:45:42 +00:00
|
|
|
output: {
|
2017-03-01 19:02:57 +00:00
|
|
|
filename: "frontend-[name]-[hash].js",
|
2017-02-09 11:45:42 +00:00
|
|
|
path: __dirname + "/build/"
|
|
|
|
},
|
2017-02-09 18:58:48 +00:00
|
|
|
resolve: {
|
2017-02-09 19:39:42 +00:00
|
|
|
unsafeCache: true,
|
2017-02-09 18:58:48 +00:00
|
|
|
alias: {
|
2017-04-28 00:17:30 +00:00
|
|
|
angular: "angular/angular", // We cannot use the main file, as it exports the variable "angular", which clashes with this ProvidePlugin
|
|
|
|
"leaflet.elevation": "leaflet.elevation/dist/Leaflet.Elevation-0.0.2.src.js"
|
2017-02-09 18:58:48 +00:00
|
|
|
}
|
|
|
|
},
|
2017-02-09 11:45:42 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{ test: /\.css$/, use: [ "style-loader", "css-loader" ] },
|
2017-05-11 23:29:49 +00:00
|
|
|
{ test: /\.scss$/, use: [ "style-loader", "css-loader", "sass-loader" ]},
|
2017-02-09 11:45:42 +00:00
|
|
|
{ test: /\.js$/, exclude: /\/node_modules\//, loader: "babel-loader?presets=es2015" },
|
|
|
|
{ test: /\.(png|jpe?g|gif|ttf)$/, loader: "url-loader" },
|
2017-02-10 11:12:47 +00:00
|
|
|
{ test: /\.(html|ejs)$/, loader: "html-loader?attrs[]=img:src&attrs[]=link:href" },
|
2017-02-09 11:45:42 +00:00
|
|
|
...Object.keys(depLoaders).map(key => ({ test: new RegExp("/node_modules/" + key + "/.*\.js$"), [Array.isArray(depLoaders[key]) ? "use" : "loader"]: depLoaders[key] })),
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\/node_modules\/bootstrap\/dist\/css\/bootstrap\.css$/,
|
|
|
|
loader: "string-replace-loader",
|
|
|
|
options: {
|
|
|
|
multiple: [
|
|
|
|
{ search: "src: url\\('\\.\\./fonts/glyphicons-halflings-regular.eot'\\);", replace: "", flags: "" },
|
|
|
|
{ search: "src: url\\('\\.\\./fonts/glyphicons-halflings-regular\\..*", replace: "src: url('../fonts/glyphicons-halflings-regular.ttf') format('truetype');", flags: "" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2017-02-09 17:48:36 +00:00
|
|
|
new duplicatePlugin(),
|
2017-02-09 11:45:42 +00:00
|
|
|
new ngAnnotatePlugin({
|
|
|
|
add: true
|
|
|
|
}),
|
|
|
|
new htmlPlugin({
|
2017-02-10 11:12:47 +00:00
|
|
|
template: `${__dirname}/index/index.ejs`,
|
2017-03-01 19:02:57 +00:00
|
|
|
filename: "index.ejs",
|
|
|
|
chunks: ["index"]
|
|
|
|
}),
|
|
|
|
new htmlPlugin({
|
|
|
|
template: `${__dirname}/table/table.ejs`,
|
|
|
|
filename: "table.ejs",
|
|
|
|
chunks: ["table"]
|
2017-02-09 11:45:42 +00:00
|
|
|
}),
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
$: "jquery",
|
|
|
|
jQuery: "jquery",
|
|
|
|
"window.jQuery": "jquery",
|
|
|
|
L: "leaflet",
|
2017-02-09 18:58:48 +00:00
|
|
|
angular: "angular"
|
2017-02-09 11:45:42 +00:00
|
|
|
}),
|
2017-03-01 18:52:50 +00:00
|
|
|
new copyPlugin([ "deref.html", "opensearch.xml" ].map((file) => ({ from: `${__dirname}/static/${file}` }))),
|
2017-05-11 02:21:04 +00:00
|
|
|
...(!process.env.FM_DEV ? [
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
sourceMap: true
|
|
|
|
})
|
|
|
|
] : [ ]),
|
2017-02-09 11:45:42 +00:00
|
|
|
],
|
|
|
|
};
|
2017-05-11 02:21:04 +00:00
|
|
|
|
|
|
|
if(!process.env.FM_DEV)
|
|
|
|
module.exports.devtool = "source-map";
|