forked from ghettovoice/ol-tilecache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
144 lines (137 loc) · 3.92 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
140
141
142
143
144
const webpack = require('webpack');
const path = require('path');
const glob = require('glob');
const _ = require('lodash');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const chalk = require('chalk');
const packageJson = require('./package.json');
const RELEASE = _.includes(process.argv, '--release');
const BUILD = _.includes(process.argv, '--build');
const DEBUG = !BUILD && !RELEASE;
const VERBOSE = _.includes(process.argv, '--verbose');
const PROFILE = _.includes(process.argv, '--profile');
const GLOBALS = {
'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"',
__DEV__: DEBUG
};
const nodeModulesDir = path.join(__dirname, 'node_modules');
const srcDir = path.join(__dirname, 'src');
const outDir = path.join(__dirname, 'dist');
const bundleName = RELEASE ? 'bundle.min.js' : 'bundle.js';
const exportName = ['ol', 'TileCacheUrlFunction'];
const entry = path.join(srcDir, 'index.js');
const banner =
`${packageJson.description}
@package ${packageJson.name}
@author ${packageJson.author}
@version ${packageJson.version}
@licence MIT https://opensource.org/licenses/MIT
Based on OpenLayers 3. Copyright 2005-2016 OpenLayers Contributors. All rights reserved. http://openlayers.org
@copyright (c) 2016, ${packageJson.author}`;
const plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin(GLOBALS),
new ProgressBarPlugin({
format: ' build ' + chalk.magenta.bold('[ol3-tilecache]') + ' ' + chalk.cyan.bold('[:bar]') + ' ' + chalk.green.bold(':percent') + ' (:elapsed seconds)'
})
];
if (DEBUG) {
plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
);
} else {
plugins.push(
new webpack.BannerPlugin(banner),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.AggressiveMergingPlugin()
);
if (RELEASE) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
comments: false,
mangle: true,
compress: {
warnings: VERBOSE
},
output: {
preamble: `/*!\n${banner}\n*/`
}
})
);
}
}
module.exports = {
devtool: DEBUG ? '#cheap-module-eval-source-map' : '#source-map',
devServer: {
contentBase: __dirname,
hot: true,
inline: true,
host: 'localhost',
port: 8080
},
stats: {
colors: true,
cached: false,
cachedAssets: false,
chunks: false,
chunkModules: false,
modules: false
},
cache: DEBUG,
profile: PROFILE,
debug: DEBUG,
entry: entry,
externals: [
{
openlayers: {
root: 'ol',
amd: 'openlayers',
commonjs: 'openlayers',
commonjs2: 'openlayers'
}
}
],
output: {
path: outDir,
filename: bundleName,
publicPath: DEBUG ? 'http://localhost:8080/dist/' : '/dist/',
crossOriginLoading: "anonymous",
library: exportName,
libraryTarget: 'umd'
},
resolve: {
root: [nodeModulesDir],
extensions: ['', '.tsx', '.ts', '.jsx', '.js', '.json']
},
node: {
console: false,
global: true,
process: true,
Buffer: true,
__filename: "mock",
__dirname: "mock",
setImmediate: true,
fs: "empty"
},
module: {
loaders: [{
test: /\.tsx?$/,
exclude: [outDir],
loaders: ['ts']
}, {
test: /\.jsx?$/,
exclude: [outDir],
loaders: ['babel']
}, {
test: /\.json$/i,
exclude: [outDir],
loader: 'json'
}, {
test: /\.txt$/i,
exclude: [outDir],
loader: 'raw'
}]
},
plugins: plugins
};