refactor webpack config

This commit is contained in:
uwap 2018-06-19 12:35:10 +02:00
parent 2d97ae4239
commit 8a37cf2c95
9 changed files with 31 additions and 131 deletions

50
webpack.config.js Normal file
View file

@ -0,0 +1,50 @@
const path = require('path');
const webpack = require('webpack');
const WebpackShellPlugin = require('webpack-shell-plugin');
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 === true) {
throw "No config file was provided.";
}
return path.resolve(__dirname, `config/${env}`);
};
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'
}
},
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)$/, loader: "file-loader" },
{ test: /\.js(x)?$/, exclude: /node_modules/, loader: "babel-loader?cacheDirectory=true" }
]
},
plugins: [
new CleanWebpackPlugin(["dist"]),
new WebpackShellPlugin({onBuildStart:preBuildScripts}),
new HtmlWebpackPlugin({
title: 'Space Map',
template: 'index.ejs'
}),
]
});