Skip to content

Commit e0e0579

Browse files
authored
Merge pull request #417 from code-dot-org/webpack-4-to-5
webpack 4 to 5
2 parents 7573af0 + 0e53fe9 commit e0e0579

10 files changed

Lines changed: 5171 additions & 5827 deletions

File tree

.babelrc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
{
2-
"presets": ["env", "react" ],
3-
"plugins": [
4-
"add-module-exports",
5-
"syntax-async-functions",
6-
"transform-object-rest-spread",
7-
"transform-class-properties",
8-
["transform-regenerator", {"async": true, "asyncGenerators": true}],
9-
["transform-es2015-classes", {"loose": true}]
10-
]
2+
"presets": ["@babel/preset-env", "@babel/preset-react"]
113
}

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
"globals": {
77
},
88
"plugins": [
9+
"react"
910
],
1011
"extends": [
1112
'plugin:react/recommended',
@@ -21,7 +22,7 @@ module.exports = {
2122
"version": "detect"
2223
}
2324
},
24-
"parser": "babel-eslint",
25+
"parser": "@babel/eslint-parser",
2526
"parserOptions": {
2627
"sourceType": "module",
2728
"ecmaFeatures": {

package.json

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
"^@ml(.*)$": "<rootDir>/src/$1",
1414
"^@public(.*)$": "<rootDir>/public/$1"
1515
},
16-
"setupTestFrameworkScriptFile": "<rootDir>/test/setup.js"
16+
"setupFilesAfterEnv": ["<rootDir>/test/setup.js"],
17+
"globals": {
18+
"window": {},
19+
"location": {}
20+
}
1721
},
1822
"scripts": {
19-
"build": "webpack -p",
23+
"build": "webpack --mode production",
2024
"start": "yarn run dev",
21-
"dev": "webpack-dev-server --mode development --content-base public --host 0.0.0.0 --disable-host-check",
25+
"dev": "webpack-dev-server --mode development --static public --host 0.0.0.0",
2226
"lint": "eslint --ext .js,.jsx src",
2327
"test": "yarn run lint && jest",
2428
"test:unit": "jest ./test/unit/*.js",
@@ -39,42 +43,35 @@
3943
"react-dom": "~16.14.0"
4044
},
4145
"devDependencies": {
46+
"@babel/core": "^7.24.0",
47+
"@babel/eslint-parser": "7.25.9",
48+
"@babel/preset-env": "^7.24.0",
49+
"@babel/preset-react": "^7.23.0",
4250
"@code-dot-org/redactable-markdown": "^0.4.0",
4351
"@code-dot-org/svm": "^0.1.1",
4452
"@tensorflow-models/knn-classifier": "~1.1.0",
4553
"@tensorflow-models/mobilenet": "^2.0.4",
4654
"@tensorflow/tfjs": "^1.3.1",
47-
"babel-core": "^6.26.3",
48-
"babel-eslint": "^7.1.1",
49-
"babel-loader": "^7.1.4",
55+
"assert": "^2.1.0",
56+
"babel-loader": "^8.3.0",
5057
"babel-plugin-add-module-exports": "^0.2.1",
51-
"babel-plugin-syntax-async-functions": "^6.8.0",
52-
"babel-plugin-transform-class-properties": "^6.23.0",
53-
"babel-plugin-transform-es2015-classes": "^6.9.0",
54-
"babel-plugin-transform-object-rest-spread": "^6.8.0",
55-
"babel-plugin-transform-react-jsx": "^6.8.0",
56-
"babel-plugin-transform-regenerator": "^6.26.0",
57-
"babel-polyfill": "^6.26.0",
58-
"babel-preset-env": "^1.7.0",
59-
"babel-preset-react": "^6.5.0",
60-
"babelify": "^10.0.0",
6158
"canvas": "^2.8.0",
6259
"clean-webpack-plugin": "^3.0.0",
63-
"copy-webpack-plugin": "^5.0.5",
64-
"css-loader": "^3.2.0",
60+
"copy-webpack-plugin": "^11.0.0",
61+
"css-loader": "^5.0.0",
6562
"enzyme": "^3.9.0",
6663
"enzyme-adapter-react-16": "^1.15.7",
67-
"eslint": ">=4.18.2",
68-
"eslint-plugin-react": "^7.11.0",
69-
"file-loader": "^4.2.0",
64+
"eslint": "^8.56.0",
65+
"eslint-plugin-react": "^7.37.5",
7066
"idempotent-babel-polyfill": "6.26.0-1",
7167
"identity-obj-proxy": "^3.0.0",
72-
"jest": "^23.6.0",
68+
"jest": "^29.7.0",
7369
"jquery": "1.12.1",
7470
"lodash": "^4.17.5",
7571
"mem": ">=4.0.0",
7672
"node-fetch": "^2.6.0",
7773
"prettier": "1.16.1",
74+
"process": "^0.11.10",
7875
"query-string": "4.1.0",
7976
"radium": "^0.25.2",
8077
"react": "~16.14.0",
@@ -84,12 +81,12 @@
8481
"remark-parse": "^7.0.2",
8582
"remark-rehype": "^5.0.0",
8683
"sinon": "^7.5.0",
87-
"style-loader": "^1.0.0",
88-
"url-loader": "^2.2.0",
89-
"webpack": "4.19.1",
90-
"webpack-bundle-analyzer": "^3.6.0",
91-
"webpack-cli": "^3.3.6",
92-
"webpack-dev-server": "^3.1.4",
84+
"style-loader": "^2.0.0",
85+
"util": "^0.12.5",
86+
"webpack": "^5.94.0",
87+
"webpack-bundle-analyzer": "^4.10.0",
88+
"webpack-cli": "^5.1.4",
89+
"webpack-dev-server": "^4.15.2",
9390
"yargs": "^14.0.0"
9491
},
9592
"bugs": {
@@ -100,7 +97,7 @@
10097
"@fortawesome/fontawesome-svg-core": "^1.2.25",
10198
"@fortawesome/free-solid-svg-icons": "^5.11.2",
10299
"@fortawesome/react-fontawesome": "^0.1.7",
103-
"messageformat": "^1.1.0",
100+
"messageformat": "2.3.0",
104101
"react-typist": "^2.0.5"
105102
},
106103
"files": [

src/oceans/assetPath.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
global.__ml_activities_asset_public_path__ = './assets/';
2-
31
export const setAssetPath = (path) => {
4-
global.__ml_activities_asset_public_path__ = path;
2+
global.__desired_webpack_public_path__ = path;
53
};
4+
5+
// Sync webpack's internal public path (__webpack_require__.p) with the global.
6+
// This is needed when this bundle is nested inside another webpack bundle (e.g.
7+
// code-dot-org apps): webpack's automatic script-tag URL detection runs first
8+
// and sets __webpack_require__.p to the host bundle's path. By overriding it
9+
// here — before source files evaluate their module-level asset requires —
10+
// asset/resource URLs (sounds, model.json) resolve to the correct location.
11+
// Fall back to '/' for running locally.
12+
13+
/* eslint-disable-next-line no-undef */
14+
__webpack_public_path__ = global.__desired_webpack_public_path__ || '/';

test/unit/oceans/models/predict.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {TrashOceanObject} from '@ml/oceans/OceanObject';
88
describe('Predict test', () => {
99
beforeAll(() => {
1010
initFishData();
11-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
1211
});
1312

1413
beforeEach(() => {

test/unit/oceans/ui.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,7 @@ describe('Words', () => {
158158

159159
expect(() => {
160160
shallow(<Words {...DEFAULT_PROPS} />);
161-
}).toThrowError(
162-
new Error(
163-
"Could not find a set of choices in wordSet for appMode 'a-fake-one!'"
164-
)
165-
);
161+
}).toThrow("Could not find a set of choices in wordSet for appMode 'a-fake-one!'");
166162
});
167163

168164
describe('onChangeWord', () => {

test/unit/qualityTest.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
BodyShape
77
} = require('@ml/utils/fishData');
88
const {generateOcean, filterOcean} = require('@ml/utils/generateOcean');
9-
const SVMTrainer = require('@ml/utils/SVMTrainer');
9+
import SVMTrainer from '@ml/utils/SVMTrainer';
1010
import {AppMode, ClassType} from '@ml/oceans/constants';
1111
import {setState} from '@ml/oceans/state';
1212

test/unit/utils/SVMTrainer.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
BodyShape
77
} = require('@ml/utils/fishData');
88
const {generateOcean, filterOcean} = require('@ml/utils/generateOcean');
9-
const SVMTrainer = require('@ml/utils/SVMTrainer');
9+
import SVMTrainer from '@ml/utils/SVMTrainer';
1010
import {ClassType} from '@ml/oceans/constants';
1111

1212
const floatEquals = (a, b) => {

webpack.config.js

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ const commonConfig = {
1515
},
1616
output: {
1717
filename: '[name].js',
18-
libraryTarget: 'umd'
18+
library: {
19+
type: 'umd'
20+
}
1921
},
2022
module: {
2123
rules: [
2224
{
2325
test: /\.js$/,
2426
loader: 'babel-loader'
2527
},
26-
{test: /\.css$/, loader: 'style-loader!css-loader'},
28+
{test: /\.css$/, use: ['style-loader', 'css-loader']},
2729
{
2830
test: /\.jsx$/,
2931
enforce: 'pre',
@@ -32,49 +34,28 @@ const commonConfig = {
3234
{
3335
loader: 'babel-loader',
3436
options: {
35-
presets: ['react', 'env'],
36-
plugins: ['transform-class-properties']
37+
presets: ['@babel/preset-react', '@babel/preset-env'],
38+
plugins: ['@babel/plugin-transform-class-properties']
3739
}
3840
}
3941
]
4042
},
4143
{
4244
test: /\.(png|gif|svg)$/,
43-
loader: 'url-loader',
44-
options: {
45-
limit: 8192,
46-
outputPath: 'assets/images',
47-
publicPath: 'images',
48-
postTransformPublicPath: p =>
49-
`__ml_activities_asset_public_path__ + ${p}`,
50-
name: '[name].[ext]?[contenthash]'
51-
}
45+
type: 'asset/inline',
5246
},
5347
{
54-
type: 'javascript/auto',
48+
type: 'asset/resource',
5549
test: /src\/oceans\/model.json$/,
56-
use: [
57-
{
58-
loader: 'file-loader',
59-
options: {
60-
outputPath: 'assets/models',
61-
publicPath: 'models',
62-
postTransformPublicPath: p =>
63-
`__ml_activities_asset_public_path__ + ${p}`,
64-
name: '[name].[ext]?[contenthash]'
65-
}
66-
}
67-
]
50+
generator: {
51+
filename: 'models/[name][ext]?[contenthash]'
52+
}
6853
},
6954
{
7055
test: /\.(mp3|ogg|wav)$/,
71-
loader: 'file-loader',
72-
options: {
73-
outputPath: 'assets/sounds',
74-
publicPath: 'sounds',
75-
postTransformPublicPath: p =>
76-
`__ml_activities_asset_public_path__ + ${p}`,
77-
name: '[name].[ext]?[contenthash]'
56+
type: 'asset/resource',
57+
generator: {
58+
filename: 'sounds/[name][ext]?[contenthash]'
7859
}
7960
}
8061
]
@@ -85,19 +66,25 @@ const commonConfig = {
8566
},
8667
maxAssetSize: 300000,
8768
maxEntrypointSize: 10500000
88-
}
69+
},
70+
plugins: [
71+
new (require('webpack').ProvidePlugin)({
72+
process: 'process/browser'
73+
})
74+
]
8975
};
9076

9177
const firstConfigOnly = {
9278
plugins: [
9379
new CleanWebpackPlugin(),
94-
new CopyPlugin([
95-
{
96-
from: 'src/oceans/*.bin',
97-
to: 'assets/models/',
98-
flatten: true
99-
}
100-
])
80+
new CopyPlugin({
81+
patterns: [
82+
{
83+
from: 'src/oceans/*.bin',
84+
to: 'models/[name][ext]'
85+
}
86+
]
87+
})
10188
]
10289
};
10390

0 commit comments

Comments
 (0)