-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwebpack.config.js
95 lines (87 loc) · 2.04 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
// webpack.config.js
const path = require('path')
const webpack = require('webpack')
const pathOutput = path.resolve(__dirname, 'dev')
const pathBuild = path.resolve(__dirname, 'build')
const pathNodeModules = path.resolve(__dirname, 'node_modules')
const env = process.env.NODE_ENV
const isProd = env === 'production'
const libraryName = 'alfrid'
console.log('Environment isProd :', isProd)
const entryPoint = process.argv.filter(arg => arg.indexOf('.js') > -1)[0]
const entryJs = entryPoint || './dev/main.js'
console.log('Entry Point :', entryJs)
const plugins = isProd
? [
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
compress: {
drop_debugger: true,
drop_console: false,
screw_ie8: true
},
comments: false,
mangle: false
})
] : [
new webpack.HotModuleReplacementPlugin()
]
const entry = isProd ? { app: `./src/${libraryName}.js` }
: { app: entryJs }
const output = isProd ? {
path: pathBuild,
filename: `./${libraryName}.js`,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
} : {
filename: 'bundle.js',
path: pathOutput
}
const devtool = 'source-map'
const config = {
entry,
devtool,
devServer: {
host: '0.0.0.0',
contentBase: './dev',
hot: true,
disableHostCheck: true
},
plugins,
output,
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['env']
}
// exclude: pathNodeModules
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
exclude: pathNodeModules
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
exclude: pathNodeModules
},
{
test: /\.(glsl|vert|frag)$/,
use: ['raw-loader', 'glslify-loader'],
exclude: pathNodeModules
}
]
},
resolve: {
alias: {
shaders: path.resolve(__dirname, 'dev/shaders'),
src: path.resolve(__dirname, 'src')
}
}
}
module.exports = config