forked from norheim/sextantwebapp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
206 lines (199 loc) · 9.26 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
const path = require("path");
const webpack = require("webpack");
// use webpack --watch to watch code to recompile
// use express in server.js (ie use debug flag)
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const nodeModulesPath = path.resolve(__dirname, "node_modules");
const buildPath = path.resolve(__dirname, "public", "build");
const indexPath = path.resolve(__dirname, "app", "index.js");
const cesiumSource = path.resolve(__dirname,"node_modules", "cesium", "Source");
const cesiumWorkers = "../Build/Cesium/Workers";
const staticPath = path.resolve(__dirname, "static");
// Cesium Navigation includes, this does not work the way cesium-navigation is packaged.
// For now we have the files copied into our cesium_util directory.
//const cesiumNavigationPath = path.resolve(__dirname,"node_modules", "cesium-navigation", "dist", "amd");
const ENV_DEFAULTS = {'CONFIG_PATH': undefined};
module.exports = (env = ENV_DEFAULTS) => {
return {
// see https://blog.flennik.com/the-fine-art-of-the-webpack-2-config-dc4d19d7f172
//devtool: "source-map",
stats: "verbose",
resolve: {
alias: {
// Cesium module name
'cesium': path.resolve(__dirname, cesiumSource),
'jquery': require.resolve('jquery')
//cesiumNavigation: path.resolve(__dirname, cesiumNavigationPath)
},
modules: [
path.resolve("./app"),
path.resolve("./config"),
path.resolve("./node_modules")
]
},
entry: [
indexPath
],
output: {
path: buildPath,
publicPath: "/build/",
filename: "xgds-3d-view.bundle.js",
library: "xgds3dview", // the name of the library we refer to
libraryTarget: "umd"
},
amd: {
// Enable webpack-friendly use of require in Cesium
toUrlUndefined: true
},
plugins: [
// new webpack.DefinePlugin({
// "process.env.CONFIG_PATH": JSON.stringify(process.env.CONFIG_PATH || undefined)
// }),
new CleanWebpackPlugin(['public/build']),
new webpack.EnvironmentPlugin({
'CONFIG_PATH': env.CONFIG_PATH
}),
// new webpack.optimize.UglifyJsPlugin({
// sourceMap: true,
// compress: {
// warnings: true
// }
// }),
// Copy Cesium Assets, Widgets, and Workers to a static directory
new CopyWebpackPlugin([{from: path.join(cesiumSource, cesiumWorkers), to: "Workers"}]),
new CopyWebpackPlugin([{from: path.join(cesiumSource, "Assets"), to: "Assets"}]),
new CopyWebpackPlugin([{from: path.join(cesiumSource, "Widgets"), to: "Widgets"}]),
new CopyWebpackPlugin([{from: path.join(staticPath, "icons"), to: "icons"}]),
new webpack.ProvidePlugin({
// Make jQuery / $ available in every module:
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery'
})
// new ExtractTextPlugin({filename:"styles.css",
// allChunks: true})
],
module: {
// noParse: [
// /.pako_inflate.js/ //this module seems to cause some warning apparently
// ],
rules: [
{
test: /\.jsx?$/,
use: [{
loader: "babel-loader",
options: {
plugins: ["transform-runtime"]
}
}
],
exclude: [nodeModulesPath]
},
{
test: /\.js$/,
exclude: [nodeModulesPath],
use: [{
loader: "babel-loader",
options: {
plugins: ["transform-runtime"]
}
}]
},
// {
// // Remove pragmas
// test: /\.js$/,
// enforce: 'pre',
// include: path.resolve(__dirname, cesiumSource),
// use: [{
// loader: 'strip-pragma-loader',
// options: {
// pragmas: {
// debug: false
// }
// }
// }]
// },
{
test: /\.css$/,
use: [
{
loader: "style-loader",
options: {
sourceMap: true,
includePaths:['node_modules'],
}
},
{
loader: "css-loader",
options: {
sourceMap: true,
includePaths:['node_modules'],
}
}
// {
// loader: 'sass-loader',
// options: {
// sourceMap: true
// }
// }
]
},
// {
// test: /\.css$/,
// use: ExtractTextPlugin.extract({
// fallback: "style-loader",
// use: [{
// loader: 'css-loader'
// /*
// options: {
// // If you are having trouble with urls not resolving add this setting.
// // See https://github.com/webpack-contrib/css-loader#url
// url: false,
// minimize: true,
// sourceMap: true
// // alias: { "./Viewer": path.join(cesiumSource, "Widgets", "Viewer"),
// // "./Animation": path.join(cesiumSource, "Widgets", "Animation"),
// // "./BaseLayerPicker": path.join(cesiumSource, "Widgets", "BaseLayerPicker"),
// // "./Cesium3DTilesInspector": path.join(cesiumSource, "Widgets", "Cesium3DTilesInspector"),
// // "./CesiumWidget": path.join(cesiumSource, "Widgets", "CesiumWidget"),
// // "./FullscreenButton": path.join(cesiumSource, "Widgets", "FullscreenButton"),
// // "./Geocoder": path.join(cesiumSource, "Widgets", "Geocoder"),
// // "./HomeButton": path.join(cesiumSource, "Widgets", "HomeButton"),
// // "./Images": path.join(cesiumSource, "Widgets", "Images"),
// // "./InfoBox": path.join(cesiumSource, "Widgets", "InfoBox"),
// // "./NavigationHelpButton": path.join(cesiumSource, "Widgets", "NavigationHelpButton"),
// // "./PerformanceWatchdog": path.join(cesiumSource, "Widgets", "PerformanceWatchdog"),
// // "./SceneModePicker": path.join(cesiumSource, "Widgets", "SceneModePicker"),
// // "./SelectionIndicator": path.join(cesiumSource, "Widgets", "SelectionIndicator"),
// // "./Timeline": path.join(cesiumSource, "Widgets", "Timeline"),
// // "./VRButton": path.join(cesiumSource, "Widgets", "VRButton")
// // }
// }
// */
// },
// {
// loader: 'sass-loader',
// options: {
// sourceMap: true
// }
// }
// ]
// })
// },
{test: /\.less$/, use: ["style-loader", "css-loader", "less-loader"]},
{
test: /\.(?:png|jpe?g|woff|woff2|eot|ttf|svg|gif|glsl)$/, use: [{
loader: "url-loader",
options: {limit: 10000}
}]
}
]
},
node: {
__dirname: true,
fs: "empty" //bug fix for cannot resolve module fs error
}
}
};