Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
add option to copy assets or not
Browse files Browse the repository at this point in the history
  • Loading branch information
odoe committed Jul 19, 2021
1 parent ef9812e commit 7aadbb1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This plugin is only really useful if you want to copy the `@arcgis/core/assets`

| Options | Default | Description |
| ----------- | :-------------: |:-------------|
| `copyAssets` | `true` | Should plugin copy assets. |
| `assetsDir` | `assets` | The directory name to copy `@arcgis/core/assets` to. |
| `locales` | `undefined` | The `t9n` locales you want included in your build output. If not specified, all locales will be available. |
| `features` | {} | **ADVANCED** - See the [Additional Features](#additional-features) section |
Expand Down Expand Up @@ -126,6 +127,25 @@ plugins: [
...
```

You can specify that you do not want to copy assets, but want to exclude some modules.

```js
// webpack.config.js
module.exports = {
...
plugins: [
new ArcGISPlugin({
copyAssets: false,
// exclude 3D modules from build
features: {
"3d": false
}
})
]
...
}
```

Again, this considered **ADVANCED** usage, so please use with caution.

# Issues
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ module.exports = class ArcGISPlugin {
* Initialize the plugin
* @constructor
* @param {Object} [options] -(optional) The options for the ArcGIS Webpack Plugin
* @param {Object} [options.assetsDir] - (optional) Directory name to copy local assets to. Default is `assets`.
* @param {Boolean} [options.copyAssets] -(optional) PLugin should copy assets. Default is `true`.
* @param {String} [options.assetsDir] - (optional) Directory name to copy local assets to. Default is `assets`.
* @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 {Boolean} [options.features.3d] - (optional) Advanced! If false, will exclude all 3D related modules from output bundles. Default is `true`
* @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
*/
constructor(options = {}) {
this.options = {
copyAssets: true,
assetsDir: 'assets',
features: {
"3d": true
Expand All @@ -46,7 +48,7 @@ module.exports = class ArcGISPlugin {
if (this.options.userDefinedExcludes && this.options.userDefinedExcludes.length) {
compiler.options.module.rules.push(userExclusions(this.options.userDefinedExcludes));
}
const plugins = requiredPlugins(this.options.locales, this.options.assetsDir);
const plugins = requiredPlugins(this.options.locales, this.options.copyAssets, this.options.assetsDir);
plugins.forEach(plugin => plugin.apply(compiler));
}
};
1 change: 1 addition & 0 deletions lib/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = {
`${jsapi}/layers/mixins/SceneService`,
// support
`${jsapi}/layers/support/LercDecoder`,
`${jsapi}/rest/support/meshFeatureSet`,
// renderers
// catches all PointCloud renderers
`${jsapi}/renderers/PointCloud`,
Expand Down
41 changes: 23 additions & 18 deletions lib/requiredPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = function requiredPlugins(locales = [], assetsDir = 'assets') {
module.exports = function requiredPlugins(locales = [], copyAssets = true, assetsDir = 'assets') {
if (process.env["TEST_ENV"]) {
return [];
}
Expand Down Expand Up @@ -50,22 +50,27 @@ module.exports = function requiredPlugins(locales = [], assetsDir = 'assets') {
const localesIgnoreList = locales.map((locale) => `*_${locale}`).join("|");
const localesIgnoreGlob = `**/!(${localesIgnoreList}).json`;
const ignoreSass = "**/*.scss";
return [
// Copy non-packed resources needed by the app to the build directory
new CopyWebpackPlugin({
patterns: [
// assets
{
context: "node_modules",
from: `${jsapi}/assets`,
to: assetsDir,
globOptions: {
// ignore the webscene spec folder, sass files,
// and any locales not need for deployment
ignore: ["**/webscene/spec/**", ignoreSass, localesIgnoreGlob],
const plugins = [];
if (copyAssets) {
plugins.push(
// Copy non-packed resources needed by the app to the build directory
new CopyWebpackPlugin({
patterns: [
// assets
{
context: "node_modules",
from: `${jsapi}/assets`,
to: "assets",
globOptions: {
// ignore the webscene spec folder, sass files,
// and any locales not need for deployment
ignore: ["**/webscene/spec/**", ignoreSass, localesIgnoreGlob],
},
},
},
],
}),
];
],
})
);
};

return plugins;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arcgis/webpack-plugin",
"version": "4.19.0",
"version": "4.20.0",
"description": "Webpack plugin to load ArcGIS API for JavaScript into a Webpack application",
"main": "index.js",
"engines": {
Expand Down

0 comments on commit 7aadbb1

Please sign in to comment.