Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies to Webpack 5 #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v2.0.0 - 2024/03/18

- Upgrade webpack to v5
- Upgrade other related dependencies

## v1.2.0 - 2019/11/11

- Add `cesiumPath` option
Expand Down
103 changes: 54 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ try {
let cesiumSource;
if (pnp) {
// Craco Cesium using Pnp
const topLevelLocation = pnp.getPackageInformation(pnp.topLevel)
.packageLocation;
const topLevelLocation = pnp.getPackageInformation(
pnp.topLevel
).packageLocation;
cesiumSource = path.resolve(
pnp.resolveToUnqualified("cesium", topLevelLocation, {
considerBuiltins: false
considerBuiltins: false,
}),
"Source"
);
Expand All @@ -42,13 +43,13 @@ try {
// ignore
}

module.exports = options => ({
module.exports = (options) => ({
overrideWebpackConfig: ({ webpackConfig, context: { env } }) => {
const { loadPartially, loadCSSinHTML, cesiumPath } = {
loadPartially: false,
loadCSSinHTML: true,
cesiumPath: "cesium",
...options
...options,
};

const prod = env === "production";
Expand All @@ -69,102 +70,106 @@ module.exports = options => ({
loader: "strip-pragma-loader",
options: {
pragmas: {
debug: false
}
}
}
]
debug: false,
},
},
},
],
});
}

webpackConfig.resolve.alias = {
...webpackConfig.resolve.alias,
cesium$: "cesium/Cesium",
cesium: "cesium/Source"
cesium: "cesium/Source",
};

webpackConfig.plugins.push(
new CopyWebpackPlugin([
{
from: path.join(cesiumSource, "../Build/Cesium/Workers"),
to: path.join(cesiumPath, "Workers")
},
{
from: path.join(cesiumSource, "../Build/Cesium/ThirdParty"),
to: path.join(cesiumPath, "ThirdParty")
},
{
from: path.join(cesiumSource, "Assets"),
to: path.join(cesiumPath, "Assets")
},
{
from: path.join(cesiumSource, "Widgets"),
to: path.join(cesiumPath, "Widgets")
}
]),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(cesiumSource, "../Build/Cesium/Workers"),
to: path.join(cesiumPath, "Workers"),
},
{
from: path.join(cesiumSource, "../Build/Cesium/ThirdParty"),
to: path.join(cesiumPath, "ThirdParty"),
},
{
from: path.join(cesiumSource, "Assets"),
to: path.join(cesiumPath, "Assets"),
},
{
from: path.join(cesiumSource, "Widgets"),
to: path.join(cesiumPath, "Widgets"),
},
],
}),
...(loadCSSinHTML
? [
new HtmlWebpackTagsPlugin({
append: false,
tags: [path.join(cesiumPath, "Widgets", "widgets.css")]
})
tags: [path.join(cesiumPath, "Widgets", "widgets.css")],
}),
]
: []),
new webpack.DefinePlugin({
CESIUM_BASE_URL: JSON.stringify(cesiumPath)
CESIUM_BASE_URL: JSON.stringify(cesiumPath),
})
);

if (amd) {
webpackConfig.output = {
...webpackConfig.output,
// Needed to compile multiline strings in Cesium
sourcePrefix: ""
sourcePrefix: "",
};

webpackConfig.amd = {
...webpackConfig.amd,
// Enable webpack-friendly use of require in Cesium
toUrlUndefined: true
toUrlUndefined: true,
};
}

webpackConfig.node = {
...webpackConfig.node,
// Resolve node module use of fs
fs: "empty"
fs: "empty",
};
} else {
// https://resium.darwineducation.com/installation1

webpackConfig.plugins.push(
new CopyWebpackPlugin([
{
from: path.join(
cesiumSource,
`../Build/Cesium${prod ? "" : "Unminified"}`
),
to: cesiumPath
}
]),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(
cesiumSource,
`../Build/Cesium${prod ? "" : "Unminified"}`
),
to: cesiumPath,
},
],
}),
new HtmlWebpackTagsPlugin({
append: false,
tags: [
...(loadCSSinHTML ? ["cesium/Widgets/widgets.css"] : []),
path.join(cesiumPath, "Cesium.js")
]
path.join(cesiumPath, "Cesium.js"),
],
}),
new webpack.DefinePlugin({
CESIUM_BASE_URL: JSON.stringify(cesiumPath)
CESIUM_BASE_URL: JSON.stringify(cesiumPath),
})
);

webpackConfig.externals = {
...webpackConfig.externals,
cesium: "Cesium"
cesium: "Cesium",
};
}

return webpackConfig;
}
},
});
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "craco-cesium",
"version": "1.2.0",
"version": "2.0.0",
"description": "Let's use Cesium with create-react-app today!",
"main": "index.js",
"repository": "https://github.com/darwin-education/craco-cesium.git",
Expand All @@ -10,9 +10,9 @@
"index.js"
],
"dependencies": {
"copy-webpack-plugin": "^5.1.1",
"html-webpack-tags-plugin": "^2.0.17",
"webpack": "^4.42.1"
"copy-webpack-plugin": "^12.0.2",
"html-webpack-tags-plugin": "^3.0.2",
"webpack": "^5.75.0"
},
"peerDependencies": {
"@craco/craco": "*"
Expand Down
Loading