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

Converts webpack to rspack #201

Open
wants to merge 11 commits into
base: dev
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
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "16.x"
node-version: "18.x"

- name: Copy dist/index.js
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# production
/build
/dist/stats.json

# misc
.DS_Store
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ How to verify the signature: https://docs.near.org/build/web3-apps/backend/#3-ve
- Add get/set methods for `window.location.hash`. `Set` method only accepts an empty string as a value.

- Allow the wallet selector to connect to an extra contract besides `config.contractName`. To enable this feature, pass the allowExternalContract flag to the config parameter of initNear, e.g. `initNear({networkId, selector, config: { allowExternalContract: 'hello.near-examples.near' }} )`


- Use [rspack](https://rspack.dev/) for build and bundle rather than webpack
- Replace unsupported node-sass packages with recent packages and versions

## 2.6.1

Expand Down
2 changes: 1 addition & 1 deletion config/presets/loadPreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const loadPresets = (env = { presets: [] }) => {
/** @type {string[]} */
const mergedPresets = [].concat(...[presets]);
const mergedConfigs = mergedPresets.map((presetName) =>
require(`./webpack.${presetName}.js`)(env)
require(`./rspack.${presetName}.js`)(env)
);

return merge({}, ...mergedConfigs);
Expand Down
6 changes: 0 additions & 6 deletions config/presets/webpack.analyze.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const { HotModuleReplacementPlugin } = require("webpack");
const { HotModuleReplacementPlugin } = require("@rspack/core");

module.exports = () => ({
devtool: false,
Expand Down
26 changes: 4 additions & 22 deletions config/webpack.production.js → config/rspack.production.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const path = require("path");
const rspack = require("@rspack/core")

module.exports = () => {
return {
// output: {
// path: path.resolve(__dirname, "../dist"),
// publicPath: "./",
// // filename: "[name].[contenthash].bundle.js",
// filename: "index.js",
// },
devtool: false,
module: {
rules: [
// {
// test: /\.(css)$/,
// use: [MiniCssExtractPlugin.loader, "css-loader"],
// // options: {
// // sourceMap: false,
// // },
// },
{
test: /\.(scss|css)$/,
use: [
Expand Down Expand Up @@ -54,17 +39,14 @@ module.exports = () => {
],
},
plugins: [
new MiniCssExtractPlugin({
new rspack.CssExtractRspackPlugin({
filename: "styles/[name].[contenthash].css",
chunkFilename: "[id].css",
}),
})
],
optimization: {
minimize: true,
minimizer: [new CssMinimizerPlugin(), "..."],
// runtimeChunk: {
// name: "runtime",
// },
minimizer: [new rspack.LightningCssMinimizerRspackPlugin(), "..."],
},
performance: {
hints: false,
Expand Down
7 changes: 5 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions dist/index.js.LICENSE.txt

This file was deleted.

29 changes: 10 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,24 @@
"tweetnacl": "^1.0.3"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"babel-loader": "^9.1.2",
"@rspack/cli": "^1.0.0",
"@rspack/core": "^1.0.0",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^9.0.1",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",
"css-loader": "^6.2.0",
"css-minimizer-webpack-plugin": "^3.0.2",
"html-webpack-plugin": "^5.3.2",
"css-loader": "^7.1.2",
"https-browserify": "^1.0.0",
"mini-css-extract-plugin": "^2.2.2",
"near-api-js": "^2.1.3",
"node-sass": "^7.0.3",
"os-browserify": "^0.3.0",
"postcss-loader": "^7.0.1",
"postcss-loader": "^8.1.1",
"process": "^0.11.10",
"sass-loader": "^13.1.0",
"sass": "^1.77.2",
"sass-loader": "^14.2.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"style-loader": "^3.2.1",
"url": "^0.11.0",
"webpack": "^5.52.0",
"webpack-bundle-analyzer": "^4.4.2",
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.1.0",
"webpack-manifest-plugin": "^5.0.0",
"webpack-merge": "^5.8.0",
"webpack-node-externals": "^3.0.0"
},
Expand All @@ -104,8 +93,10 @@
"react-dom": "^18.2.0"
},
"scripts": {
"webpack": "webpack",
"prod": "npm run webpack -- --env mode=production",
"rspack": "rspack",
"dev": "npm run rspack build -- --env mode=development",
"prod": "npm run rspack build -- --env mode=production",
"prod:analyze": "npm run prod -- --analyze",
"build": "npm run prod"
},
"eslintConfig": {
Expand Down
31 changes: 20 additions & 11 deletions webpack.config.js → rspack.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const webpack = require("webpack");
const rspack = require("@rspack/core");
const paths = require("./config/paths");
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { merge } = require("webpack-merge");
const loadPreset = require("./config/presets/loadPreset");
const loadConfig = (mode) => require(`./config/webpack.${mode}.js`)(mode);
const loadConfig = (mode) => require(`./config/rspack.${mode}.js`)(mode);
const nodeExternals = require("webpack-node-externals");

module.exports = function (env) {
Expand Down Expand Up @@ -44,9 +44,22 @@ module.exports = function (env) {
},
},
{
test: /\.js$/,
use: ["babel-loader"],
exclude: path.resolve(__dirname, "node_modules"),
test: /\.(j|t)s$/,
exclude: [/[\\/]node_modules[\\/]/],
loader: "builtin:swc-loader",
options: {
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
},
externalHelpers: true,
},
env: {
targets: "Chrome >= 48",
},
},
type: 'javascript/auto',
},
// Images: Copy image files to build folder
{ test: /\.(?:ico|gif|png|jpg|jpeg)$/i, type: "asset/resource" },
Expand All @@ -65,13 +78,9 @@ module.exports = function (env) {
},
target: "node",
plugins: [
// new webpack.EnvironmentPlugin({
// // Configure environment variables here.
// ENVIRONMENT: "browser",
// }),
new CleanWebpackPlugin(),
new webpack.ProgressPlugin(),
new webpack.ProvidePlugin({
new rspack.ProgressPlugin(),
new rspack.ProvidePlugin({
process: "process/browser",
Buffer: [require.resolve("buffer/"), "Buffer"],
}),
Expand Down
Loading
Loading