From c02c56ef90403dd7bff8639debf812a7e8314e66 Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Thu, 24 Aug 2023 22:01:32 +0800 Subject: [PATCH] refactor: dropped babel The `babel-loader` was replaced by `esbuild-loader`, providing a modern fast transformation experience. Babel deps were removed, leaving `@babel/parser` and `@babel/traverse` for attributes extraction of page component. BREAKING CHANGE: babel loader was removed. Signed-off-by: Chawye Hsu --- packages/saber/babel.js | 1 - packages/saber/package.json | 11 +- packages/saber/src/babel/preset.js | 72 -- .../src/plugins/transformer-components.ts | 24 +- ...{parseAttributes.js => parseAttributes.ts} | 31 +- packages/saber/src/webpack/babel-loader.js | 73 -- packages/saber/src/webpack/webpack.config.ts | 12 +- yarn.lock | 855 +++++------------- 8 files changed, 245 insertions(+), 834 deletions(-) delete mode 100644 packages/saber/babel.js delete mode 100644 packages/saber/src/babel/preset.js rename packages/saber/src/utils/{parseAttributes.js => parseAttributes.ts} (64%) delete mode 100644 packages/saber/src/webpack/babel-loader.js diff --git a/packages/saber/babel.js b/packages/saber/babel.js deleted file mode 100644 index 10fb93abb..000000000 --- a/packages/saber/babel.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./dist/babel/preset') diff --git a/packages/saber/package.json b/packages/saber/package.json index 4d3953171..949e2e27d 100644 --- a/packages/saber/package.json +++ b/packages/saber/package.json @@ -3,7 +3,6 @@ "version": "0.11.7", "description": "A simple yet powerful static site generator", "files": [ - "/babel.js", "/types", "/dist", "/vue-app", @@ -21,15 +20,10 @@ "types": "types/index.d.ts", "license": "MIT", "dependencies": { - "@babel/core": "^7.5.4", - "@babel/plugin-proposal-object-rest-spread": "^7.5.4", - "@babel/plugin-syntax-dynamic-import": "^7.2.0", - "@babel/plugin-transform-runtime": "^7.5.0", - "@babel/preset-env": "^7.5.4", - "@babel/runtime": "^7.5.4", + "@babel/parser": "^7.22.11", + "@babel/traverse": "^7.22.11", "@egoist/postcss-loader": "^3.0.2", "@intervolga/optimize-cssnano-plugin": "^1.0.6", - "babel-loader": "8.3.0", "cac": "^6.5.1", "cache-loader": "^4.1.0", "chokidar": "^3.5.3", @@ -37,6 +31,7 @@ "cssnano": "^4.1.8", "devalue": "^2.0.0", "download-git-repo": "^2.0.0", + "esbuild-loader": "^4.0.1", "fast-deep-equal": "^2.0.1", "file-loader": "^6.2.0", "get-port": "^5.0.0", diff --git a/packages/saber/src/babel/preset.js b/packages/saber/src/babel/preset.js deleted file mode 100644 index 2c1c7144d..000000000 --- a/packages/saber/src/babel/preset.js +++ /dev/null @@ -1,72 +0,0 @@ -const path = require('path') - -const env = process.env.BABEL_ENV || process.env.NODE_ENV -const isEnvTest = env === 'test' - -module.exports = (_, { isServer } = {}) => { - const presets = [ - [ - require('@babel/preset-env'), - isEnvTest || isServer - ? { - targets: { - node: 'current' - } - } - : { - modules: false, - // If users import all core-js they're probably not concerned with - // bundle size. We shouldn't rely on magic to try and shrink it. - useBuiltIns: false, - // Exclude transforms that make all code slower - exclude: ['transform-typeof-symbol'] - } - ] - ] - - const plugins = [ - require('@babel/plugin-syntax-dynamic-import'), - [ - require('@babel/plugin-proposal-object-rest-spread'), - { - useBuiltIns: true - } - ], - // Polyfills the runtime needed for async/await, generators, and friends - // https://babeljs.io/docs/en/babel-plugin-transform-runtime - [ - require('@babel/plugin-transform-runtime').default, - { - corejs: false, - helpers: false, - regenerator: true, - // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules - // We should turn this on once the lowest version of Node LTS - // supports ES Modules. - useESModules: false, - // Undocumented option that lets us encapsulate our runtime, ensuring - // the correct version is used - // https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42 - absoluteRuntime: path.dirname( - require.resolve('@babel/runtime/package.json') - ) - } - ], - function() { - return { - visitor: { - StringLiteral(path) { - if (path.node.value.endsWith('egoist is baka baka baka')) { - path.node.value += '!!' - } - } - } - } - } - ] - - return { - presets, - plugins - } -} diff --git a/packages/saber/src/plugins/transformer-components.ts b/packages/saber/src/plugins/transformer-components.ts index 9404f0c78..61f017024 100644 --- a/packages/saber/src/plugins/transformer-components.ts +++ b/packages/saber/src/plugins/transformer-components.ts @@ -1,6 +1,8 @@ import { slash } from 'saber-utils' +import { parseComponent } from 'vue-template-compiler' import { SaberPlugin } from '..' import { Page } from '../Pages' +import parseAttributes from '../utils/parseAttributes' const getPageComponent = (page: Page) => { return `