60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
const path = require('path');
|
|
const webpack = require('webpack');
|
|
const WebpackShellPlugin = require('webpack-shell-plugin-next');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
const preBuildScripts = process.env.NO_FLOW == undefined ?
|
|
process.env.FLOW_PATH != undefined ? [process.env.FLOW_PATH] : ['flow']
|
|
: [];
|
|
|
|
const configPath = env => {
|
|
if (env.length < 3) {
|
|
throw "No config file was provided.";
|
|
}
|
|
return path.resolve(__dirname, `config/${Object.keys(env)[2]}`);
|
|
};
|
|
|
|
module.exports = env => ({
|
|
entry: {
|
|
main: [configPath(env),
|
|
path.resolve(__dirname, 'src/index.jsx')]
|
|
},
|
|
resolve: {
|
|
modules: [path.resolve(__dirname, "src"), "node_modules"],
|
|
extensions: ['.js', '.jsx'],
|
|
alias: {
|
|
'lodash': 'lodash-es',
|
|
"leaflet": "leaflet/dist/leaflet-src.esm.js"
|
|
},
|
|
},
|
|
output: {
|
|
path: path.resolve(__dirname, 'dist'),
|
|
filename: '[name]-[chunkhash].js'
|
|
},
|
|
module: {
|
|
rules: [
|
|
// TODO: CSS follow imports and minify + sourcemap on production
|
|
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ] },
|
|
{ test: /\.(woff2?|eot|ttf|svg|png)$/, use: [ { loader: "file-loader", options: { esModule: false } } ] },
|
|
{ test: /\.js(x)?$/, use: ["babel-loader?cacheDirectory=true"] }
|
|
]
|
|
},
|
|
plugins: [
|
|
new CleanWebpackPlugin(),
|
|
new WebpackShellPlugin({
|
|
onBuildStart: {
|
|
scripts: preBuildScripts,
|
|
blocking: true,
|
|
parallel: false
|
|
}
|
|
}),
|
|
new HtmlWebpackPlugin({
|
|
title: 'Space Map',
|
|
template: 'index.ejs'
|
|
}),
|
|
new webpack.ProvidePlugin({
|
|
Buffer: ['buffer', 'Buffer'],
|
|
process: 'process/browser',
|
|
}),
|
|
]
|
|
});
|