homepage-frontend/webpack.config.js

125 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-07-23 12:31:29 +00:00
const path = require("path")
const webpack = require("webpack")
const baseConfig = {
output: {
path: path.resolve(__dirname, "./build"),
filename: "[name].bundle.js",
sourceMapFilename: "[file].map"
},
resolve: {
alias: {
"react": "inferno-compat",
"react-dom": "inferno-compat"
}
},
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]"
}
}
]
}
]
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",
2017-07-23 15:24:59 +00:00
library: "homepage",
libraryTarget: "umd"
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({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
compress:{
warnings: true
}
})
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,
port: 3000,
compress: true,
overlay: true,
hot: true,
contentBase: path.resolve(__dirname, "build")
2017-07-23 15:24:59 +00:00
},
devtool: "source-map",
plugins: [
new webpack.HotModuleReplacementPlugin(),
]
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 {
return [development(index), development(runtime)]
2017-07-23 12:31:29 +00:00
}
}