forked from cookpete/react-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
78 lines (73 loc) · 1.74 KB
/
webpack.config.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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'
const PUBLIC_PATH = PRODUCTION ? '' : `http://localhost:${PORT}/`
const PATH_DEMO = join(__dirname, 'demo')
const PATH_SRC = join(__dirname, 'src')
const PATH_INDEX = join(__dirname, 'index.html')
const PATH_TESTS = join(__dirname, 'test', 'specs')
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 ]
},
{
test: /\.css$/,
use: styleLoader([
'style-loader',
'css-loader?sourceMap',
'postcss-loader?sourceMap'
]),
include: PATH_SRC
}
]
},
output: {
path: PATH_DEMO,
filename: 'app.js',
publicPath: PUBLIC_PATH
},
plugins: [
...plugins,
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin()
],
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
}