-
Notifications
You must be signed in to change notification settings - Fork 107
/
webpack.config.js
139 lines (132 loc) · 5.05 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
const path = require('path');
const webpack = require('webpack');
module.exports = (env) => {
const LIB_NAME = 'geolocator';
const SRC_PATH = path.resolve(__dirname, 'src');
const OUT_PATH = path.resolve(__dirname, 'dist');
const ENTRY_PATH = path.resolve(__dirname, 'src');
const PUBLIC_PATH = 'dist/';
// Webpack configuration
// http://webpack.github.io/docs/configuration.html
const config = {
mode: 'development',
cache: false,
entry: ENTRY_PATH,
// http://webpack.github.io/docs/configuration.html#devtool
devtool: 'source-map',
// the environment in which the bundle should run changes chunk loading
// behavior and available modules
target: 'web',
// string (absolute path!). the home directory for webpack the entry and
// module.rules.loader option is resolved relative to this directory
context: __dirname,
output: {
// the target directory for all output files must be an absolute
// path (use the Node.js path module)
path: OUT_PATH,
// the filename template for entry chunks
filename: LIB_NAME + '.js',
// the name of the exported library
library: LIB_NAME,
// the type of the exported library
libraryTarget: 'umd',
// use a named AMD module in UMD library
umdNamedDefine: true,
// the url to the output directory resolved relative to the HTML
// page
publicPath: PUBLIC_PATH
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
// https://github.com/rollup/rollup-plugin-babel/issues/120#issuecomment-301325496
presets: [
['es2015', { "modules": false }]
]
}
}
},
{
test: /\.html?$/,
loader: 'html-loader'
},
{
test: /\.svg$/,
loader: 'svg-inline'
}
]
},
resolve: {
modules: [SRC_PATH],
extensions: ['.js']
},
// errors-only | minimal | none | normal | verbose
stats: 'normal',
plugins: [
// https://webpack.js.org/plugins/banner-plugin/
new webpack.BannerPlugin({
banner: `Geolocator.js https://github.com/onury/geolocator\n@license MIT. © ${new Date().getFullYear()}, Onur Yıldırım`,
raw: false
})
],
// https://webpack.js.org/configuration/dev-server/#devserver
devServer: {
// Tell the server where to serve content from. This is only
// necessary if you want to serve static files. devServer.publicPath
// will be used to determine where the bundles should be served
// from, and takes precedence.
contentBase: path.resolve(__dirname, 'example'),
index: 'index.html',
// enable gzip compression for everything served
compress: true,
host: 'localhost',
port: 9991,
publicPath: '/' + PUBLIC_PATH,
// when using the HTML5 History API, the index.html page will likely
// have to be served in place of any 404 responses.
historyApiFallback: true,
// enable webpack's Hot Module Replacement feature
hot: true,
// Whether to embed the webpack-dev-server runtime into the bundle.
inline: false,
// if enabled, the dev-server will only compile the bundle when it
// gets requested. This means that webpack will not watch any file
// changes.
lazy: false,
// if enabled, messages like the webpack bundle information that is
// shown when starting up and after each save, will be hidden.
// errors and warnings will still be shown.
noInfo: true,
// if enabled, the dev server will open the browser.
open: false,
// openPage: '',
overlay: false,
quiet: false,
stats: 'normal',
watchContentBase: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
ignored: /node_modules/
}
}
};
if (env.prod) {
config.mode = 'production';
config.output.filename = LIB_NAME + '.min.js';
config.optimization = {
minimize: true
};
}
if (env.serve) {
config.mode = 'development';
config.watch = true;
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
return config;
};