Init
This commit is contained in:
22
node_modules/@prefresh/vite/LICENSE
generated
vendored
Normal file
22
node_modules/@prefresh/vite/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020-2021 Jovi De Croock
|
||||
Copyright (c) 2021-Present Preact Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
56
node_modules/@prefresh/vite/README.md
generated
vendored
Normal file
56
node_modules/@prefresh/vite/README.md
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
# Prefresh-vite
|
||||
|
||||
[](https://www.npmjs.com/package/@prefresh/vite)
|
||||
|
||||
## Setup
|
||||
|
||||
```
|
||||
npm i -s @prefresh/vite
|
||||
## OR
|
||||
yarn add @prefresh/vite
|
||||
```
|
||||
|
||||
Then add it to your `vite.config.js` config:
|
||||
|
||||
```js
|
||||
import prefresh from '@prefresh/vite';
|
||||
|
||||
export default {
|
||||
plugins: [prefresh()],
|
||||
};
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
The plugin accepts two options `include` & `exclude` which are used in the [`@rollup/pluginutils.createFilter`](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) to filter out files or include them.
|
||||
|
||||
The plugin also accepts the addition of [`parserPlugins`](https://babeljs.io/docs/en/babel-parser#plugins)
|
||||
|
||||
## Best practices
|
||||
|
||||
### Recognition
|
||||
|
||||
We need to be able to recognise your components, this means that components should
|
||||
start with a capital letter and hook should start with `use` followed by a capital letter.
|
||||
This allows the Babel plugin to effectively recognise these.
|
||||
|
||||
Do note that a component as seen below is not named.
|
||||
|
||||
```jsx
|
||||
export default () => {
|
||||
return <p>Want to refresh</p>;
|
||||
};
|
||||
```
|
||||
|
||||
Instead do:
|
||||
|
||||
```jsx
|
||||
const Refresh = () => {
|
||||
return <p>Want to refresh</p>;
|
||||
};
|
||||
|
||||
export default Refresh;
|
||||
```
|
||||
|
||||
When you are working with HOC's be sure to lift up the `displayName` so we can
|
||||
recognise it as a component.
|
12
node_modules/@prefresh/vite/index.d.ts
generated
vendored
Normal file
12
node_modules/@prefresh/vite/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { FilterPattern } from '@rollup/pluginutils';
|
||||
import { Plugin } from 'vite';
|
||||
|
||||
interface Options {
|
||||
parserPlugins?: readonly string[];
|
||||
include?: FilterPattern;
|
||||
exclude?: FilterPattern;
|
||||
}
|
||||
|
||||
declare const prefreshPlugin: (options?: Options) => Plugin;
|
||||
|
||||
export = prefreshPlugin;
|
55
node_modules/@prefresh/vite/package.json
generated
vendored
Normal file
55
node_modules/@prefresh/vite/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "@prefresh/vite",
|
||||
"version": "2.4.7",
|
||||
"main": "src/index.js",
|
||||
"types": "index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"require": "./src/index.js",
|
||||
"import": "./src/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"modes": {
|
||||
"default": "src/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"runtime",
|
||||
"utils",
|
||||
"index.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/preactjs/prefresh.git",
|
||||
"directory": "packages/vite"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/preactjs/prefresh/issues"
|
||||
},
|
||||
"homepage": "https://github.com/preactjs/prefresh#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.22.1",
|
||||
"@prefresh/babel-plugin": "0.5.1",
|
||||
"@prefresh/core": "^1.5.1",
|
||||
"@prefresh/utils": "^1.2.0",
|
||||
"@rollup/pluginutils": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"preact": "^10.15.1",
|
||||
"vite": "^5.0.13"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"preact": "^10.4.0",
|
||||
"vite": ">=2.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"provenance": true
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint src",
|
||||
"test": "jest --clearCache && jest --runInBand --forceExit --detectOpenHandles"
|
||||
}
|
||||
}
|
117
node_modules/@prefresh/vite/src/index.js
generated
vendored
Normal file
117
node_modules/@prefresh/vite/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
const { transformSync } = require('@babel/core');
|
||||
const { createFilter } = require('@rollup/pluginutils');
|
||||
const prefreshBabelPlugin = require('@prefresh/babel-plugin');
|
||||
|
||||
/** @returns {import('vite').Plugin} */
|
||||
module.exports = function prefreshPlugin(options = {}) {
|
||||
let shouldSkip = false;
|
||||
const filter = createFilter(options.include, options.exclude);
|
||||
|
||||
return {
|
||||
name: 'prefresh',
|
||||
configResolved(config) {
|
||||
shouldSkip = config.isProduction || config.command === 'build' || config.server.hmr === false;
|
||||
},
|
||||
async transform(code, id, options) {
|
||||
const ssr =
|
||||
typeof options === 'boolean'
|
||||
? options
|
||||
: options && options.ssr === true;
|
||||
if (
|
||||
shouldSkip ||
|
||||
!/\.(c|m)?(t|j)sx?$/.test(id) ||
|
||||
id.includes('node_modules') ||
|
||||
id.includes('?worker') ||
|
||||
!filter(id) ||
|
||||
ssr
|
||||
)
|
||||
return;
|
||||
|
||||
const parserPlugins = [
|
||||
'jsx',
|
||||
'classProperties',
|
||||
'classPrivateProperties',
|
||||
'classPrivateMethods',
|
||||
/\.tsx?$/.test(id) && 'typescript',
|
||||
...((options && options.parserPlugins) || []),
|
||||
].filter(Boolean);
|
||||
|
||||
const result = transform(code, id, parserPlugins);
|
||||
const hasReg = /\$RefreshReg\$\(/.test(result.code);
|
||||
const hasSig = /\$RefreshSig\$\(/.test(result.code);
|
||||
|
||||
if (!hasSig && !hasReg) return code;
|
||||
|
||||
const prefreshCore = await this.resolve('@prefresh/core', __filename);
|
||||
const prefreshUtils = await this.resolve('@prefresh/utils', __filename);
|
||||
|
||||
const prelude = `
|
||||
${'import'} ${JSON.stringify(prefreshCore.id)};
|
||||
${'import'} { flush as flushUpdates } from ${JSON.stringify(
|
||||
prefreshUtils.id
|
||||
)};
|
||||
|
||||
let prevRefreshReg;
|
||||
let prevRefreshSig;
|
||||
|
||||
if (import.meta.hot) {
|
||||
prevRefreshReg = self.$RefreshReg$ || (() => {});
|
||||
prevRefreshSig = self.$RefreshSig$ || (() => (type) => type);
|
||||
|
||||
self.$RefreshReg$ = (type, id) => {
|
||||
self.__PREFRESH__.register(type, ${JSON.stringify(id)} + " " + id);
|
||||
};
|
||||
|
||||
self.$RefreshSig$ = () => {
|
||||
let status = 'begin';
|
||||
let savedType;
|
||||
return (type, key, forceReset, getCustomHooks) => {
|
||||
if (!savedType) savedType = type;
|
||||
status = self.__PREFRESH__.sign(type || savedType, key, forceReset, getCustomHooks, status);
|
||||
return type;
|
||||
};
|
||||
};
|
||||
}
|
||||
`.replace(/[\n]+/gm, '');
|
||||
|
||||
if (hasSig && !hasReg) {
|
||||
return {
|
||||
code: `${prelude}${result.code}`,
|
||||
map: result.map,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
code: `${prelude}${result.code}
|
||||
|
||||
if (import.meta.hot) {
|
||||
self.$RefreshReg$ = prevRefreshReg;
|
||||
self.$RefreshSig$ = prevRefreshSig;
|
||||
import.meta.hot.accept((m) => {
|
||||
try {
|
||||
flushUpdates();
|
||||
} catch (e) {
|
||||
self.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
`,
|
||||
map: result.map,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const transform = (code, path, plugins) =>
|
||||
transformSync(code, {
|
||||
plugins: [[prefreshBabelPlugin, { skipEnvCheck: true }]],
|
||||
parserOpts: {
|
||||
plugins,
|
||||
},
|
||||
ast: false,
|
||||
sourceMaps: true,
|
||||
filename: path,
|
||||
sourceFileName: path,
|
||||
configFile: false,
|
||||
babelrc: false,
|
||||
});
|
Reference in New Issue
Block a user