homepage-frontend/webpack.config.js

126 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-07-23 12:31:29 +00:00
const path = require("path")
const webpack = require("webpack")
2018-03-02 09:33:58 +00:00
const WebpackNotifierPlugin = require("webpack-notifier")
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: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
},
{
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"
}
}
]
2017-07-23 12:31:29 +00:00
}
]
2017-07-23 15:24:59 +00:00
}
}
// targets
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"
}
})
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,
__filename: false,
2017-07-23 15:24:59 +00:00
}
})
// decorators
const production = config => Object.assign({ }, config(), {
2017-07-23 12:31:29 +00:00
plugins: [
2017-07-28 21:03:26 +00:00
new webpack.DefinePlugin({
2018-01-21 00:21:54 +00:00
"process.env.NODE_ENV": JSON.stringify('production')
2017-07-28 21:03:26 +00:00
}),
2018-01-21 00:21:54 +00:00
new webpack.optimize.UglifyJsPlugin()
2017-07-23 12:31:29 +00:00
]
2017-07-23 15:24:59 +00:00
})
2017-07-23 12:31:29 +00:00
2017-07-23 15:24:59 +00:00
const development = config => Object.assign({ }, config(), {
2017-07-23 12:31:29 +00:00
devServer: {
historyApiFallback: true,
stats: 'errors-only',
host: process.env.HOST,
2018-02-16 19:52:28 +00:00
port: 5000,
2017-07-23 12:31:29 +00:00
compress: true,
overlay: true,
hot: true,
2017-10-30 20:11:50 +00:00
contentBase: path.resolve(__dirname, "build/static")
2017-07-23 15:24:59 +00:00
},
devtool: "source-map",
plugins: [
new webpack.HotModuleReplacementPlugin(),
2018-03-02 09:33:58 +00:00
new WebpackNotifierPlugin()
2017-07-23 15:24:59 +00:00
]
2017-07-23 12:31:29 +00:00
})
module.exports = env => {
if (env === 'production') {
2017-07-28 21:03:26 +00:00
return [production(index), production(runtime)]
2017-08-02 20:54:02 +00:00
} else {
2018-01-18 16:14:16 +00:00
return [development(runtime)]
2017-07-23 12:31:29 +00:00
}
}