This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.js
100 lines (96 loc) · 3.91 KB
/
index.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
/*
Copyright 2020 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const DojoWebpackPlugin = require("dojo-webpack-plugin");
const path = require("path");
const requiredPlugins = require("./lib/requiredPlugins");
const features = require("./lib/features");
const userExclusions = require("./lib/userExclusions");
module.exports = class ArcGISPlugin {
/**
* Initialize the plugin
* @constructor
* @param {Object} [options] -(optional) The options for the ArcGIS Webpack Plugin
* @param {boolean} [options.useDefaultAssetLoaders] - (optional) Let the plugin manage how image, svg, and fonts are loaded
* @param {Object} [options.features] - (optional) Advanced! Set of features you can enable and disable.
* @param {boolean} [options.features.3d] - (optional) Advanced! If false, will exclude all 3D related modules from output bundles. Default is `true`
* @param {Object} [options.features.has] - (optional) Additional `has` features to provide to the build
* @param {Array.<string>} [options.userDefinedExcludes] - (optional) Advanced! Provide a list of modules you would like to exclude from the output bundles
* @param {Array.<string>} [options.locales] - (optional) Which locales to include in build, leave empty to support all locales
* @param {Object} [options.options] - (optional) - Override the dojo-webpack-plugin options used by the ArcGIS Webpack Plugin
*/
constructor(options = {}) {
this.options = {
useDefaultAssetLoaders: true,
features: {
"3d": true,
has: {}
},
userDefinedExcludes: [],
globalContext: path.join(__dirname, "node_modules", "arcgis-js-api"),
environment: {
root: options.root || "."
},
buildEnvironment: {
root: "node_modules"
},
loader: path.join(__dirname, "./loader/dojo.js"),
noConsole: true
};
this.options = { ...this.options, ...options, ...options.options };
if (!this.options.loaderConfig) {
this.options.loaderConfig = require("./lib/loaderConfig")(this.options.features.has);
}
}
apply(compiler) {
compiler.options.module.rules = compiler.options.module.rules || [];
compiler.options.module.rules.push({
test: /@dojo/,
use: "umd-compat-loader"
});
if (this.options.useDefaultAssetLoaders) {
compiler.options.module.rules.push({
test: /arcgis-js-api([\\]+|\/).*.(jpe?g|png|gif|webp)$/,
use: [
{
loader: "url-loader",
options: {
// Inline files smaller than 10 kB (10240 bytes)
limit: 10 * 1024,
}
}
]
});
if (this.options.features["3d"] == false) {
compiler.options.module.rules.push(features["3d"]);
}
if (this.options.userDefinedExcludes && this.options.userDefinedExcludes.length) {
compiler.options.module.rules.push(userExclusions(this.options.userDefinedExcludes));
}
compiler.options.module.rules.push({
test: /arcgis-js-api([\\]+|\/).*.(wsv|ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "build/[name].[ext]"
}
}
]
});
}
const plugins = requiredPlugins(this.options.features.has);
this.dojoPlugin = new DojoWebpackPlugin(this.options);
plugins.unshift(this.dojoPlugin);
plugins.forEach(plugin => plugin.apply(compiler));
}
};