Skip to content

Commit

Permalink
Use SWC instead of Babel
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Aug 1, 2024
1 parent 98baabc commit 7288d8e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"target": "esnext",
"verbatimModuleSyntax": true,
"useDefineForClassFields": true,
"skipLibCheck": true,
"skipLibCheck": true
},
"include": ["./"],
"exclude": ["node_modules", "dist"]
Expand Down
2 changes: 0 additions & 2 deletions programs/develop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"style-loader": "^3.3.4",
"swc-loader": "^0.2.6",
"tiny-glob": "^0.2.9",
"ts-loader": "^9.5.1",
"webpack": "~5.92.0",
"webpack-browser-extension-resolve": "*",
"webpack-dev-server": "^5.0.2"
Expand Down Expand Up @@ -88,7 +87,6 @@
"stylelint": "^16.7.0",
"stylelint-config-standard-scss": "^13.1.0",
"stylelint-webpack-plugin": "^5.0.1",
"ts-loader": "^9.5.1",
"typescript": "5.3.3",
"vue-loader": "^17.4.2",
"vue-style-loader": "^4.1.3",
Expand Down
35 changes: 31 additions & 4 deletions programs/develop/webpack/plugin-js-frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,46 @@ export class JsFrameworksPlugin {
const maybeInstallVue = await maybeUseVue(compiler, projectPath)

compiler.options.resolve.alias = {
...compiler.options.resolve.alias,
...(maybeInstallBabel?.alias || {}),
...(maybeInstallReact?.alias || {}),
...(maybeInstallPreact?.alias || {}),
...(maybeInstallVue?.alias || {})
...(maybeInstallVue?.alias || {}),
...compiler.options.resolve.alias
}

compiler.options.module.rules = [
...compiler.options.module.rules,
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: require.resolve('swc-loader'),
options: {
module: {
type: 'es6'
},
minify: this.mode === 'production',
isModule: true,
jsc: {
target: 'es2016',
parser: {
syntax: 'typescript',
tsx: true,
dynamicImport: true
},
transform: {
react: {
runtime: 'automatic'
}
}
}
}
}
},
...(maybeInstallBabel?.loaders || []),
...(maybeInstallReact?.loaders || []),
...(maybeInstallPreact?.loaders || []),
...(maybeInstallVue?.loaders || [])
...(maybeInstallVue?.loaders || []),
...compiler.options.module.rules
].filter(Boolean)

maybeInstallReact?.plugins?.forEach((plugin) => plugin.apply(compiler))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export function defaultTypeScriptConfig(projectPath: string, _opts?: any) {
target: 'esnext',
// Ensure each file can be safely transpiled without relying
// on other imports
isolatedModules: false
isolatedModules: false,
skipLibCheck: true
},
exclude: ['node_modules', 'dist']
}
Expand Down Expand Up @@ -168,7 +169,7 @@ export async function maybeUseTypeScript(
try {
require.resolve('typescript')
} catch (e) {
const typescriptDependencies = ['typescript', 'ts-loader']
const typescriptDependencies = ['typescript']

await installOptionalDependencies('TypeScript', typescriptDependencies)

Expand Down
19 changes: 2 additions & 17 deletions programs/develop/webpack/plugin-js-frameworks/js-tools/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function maybeUseVue(
try {
require.resolve('vue-loader')
} catch (e) {
const typeScriptDependencies = ['typescript', 'ts-loader']
const typeScriptDependencies = ['typescript']

await installOptionalDependencies('TypeScript', typeScriptDependencies)

Expand All @@ -72,25 +72,10 @@ export async function maybeUseVue(
{
test: /\.vue$/,
loader: 'vue-loader',
include: path.resolve(__dirname, 'src')
include: projectPath
}
]

// use vue and typescript, need to add ts-loader
if (isUsingTypeScript(projectPath)) {
vueLoaders.push({
test: /\.ts?$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
// Skip type checking
transpileOnly: true
}
})
}

// const {VueLoaderPlugin} = require('vue-loader')
// new VueLoaderPlugin().apply(compiler)
const vuePlugins: JsFramework['plugins'] = [
new (require('vue-loader').VueLoaderPlugin)() //.apply(compiler)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ function patchWebResourcesV2(manifest: Manifest) {
}

function patchWebResourcesV3(manifest: Manifest) {
const defaultResources = ['/*.json', '/*.js', '/*.css']
const defaultResources = ['/*.json', '/*.js', '/*.css']
return [
...manifest.web_accessible_resources || [],
...(manifest.web_accessible_resources || []),
{
resources: defaultResources,
matches: ['<all_urls>']
Expand Down
19 changes: 4 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4875,7 +4875,7 @@ encodeurl@~1.0.2:
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
integrity sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==

enhanced-resolve@^5.0.0, enhanced-resolve@^5.17.0:
enhanced-resolve@^5.17.0:
version "5.17.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz#67bfbbcc2f81d511be77d686a90267ef7f898a15"
integrity sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==
Expand Down Expand Up @@ -7569,7 +7569,7 @@ methods@~1.1.2:
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==

micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5, micromatch@^4.0.7:
micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5, micromatch@^4.0.7:
version "4.0.7"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.7.tgz#33e8190d9fe474a9895525f5618eee136d46c2e5"
integrity sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==
Expand Down Expand Up @@ -9135,7 +9135,7 @@ semver@^6.3.0, semver@^6.3.1:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.0.0, semver@^7.3.4, semver@^7.5.3, semver@^7.5.4:
semver@^7.0.0, semver@^7.5.3, semver@^7.5.4:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==
Expand Down Expand Up @@ -9367,7 +9367,7 @@ [email protected]:
dependencies:
whatwg-url "^7.0.0"

source-map@^0.7.3, source-map@^0.7.4:
source-map@^0.7.3:
version "0.7.4"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656"
integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==
Expand Down Expand Up @@ -9939,17 +9939,6 @@ ts-jest@^29.1.2:
semver "^7.5.3"
yargs-parser "^21.0.1"

ts-loader@^9.5.1:
version "9.5.1"
resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.5.1.tgz#63d5912a86312f1fbe32cef0859fb8b2193d9b89"
integrity sha512-rNH3sK9kGZcH9dYzC7CewQm4NtxJTjSEVRJ2DyBZR7f8/wcta+iV44UPCXc5+nzDzivKtlzV6c9P4e+oFhDLYg==
dependencies:
chalk "^4.1.0"
enhanced-resolve "^5.0.0"
micromatch "^4.0.0"
semver "^7.3.4"
source-map "^0.7.4"

ts-node@^10.9.2:
version "10.9.2"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f"
Expand Down

0 comments on commit 7288d8e

Please sign in to comment.