homepage-frontend/webpack.config.js

159 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-07-23 12:31:29 +00:00
const path = require("path")
const webpack = require("webpack")
const port = parseInt(process.env.PORT) || 5000
/************************************************************/
/* Base configuration */
/************************************************************/
2017-07-23 12:31:29 +00:00
const baseConfig = {
output: {
path: path.resolve(__dirname, "./build"),
filename: "[name].bundle.js",
sourceMapFilename: "[file].map"
},
2018-01-21 15:52:21 +00:00
externals: [ "express", "ejs" ],
2017-07-23 12:31:29 +00:00
module: {
rules: [
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, "./src")
],
loader: "babel-loader"
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
2018-10-20 14:29:39 +00:00
loader: "url-loader",
2017-07-23 12:31:29 +00:00
options: {
2018-10-23 19:56:42 +00:00
limit: 1000
2017-07-23 12:31:29 +00:00
}
}
]
},
{
test: /\.html$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]"
}
}
]
2018-02-08 21:07:38 +00:00
},
{
test: /.asc$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].asc"
}
}
]
},
{
test: /.less$/,
use: [
{
loader: "css-loader"
},
{
loader: "less-loader"
}
]
2017-07-23 12:31:29 +00:00
}
]
2017-07-23 15:24:59 +00:00
}
}
/************************************************************/
/* Targets */
/************************************************************/
//This will be the script which is included in the index.html
2017-07-23 15:24:59 +00:00
const runtime = () => Object.assign({ }, baseConfig, {
2017-07-28 21:03:26 +00:00
target: "web",
2017-07-23 15:24:59 +00:00
entry: {
runtime: path.resolve("src/runtime.js")
},
output: {
path: path.resolve("build/static"),
filename: "[name].bundle.js",
sourceMapFilename: "[file].map"
}
})
//This target will be exposed by this package, that either node
//or browser applications can require it.
2017-07-23 15:24:59 +00:00
const index = () => Object.assign({ }, baseConfig, {
target: "node",
entry: {
index: path.resolve("src/index.js")
2017-07-23 12:31:29 +00:00
},
2017-07-23 15:24:59 +00:00
output: {
path: path.resolve("build"),
2017-07-29 08:34:15 +00:00
filename: "index.js",
sourceMapFilename: "index.map",
2018-01-19 00:38:50 +00:00
libraryTarget: "umd",
library: "homepage"
2017-07-28 21:03:26 +00:00
},
node: {
__dirname: false,
2018-10-20 14:29:39 +00:00
__filename: false
2017-07-23 15:24:59 +00:00
}
})
/************************************************************/
/* Decorators */
/************************************************************/
//extend the configuration by all production settings
2017-07-23 15:24:59 +00:00
const production = config => Object.assign({ }, config(), {
2018-10-20 14:29:39 +00:00
mode: "production",
2017-07-23 12:31:29 +00:00
plugins: [
2017-07-28 21:03:26 +00:00
new webpack.DefinePlugin({
2018-10-20 14:29:39 +00:00
"process.env.NODE_ENV": JSON.stringify("production")
})
2017-07-23 12:31:29 +00:00
]
2017-07-23 15:24:59 +00:00
})
2017-07-23 12:31:29 +00:00
//extend the configuration by all development settings
2017-07-23 15:24:59 +00:00
const development = config => Object.assign({ }, config(), {
2018-10-20 14:29:39 +00:00
mode: "development",
2017-07-23 12:31:29 +00:00
devServer: {
historyApiFallback: true,
2018-10-20 14:29:39 +00:00
stats: "errors-only",
2017-07-23 12:31:29 +00:00
host: process.env.HOST,
port,
2017-07-23 12:31:29 +00:00
compress: true,
overlay: true,
hot: true,
2019-02-20 14:33:44 +00:00
contentBase: path.resolve(__dirname, "build/static"),
proxy: {
"/api": {
"target": "https://localhost:6000",
secure: false
}
}
2017-07-23 15:24:59 +00:00
},
devtool: "source-map",
plugins: [
new webpack.HotModuleReplacementPlugin()
2017-07-23 15:24:59 +00:00
]
2017-07-23 12:31:29 +00:00
})
//choose according to environment
2017-07-23 12:31:29 +00:00
module.exports = env => {
2018-10-20 14:29:39 +00:00
if (env === "production") {
return [ production(index), production(runtime) ]
2017-08-02 20:54:02 +00:00
} else {
2018-10-20 14:29:39 +00:00
return [ development(runtime) ]
2017-07-23 12:31:29 +00:00
}
}