Skip to content

Webpack 5 upgrade #718

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

Merged
merged 30 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e3dffa2
Convert CJS require() to ESM style `import` statements.
na9da Nov 14, 2024
ad0e2eb
Update deps.
na9da Nov 14, 2024
d86701e
Merge branch 'main' into cjs-to-esm
na9da Nov 29, 2024
062a124
Migrate to modern SASS api.
na9da Dec 4, 2024
fd095d8
Update webpack config files to use webpack5.
na9da Dec 4, 2024
9f79a30
Refactor index.js and entry.js and convert to ESM style modules.
na9da Dec 4, 2024
0504f77
Update package.json.
na9da Dec 4, 2024
e867510
Update package.json.
na9da Dec 4, 2024
9e43066
Merge remote-tracking branch 'origin/main' into webpack5
zoran995 Feb 10, 2025
1833194
sync dependencies between packages
zoran995 Feb 10, 2025
4f2c7cf
Handle null and undefined globalDisclaimer values.
na9da Feb 11, 2025
a9afdff
Remove call to stale `polyfill` function.
na9da Feb 11, 2025
6fa66c3
Upgrade terriajs-cesium to 8.0.2.
na9da Feb 11, 2025
1bae868
Temporarily use webpack5 branch.
na9da Feb 11, 2025
67aa8ef
Update yarn.lock.
na9da Feb 11, 2025
1686f9c
Update min node version to 18.x.
na9da Feb 11, 2025
28ffafa
Set min node engine version to 20.x
na9da Feb 11, 2025
ba5c5d9
Remove unavailable node version from CI.
na9da Feb 11, 2025
7484e74
Merge branch 'main' into webpack5
na9da Feb 11, 2025
846025c
Remove unused dependencies and resolutions.
na9da Feb 11, 2025
256e64d
Update yarn.lock.
na9da Feb 11, 2025
499a2d8
Sync eslint version with terriajs.
na9da Feb 11, 2025
9079e73
Bump to node20 in Dockerfile.
na9da Feb 11, 2025
af9501b
Merge branch 'main' into webpack5
na9da Feb 11, 2025
18a47c4
Bump node to v20 in docker file.
na9da Feb 11, 2025
e83e199
Bump yarn.lock.
na9da Feb 11, 2025
35f44cd
Typescript 5.7 and eslint upgrades.
na9da Feb 12, 2025
18b28f7
Upgrade @types/node.
na9da Feb 12, 2025
4f9bcc8
Bump version to 0.3.0.
na9da Feb 18, 2025
926332c
Replace require() with import in showGlobalDisclaimer.ts.
na9da Feb 18, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]
node-version: [20.x, 22.x, 23.x]

steps:
- uses: actions/checkout@v2
Expand Down
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

#### 0.3.0

**2025-02-18**

- **Breaking changes:**
- Updated TerriaJS to `8.8.0`
- Upgrades Webpack to version 5
- Upgraded sass to version 1.80+
- [Full list of TerriaJS changes](https://github.com/TerriaJS/terriajs/blob/main/CHANGES.md#880---2025-02-18)
- Converted files from CJS to ESM style
- This includes `entry.js`, `index.js` - if you have changed these files it is likely that you will get a merge conflict when upgrading. Please [reach out to us](https://github.com/terriajs/terriajs/discussions) if you need help.
- Replaced webpack aliases `~terriajs-variables` and `~terriajs` in css imports with relative paths. This simplifies the webpack configuration.

#### 0.2.4

**2024-12-19**
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# develop container
FROM node:16 AS develop
FROM node:20 AS develop

# build container
FROM node:16 AS build
FROM node:20 AS build
USER node

COPY --chown=node:node . /app
Expand All @@ -13,7 +13,7 @@ RUN yarn install --network-timeout 1000000
RUN yarn gulp release

# deploy container
FROM node:16-slim AS deploy
FROM node:20-slim AS deploy

USER node

Expand Down
7 changes: 4 additions & 3 deletions buildprocess/configureWebpackForPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fs = require("fs");
* "terriajs-plugin-sample", "terriajs-sample-plugin" as well as
* "terriajs-some-plugin-for-something".
*/
const PluginPackagePattern = /^terriajs-.*plugin/;
const PluginPackagePattern = /(^@terriajs\/plugin-*|^terriajs-.*plugin)/;

function configureWebpackForPlugins(config) {
config.module.rules.push(createPluginIconsRule());
Expand Down Expand Up @@ -71,9 +71,10 @@ function readPackageName(packageFile) {
? packageJson.name
: undefined;
return packageJsonNames[packageFile];
} catch {}
} catch {
return;
}
}
return undefined;
}

module.exports = configureWebpackForPlugins;
1 change: 0 additions & 1 deletion buildprocess/webpack.config.hot.js

This file was deleted.

165 changes: 75 additions & 90 deletions buildprocess/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
"use strict";
const configureWebpackForTerriaJS = require("terriajs/buildprocess/configureWebpack");
const configureWebpackForPlugins = require("./configureWebpackForPlugins");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");

/*global require*/
var configureWebpackForTerriaJS = require("terriajs/buildprocess/configureWebpack");
var configureWebpackForPlugins = require("./configureWebpackForPlugins");
var MiniCssExtractPlugin = require("mini-css-extract-plugin");
var path = require("path");

