2017-09-08 14:28:21 +01:00
import { join } from 'path'
import webpack from 'webpack'
import { extract } from 'extract-text-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
const PORT = 3000
const PRODUCTION = process . env . NODE _ENV === 'production'
2017-09-08 23:42:06 +01:00
const PUBLIC _PATH = PRODUCTION ? '' : ` http://localhost: ${ PORT } / `
2017-09-08 14:28:21 +01:00
const PATH _DEMO = join ( _ _dirname , 'demo' )
const PATH _SRC = join ( _ _dirname , 'src' )
const PATH _INDEX = join ( _ _dirname , 'index.html' )
2017-09-12 11:06:37 +01:00
const PATH _TESTS = join ( _ _dirname , 'test' , 'specs' )
2017-09-08 14:28:21 +01:00
export const plugins = [
new HtmlWebpackPlugin ( {
template : PATH _INDEX ,
minify : {
collapseWhitespace : true ,
quoteCharacter : '\''
}
} )
]
export default {
devtool : 'cheap-module-eval-source-map' ,
entry : [
` webpack-dev-server/client?http://localhost: ${ PORT } ` ,
'webpack/hot/only-dev-server' ,
'./src/demo/index'
] ,
module : {
rules : [
{
test : /\.js$/ ,
loader : 'babel-loader' ,
include : [ PATH _SRC , PATH _TESTS ]
} ,
{
2018-01-17 11:52:23 +00:00
test : /\.css$/ ,
2017-09-08 14:28:21 +01:00
use : styleLoader ( [
'style-loader' ,
'css-loader?sourceMap' ,
2018-01-17 11:52:23 +00:00
'postcss-loader?sourceMap'
2017-09-08 14:28:21 +01:00
] ) ,
include : PATH _SRC
}
]
} ,
output : {
path : PATH _DEMO ,
filename : 'app.js' ,
publicPath : PUBLIC _PATH
} ,
plugins : [
... plugins ,
new webpack . HotModuleReplacementPlugin ( ) ,
2017-09-09 01:05:34 +01:00
new webpack . NoEmitOnErrorsPlugin ( ) ,
new webpack . NamedModulesPlugin ( )
2017-09-08 14:28:21 +01:00
] ,
devServer : {
port : PORT ,
publicPath : PUBLIC _PATH ,
hot : true ,
historyApiFallback : true ,
stats : {
colors : true
}
}
}
function styleLoader ( loaders ) {
if ( process . env . NODE _ENV === 'production' ) {
const [ fallback , ... use ] = loaders
return extract ( { fallback , use } )
}
return loaders
}