Skip to content

Commit 2b8e8b7

Browse files
author
dbuchet
committed
Update craco.config to work with webpack5
1 parent c065035 commit 2b8e8b7

File tree

3 files changed

+24
-44
lines changed

3 files changed

+24
-44
lines changed

README.md

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,15 @@ The only differences with a traditional create-react-app application are :
88

99
Note that you should make sure your server serves `.wasm` files with the right mimetype, that is: `application/wasm`. Otherwise, you'll see the following error: `TypeError: Response has unsupported MIME type`
1010

11-
See [`src/App.js`](./src/App.js) for the code.
12-
13-
### [view the live demo](https://react-sqljs-demo.ophir.dev/)
14-
15-
## Using with Webpack 5
16-
Webpack 5 do not include nodejs polyfills by default, and you'll have to explicitely specify the file-loader for `wasm` file. So you'll need to update `craco.config.js` as below
17-
```js
18-
module.exports = {
19-
webpack: {
20-
configure: {
21-
module: {
22-
rules: [
23-
{
24-
test: /\.wasm$/,
25-
type: 'javascript/auto',
26-
use: [
27-
{ loader: 'file-loader' }
28-
]
29-
},
30-
},
31-
resolve: {
32-
fallback: {
33-
'path': require.resolve('path-browserify'),
34-
'crypto': require.resolve('crypto-browserify'),
35-
'stream': require.resolve('stream-browserify')
36-
}
37-
},
38-
},
39-
},
40-
};
41-
```
42-
And add the required module to your project
11+
Webpack 5 do not include nodejs polyfills by default, so you'll need to include them by adding them as dev dependency
4312
```
4413
npm install -D path-browserify crypto-browserify stream-browserify
4514
```
4615
or
4716
```
4817
yarn add -D path-browserify crypto-browserify stream-browserify
4918
```
19+
20+
See [`src/App.js`](./src/App.js) for the code.
21+
22+
### [view the live demo](https://react-sqljs-demo.ophir.dev/)

craco.config.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
module.exports = {
22
webpack: {
3-
configure:{
4-
// See https://github.com/webpack/webpack/issues/6725
5-
module:{
3+
configure: {
4+
module: {
65
rules: [{
76
test: /\.wasm$/,
87
type: 'javascript/auto',
9-
}]
10-
}
11-
}
12-
}
8+
use: [{ loader: 'file-loader' }]
9+
}],
10+
},
11+
resolve: {
12+
fallback: {
13+
'path': require.resolve('path-browserify'),
14+
'crypto': require.resolve('crypto-browserify'),
15+
'stream': require.resolve('stream-browserify')
16+
}
17+
},
18+
},
19+
},
1320
};

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
"main": "src/index.js",
1010
"license": "MIT",
1111
"dependencies": {
12-
"react": "^17.0.2",
13-
"react-dom": "^17.0.2",
14-
"sql.js": "^1.6.2"
12+
"react": "^18.2.0",
13+
"react-dom": "^18.2.0",
14+
"sql.js": "^1.8.0"
1515
},
1616
"devDependencies": {
17-
"@craco/craco": "^5.9.0",
18-
"typescript": "^4.5.5"
17+
"@craco/craco": "^7.0.0",
18+
"typescript": "^4.9.4"
1919
},
2020
"scripts": {
2121
"start": "craco start",

0 commit comments

Comments
 (0)