-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
139 lines (129 loc) · 3.22 KB
/
webpack.config.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// https://github.com/diegohaz/arc/wiki/Webpack
const path = require('path')
const fs = require('fs')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const devServer = require('@webpack-blocks/dev-server2')
const splitVendor = require('webpack-blocks-split-vendor')
// const happypack = require('webpack-blocks-happypack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const {
addPlugins, createConfig, entryPoint, env, setOutput,
sourceMaps, defineConstants, webpack,
} = require('@webpack-blocks/webpack2')
const host = process.env.HOST || '0.0.0.0'
const port = process.env.PORT || 3000
const sourceDir = process.env.SOURCE || 'src'
const publicPath = `/${process.env.PUBLIC_PATH || ''}/`.replace('//', '/')
const sourcePath = path.join(process.cwd(), sourceDir)
const outputPath = path.join(process.cwd(), 'dist')
const babel = () => () => ({
module: {
rules: [
{ test: /\.jsx?$/, exclude: /node_modules\/(?!react-voice-components)/, loader: 'babel-loader' },
],
},
})
const assets = () => () => ({
module: {
rules: [
{ test: /\.(png|jpe?g|svg|woff2?|ttf|eot)$/, loader: 'url-loader?limit=8000' },
],
},
})
const resolveModules = modules => () => ({
resolve: {
modules: [].concat(modules, ['node_modules', 'semantic']),
},
})
const css = () => () => ({
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [ 'css-loader' ]
})
},
// {
// test: /\.css$/,
// use: [ 'style-loader', 'css-loader' ]
// },
]
},
plugins: [
new ExtractTextPlugin({
filename: '[name].css'
})
]
})
const devServerConfig = () => () => ({
devServer: {
compress: true,
disableHostCheck: true, // That solved it
}
})
const https = () => () => ({
devServer: {
https: {
key: fs.readFileSync("./public/certbot/privkey.pem"),
cert: fs.readFileSync("./public/certbot/fullchain.pem"),
// ca: fs.readFileSync("/path/to/ca.pem"),
}
}
})
const config = createConfig([
entryPoint({
app: sourcePath,
}),
setOutput({
filename: '[name].js',
path: outputPath,
publicPath,
}),
defineConstants({
'process.env.NODE_ENV': process.env.NODE_ENV,
'process.env.PUBLIC_PATH': publicPath.replace(/\/$/, ''),
}),
addPlugins([
new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(process.cwd(), 'public/index.html'),
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]),
babel(),
// happypack([
// babel(),
// ]),
assets(),
resolveModules(sourceDir),
https(),
// css(),
env('development', [
devServer({
contentBase: 'public',
stats: 'errors-only',
historyApiFallback: { index: publicPath },
headers: { 'Access-Control-Allow-Origin': '*' },
host,
port,
}),
devServerConfig(),
sourceMaps(),
addPlugins([
new webpack.NamedModulesPlugin(),
]),
]),
env('production', [
splitVendor(),
addPlugins([
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }),
]),
]),
])
module.exports = config