module.exports = function (devMode, hot) {
var config = {
/**
* Webpack config for building terriamap
*/
module.exports = function (devMode) {
// Base configuration
const config = {
mode: devMode ? "development" : "production",
entry: "./entry.js",
output: {
path: path.resolve(__dirname, "..", "wwwroot", "build"),
filename: "TerriaMap.js",
// work around chrome needing the full URL when using sourcemaps (http://stackoverflow.com/questions/34133808/webpack-ots-parsing-error-loading-fonts/34133809#34133809)
publicPath: hot ? "http://localhost:3003/build/" : "build/",
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: [
{
test: /\.html$/,
include: path.resolve(__dirname, "..", "lib", "Views"),
loader: "raw-loader"
},
// build source files
{
test: /\.(ts|js)x?$/,
include: [
Expand All @@ -51,119 +50,105 @@ module.exports = function (devMode, hot) {
["@babel/typescript", { allowNamespaces: true }]
],
plugins: [
"@babel/plugin-transform-modules-commonjs",
["@babel/plugin-proposal-decorators", { legacy: true }],
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"babel-plugin-styled-components",
require.resolve("@babel/plugin-syntax-dynamic-import")
"babel-plugin-styled-components"
]
}
}
// Re-enable this if we need to observe any differences in the
// transpilation via ts-loader, & babel's stripping of types,
// or if TypeScript has newer features that babel hasn't
// caught up with
// {
// loader: require.resolve('ts-loader'),
// options: {
// transpileOnly: true
// // configFile: path.resolve(__dirname, '..', 'node_modules', 'terriajs', 'tsconfig.json')
// }
// }
]
},
// 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"),
loader: "url-loader",
options: {
limit: 8192
}
type: "asset" // inlines as data url if size < 8kb
},
// import globe.gif
{
test: /globe\.gif$/,
include: path.resolve(__dirname, "..", "lib", "Styles"),
loader: "url-loader",
options: {
limit: 65536
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 65536 // < inline as data url if size < 64k
}
}
},
// handle css files - inject in html tag
{
test: /loader\.css$/,
include: [path.resolve(__dirname, "..", "lib", "Styles")],
loader: ["style-loader", "css-loader"]
use: ["style-loader", "css-loader"]
},
// handle scss files
{
test: /\.scss$/,
include: [path.resolve(__dirname, "..", "lib")],
loader: hot
? [
"style-loader",
{
loader: "css-loader",
options: {
sourceMap: true,
modules: true,
camelCase: true,
localIdentName: "tm-[name]__[local]",
importLoaders: 2
}
},
{
loader: "resolve-url-loader",
options: {
sourceMap: false
}
},
"sass-loader?sourceMap"
]
: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
modules: true,
camelCase: true,
localIdentName: "tm-[name]__[local]",
importLoaders: 2
}
},
{
loader: "resolve-url-loader",
options: {
sourceMap: false
}
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: "css-loader",
options: {
sourceMap: true,
modules: {
localIdentName: "tjs-[name]__[local]",
exportLocalsConvention: "camelCase"
},
"sass-loader?sourceMap"
]
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",
disable: hot,
ignoreOrder: true,
allChunks: true
ignoreOrder: true
})
],
resolve: {
alias: {},
modules: ["node_modules"]
}
};
config.resolve.alias["terriajs-variables"] = require.resolve(
"../lib/Styles/variables.scss"
);

return configureWebpackForPlugins(
configureWebpackForTerriaJS(
path.dirname(require.resolve("terriajs/package.json")),
configureWebpackForTerriaJS({
terriaJSBasePath: path.dirname(require.resolve("terriajs/package.json")),
config,
devMode,
hot,
MiniCssExtractPlugin
)
})
);
};
2 changes: 1 addition & 1 deletion deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docker image for the primary terria map application server
FROM node:16
FROM node:20

RUN mkdir -p /usr/src/app && mkdir -p /etc/config/client
WORKDIR /usr/src/app/component
Expand Down
52 changes: 16 additions & 36 deletions entry.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
const globeGif = require("./lib/Styles/globe.gif");
const polyfill = require("terriajs/lib/Core/polyfill");
import globeGif from "./lib/Styles/globe.gif";
import "./lib/Styles/loader.css";

require("./lib/Styles/loader.css");

function loadMainScript() {
// load the main chunk
return new Promise((resolve, reject) => {
require.ensure(
["terriajs/lib/Core/prerequisites"],
function (require) {
require("terriajs/lib/Core/prerequisites");
require.ensure(
["./index"],
function (require) {
resolve(require("./index"));
},
reject,
"index"
);
},
reject,
"index"
);
});
async function loadMainScript() {
return import("terriajs/lib/Core/prerequisites")
.then(() => import("./index"))
.then(({ default: terriaPromise }) => terriaPromise);
}

function createLoader() {
Expand All @@ -44,18 +26,16 @@ function createLoader() {
loaderDiv.style.backgroundColor = "#383F4D";
document.body.appendChild(loaderDiv);

polyfill(function () {
loadMainScript()
.catch(() => {
// Ignore errors and try to show the map anyway
})
.then(() => {
loaderDiv.classList.add("loader-ui-hide");
setTimeout(() => {
document.body.removeChild(loaderDiv);
}, 2000);
});
});
loadMainScript()
.catch((_err) => {
// Ignore errors and try to show the map anyway
})
.then(() => {
loaderDiv.classList.add("loader-ui-hide");
setTimeout(() => {
document.body.removeChild(loaderDiv);
}, 2000);
});
}

createLoader();
Loading