From 0bde68793c64d78db24be7e2db8e9a5a1ab14ab6 Mon Sep 17 00:00:00 2001 From: Yugang Cao <1442770751@qq.com> Date: Fri, 2 Aug 2024 21:15:33 +0800 Subject: [PATCH] docs: update readme (#278) --- README.md | 4 +- playground/rolldown/rolldown.config.js | 2 +- playground/rolldown/tsconfig.json | 26 ++--- playground/rspack/rspack.config.js | 138 +++++++++++++------------ src/core/unpluginContext.ts | 1 - 5 files changed, 85 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index 9db8d9a..2e4ee5b 100644 --- a/README.md +++ b/README.md @@ -144,9 +144,7 @@ Remove({ // filters for transforming targets include: [/\.[jt]sx?$/, /\.vue\??/], - exclude: [/node_modules/, /\.git/], - // transform source code - sourceMaps: true, + exclude: [/node_modules/, /\.git/] }) ``` diff --git a/playground/rolldown/rolldown.config.js b/playground/rolldown/rolldown.config.js index ed89401..7afb2d1 100644 --- a/playground/rolldown/rolldown.config.js +++ b/playground/rolldown/rolldown.config.js @@ -8,6 +8,6 @@ export default defineConfig({ sourcemap: true, }, plugins: [ - process.env.MODE === 'production' ? Rolldown({ sourceMaps: true }) : null, + process.env.MODE === 'production' ? Rolldown() : null, ].filter(Boolean), }) diff --git a/playground/rolldown/tsconfig.json b/playground/rolldown/tsconfig.json index 9476cde..c80a8d7 100644 --- a/playground/rolldown/tsconfig.json +++ b/playground/rolldown/tsconfig.json @@ -11,9 +11,12 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - "jsx": "preserve", /* Specify what JSX code is generated. */ + "jsx": "preserve", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + "baseUrl": "./", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ @@ -24,10 +27,10 @@ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "ESNext", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + "module": "ESNext", /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ @@ -67,7 +70,7 @@ // "newLine": "crlf", /* Set the newline character for emitting files. */ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - "noEmitOnError": false, /* Disable emitting files if any type checking errors are reported. */ + "noEmitOnError": false, /* Disable emitting files if any type checking errors are reported. */ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ @@ -76,12 +79,9 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ + "forceConsistentCasingInFileNames": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ @@ -103,7 +103,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, "include": ["src/**/*"] } diff --git a/playground/rspack/rspack.config.js b/playground/rspack/rspack.config.js index 4cfe509..6cce73b 100644 --- a/playground/rspack/rspack.config.js +++ b/playground/rspack/rspack.config.js @@ -1,72 +1,74 @@ -const rspack = require("@rspack/core"); -const refreshPlugin = require("@rspack/plugin-react-refresh"); -const isDev = process.env.NODE_ENV === "development"; -const RspackPlugin = require('unplugin-remove/rspack').default; +/* eslint-disable @typescript-eslint/no-var-requires */ +const rspack = require('@rspack/core') +const RefreshPlugin = require('@rspack/plugin-react-refresh') + +const isDev = process.env.NODE_ENV === 'development' +const RspackPlugin = require('unplugin-remove/rspack').default /** * @type {import('@rspack/cli').Configuration} */ module.exports = { - context: __dirname, - entry: { - main: "./src/main.tsx" - }, - resolve: { - extensions: ["...", ".ts", ".tsx", ".jsx"] - }, - devServer: { - port: 3000, - hot: true, - open: true - }, - module: { - rules: [ - { - test: /\.svg$/, - type: "asset" - }, - { - test: /\.(jsx?|tsx?)$/, - use: [ - { - loader: "builtin:swc-loader", - options: { - sourceMap: true, - jsc: { - parser: { - syntax: "typescript", - tsx: true - }, - transform: { - react: { - runtime: "automatic", - development: isDev, - refresh: isDev - } - } - }, - env: { - targets: [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14" - ] - } - } - } - ] - } - ] - }, - plugins: [ - new rspack.DefinePlugin({ - "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV) - }), - new rspack.ProgressPlugin({}), - new rspack.HtmlRspackPlugin({ - template: "./index.html" - }), - RspackPlugin(), - isDev ? new refreshPlugin() : null - ].filter(Boolean) -}; + context: __dirname, + entry: { + main: './src/main.tsx', + }, + resolve: { + extensions: ['...', '.ts', '.tsx', '.jsx'], + }, + devServer: { + port: 3000, + hot: true, + open: true, + }, + module: { + rules: [ + { + test: /\.svg$/, + type: 'asset', + }, + { + test: /\.(jsx?|tsx?)$/, + use: [ + { + loader: 'builtin:swc-loader', + options: { + sourceMap: true, + jsc: { + parser: { + syntax: 'typescript', + tsx: true, + }, + transform: { + react: { + runtime: 'automatic', + development: isDev, + refresh: isDev, + }, + }, + }, + env: { + targets: [ + 'chrome >= 87', + 'edge >= 88', + 'firefox >= 78', + 'safari >= 14', + ], + }, + }, + }, + ], + }, + ], + }, + plugins: [ + new rspack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), + }), + new rspack.ProgressPlugin({}), + new rspack.HtmlRspackPlugin({ + template: './index.html', + }), + RspackPlugin(), + isDev ? new RefreshPlugin() : null, + ].filter(Boolean), +} diff --git a/src/core/unpluginContext.ts b/src/core/unpluginContext.ts index d34415b..e53e7a5 100644 --- a/src/core/unpluginContext.ts +++ b/src/core/unpluginContext.ts @@ -18,7 +18,6 @@ export const createUnpluginContext = (options: Options = {}) => { } code = removeDebugger(code) const { generatorCode } = removeConsoleLogs(code, options.consoleType, true) - console.log('generatorCode', generatorCode, id) s = new MagicString(generatorCode) return { code: generatorCode,