-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathwebpack.config.js
More file actions
163 lines (159 loc) · 5.06 KB
/
webpack.config.js
File metadata and controls
163 lines (159 loc) · 5.06 KB
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
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-require-imports */
const configureWebpackForTerriaJS = require("terriajs/buildprocess/configureWebpack");
const configureWebpackForPlugins = require("./configureWebpackForPlugins");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const HtmlPlugin = require("html-webpack-plugin");
/**
* Webpack config for building terriamap
*/
module.exports = function ({ devMode, baseHref = "/" }) {
// Base configuration
const config = {
mode: devMode ? "development" : "production",
entry: "./entry.js",
output: {
path: path.resolve(__dirname, "..", "wwwroot", "build"),
filename: "TerriaMap.js",
publicPath: "build/",
sourcePrefix: "", // to avoid breaking multi-line string literals by inserting extra tabs.
globalObject: "(self || window)" // to avoid breaking in web worker (https://github.com/webpack/webpack/issues/6642)
},
devtool: devMode ? "eval-cheap-module-source-map" : false,
module: {
// following rules are for terriamap source files
// rules for building terriajs are configured in configureWebpackForTerriaJS
rules: [
// build source files
{
test: /\.(ts|js)x?$/,
include: [
path.resolve(__dirname, "..", "index.js"),
path.resolve(__dirname, "..", "entry.js"),
path.resolve(__dirname, "..", "plugins.ts"),
path.resolve(__dirname, "..", "lib")
],
use: [
{
loader: "babel-loader",
options: {
cacheDirectory: true,
presets: [
[
"@babel/preset-env",
{
corejs: 3,
useBuiltIns: "usage"
}
],
["@babel/preset-react", { runtime: "automatic" }],
["@babel/preset-typescript", { allowNamespaces: true }]
],
plugins: [
["@babel/plugin-proposal-decorators", { legacy: true }],
"babel-plugin-styled-components"
]
}
}
]
},
// import html file as string
{
test: /\.html$/,
include: path.resolve(__dirname, "..", "lib", "Views"),
type: "asset/source"
},
// import images
{
test: /\.(png|jpg|svg|gif)$/,
include: path.resolve(__dirname, "..", "wwwroot", "images"),
type: "asset" // inlines as data url if size < 8kb
},
// import globe.gif
{
test: /globe\.gif$/,
include: path.resolve(__dirname, "..", "lib", "Styles"),
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 65536 // < inline as data url if size < 64k
}
}
},
// handle scss files
{
test: /\.scss$/,
include: [path.resolve(__dirname, "..", "lib")],
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// Use default export for css modules as opposed to the more
// efficient named exports. This is required because most of
// legacy stylesheets in TerriaJS assumes default export style.
defaultExport: true
}
},
{ loader: "terriajs-typings-for-css-modules-loader" },
{
loader: "css-loader",
options: {
sourceMap: true,
modules: {
localIdentName: "tjs-[name]__[local]",
exportLocalsConvention: "camelCase"
},
importLoaders: 2
}
},
{
loader: "resolve-url-loader",
options: {
sourceMap: false
}
},
{
loader: "sass-loader",
options: {
api: "modern",
sassOptions: {
sourceMap: true
}
}
}
]
}
]
},
plugins: [
// Extract SASS styles into a seperate stylesheet
new MiniCssExtractPlugin({
filename: "TerriaMap.css",
ignoreOrder: true
}),
new HtmlPlugin({
filename: path.resolve(__dirname, "..", "wwwroot", "index.html"),
template: path.resolve(__dirname, "..", "wwwroot", "index.ejs"),
templateParameters: {
baseHref: baseHref
}
})
],
resolve: {
alias: {},
modules: ["node_modules"]
}
};
config.resolve.alias["terriajs-variables"] = require.resolve(
"../lib/Styles/variables-overrides.scss"
);
return configureWebpackForPlugins(
configureWebpackForTerriaJS({
terriaJSBasePath: path.dirname(require.resolve("terriajs/package.json")),
config,
devMode,
MiniCssExtractPlugin
})
);
};