-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Webpack + SWC Loader #1650
Merged
Merged
Webpack + SWC Loader #1650
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
83c89bc
desktopc-client swc-loader
joel-jeremy cf21896
More swc
joel-jeremy 3196b00
Jest swc + upgrades
joel-jeremy 76c6ac4
Revert @swc/jest usage for now
joel-jeremy 1ca370e
SWC minify
joel-jeremy 27ce75b
Remove setupFilesAfterEnv in package.json as per warning message in CI
joel-jeremy 32bf51c
Release notes
joel-jeremy 7e4a3fc
Minify on CI
joel-jeremy 61ec67d
swc helpers in loot-core
joel-jeremy 6041330
@swc/jest
joel-jeremy f039f54
Upgrade webpack
joel-jeremy b0eb430
Add @swc/core to crdt
joel-jeremy 9094c31
Use yarn cache in github actions
joel-jeremy 99e87a2
Cleanup
joel-jeremy 9461612
Fix electron
MatissJanis 094290c
Revert "Fix electron"
MatissJanis f8d0075
Revert action.yml cache changes
joel-jeremy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest/presets/js-with-ts-esm', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.(t|j)sx?$': '@swc/jest', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"jsc": { | ||
"target": "es2022", | ||
"transform": { | ||
"react": { | ||
"runtime": "automatic" | ||
} | ||
}, | ||
"externalHelpers": true, | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
const path = require('path'); | ||
|
||
const { | ||
loaderByName, | ||
removeLoaders, | ||
addAfterLoader, | ||
addPlugins, | ||
} = require('@craco/craco'); | ||
const chokidar = require('chokidar'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
const { IgnorePlugin } = require('webpack'); | ||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); | ||
|
||
if (process.env.CI) { | ||
process.env.DISABLE_ESLINT_PLUGIN = 'true'; | ||
} | ||
|
||
// Forward Netlify env variables | ||
if (process.env.REVIEW_ID) { | ||
process.env.REACT_APP_REVIEW_ID = process.env.REVIEW_ID; | ||
} | ||
|
||
module.exports = { | ||
webpack: { | ||
configure: (webpackConfig, { env, paths }) => { | ||
webpackConfig.mode = | ||
process.env.NODE_ENV === 'development' ? 'development' : 'production'; | ||
|
||
// swc-loader | ||
addAfterLoader(webpackConfig, loaderByName('babel-loader'), { | ||
test: /\.m?[tj]sx?$/, | ||
exclude: /node_modules/, | ||
loader: require.resolve('swc-loader'), | ||
}); | ||
|
||
// remove the babel loaders | ||
removeLoaders(webpackConfig, loaderByName('babel-loader')); | ||
|
||
addPlugins(webpackConfig, [ | ||
new BundleAnalyzerPlugin({ | ||
analyzerMode: 'disabled', | ||
generateStatsFile: true, | ||
}), | ||
// Pikaday throws a warning if Moment.js is not installed however it doesn't | ||
// actually require it to be installed. As we don't use Moment.js ourselves | ||
// then we can just silence this warning. | ||
new IgnorePlugin({ | ||
contextRegExp: /pikaday$/, | ||
resourceRegExp: /moment$/, | ||
}), | ||
]); | ||
|
||
webpackConfig.resolve.extensions = [ | ||
'.web.js', | ||
'.web.jsx', | ||
'.web.ts', | ||
'.web.tsx', | ||
'.js', | ||
'.jsx', | ||
'.ts', | ||
'.tsx', | ||
...webpackConfig.resolve.extensions, | ||
]; | ||
|
||
if (process.env.IS_GENERIC_BROWSER) { | ||
webpackConfig.resolve.extensions = [ | ||
'.browser.js', | ||
'.browser.jsx', | ||
'.browser.ts', | ||
'.browser.tsx', | ||
...webpackConfig.resolve.extensions, | ||
]; | ||
} | ||
|
||
webpackConfig.optimization = { | ||
...webpackConfig.optimization, | ||
minimize: | ||
process.env.CI === 'true' || process.env.NODE_ENV !== 'development', | ||
minimizer: [ | ||
new TerserPlugin({ | ||
minify: TerserPlugin.swcMinify, | ||
// `terserOptions` options will be passed to `swc` (`@swc/core`) | ||
// Link to options - https://swc.rs/docs/config-js-minify | ||
terserOptions: { | ||
compress: false, | ||
mangle: true, | ||
}, | ||
}), | ||
], | ||
}; | ||
|
||
return webpackConfig; | ||
}, | ||
}, | ||
devServer: (devServerConfig, { env, paths, proxy, allowedHost }) => { | ||
devServerConfig.onBeforeSetupMiddleware = server => { | ||
chokidar | ||
.watch([ | ||
path.resolve('../loot-core/lib-dist/*.js'), | ||
path.resolve('../loot-core/lib-dist/browser/*.js'), | ||
]) | ||
.on('all', function () { | ||
for (const ws of server.webSocketServer.clients) { | ||
ws.send(JSON.stringify({ type: 'static-changed' })); | ||
} | ||
}); | ||
}; | ||
devServerConfig.headers = { | ||
...devServerConfig.headers, | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
'Cross-Origin-Embedder-Policy': 'require-corp', | ||
}; | ||
|
||
return devServerConfig; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"jsc": { | ||
"target": "es2022", | ||
"externalHelpers": true, | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion:
react-scripts
can also be removed IMOThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Craco still uses react-scripts under the hood I believe: https://craco.js.org/docs/getting-started/