@crxjs/vite-plugin 1.0.8 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @crxjs/vite-plugin
2
2
 
3
+ ## 1.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - dc479d1: Fix global constant replacement in background
8
+
9
+ ## 1.0.10
10
+
11
+ ### Patch Changes
12
+
13
+ - f35c49e: Update READMEs
14
+
15
+ ## 1.0.9
16
+
17
+ ### Patch Changes
18
+
19
+ - 8941353: Remove & refactor use of fs-extra
20
+
3
21
  ## 1.0.8
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -1,74 +1,30 @@
1
- # [rollup-plugin-chrome-extension](https://www.extend-chrome.dev/rollup-plugin)
1
+ # ![CRXJS](./banner-github.png)
2
2
 
3
- [![npm (scoped)](https://img.shields.io/npm/v/rollup-plugin-chrome-extension/beta.svg)](https://www.npmjs.com/package/rollup-plugin-chrome-extension)
4
- [![GitHub last commit](https://img.shields.io/github/last-commit/crxjs/rollup-plugin-chrome-extension.svg?logo=github)](https://github.com/crxjs/rollup-plugin-chrome-extension)
5
- ![GitHub action badge](https://github.com/crxjs/rollup-plugin-chrome-extension/actions/workflows/vite-plugin.yml/badge.svg)
6
- [![TypeScript Declarations Included](https://img.shields.io/badge/types-TypeScript-informational)](#typescript)
3
+ [![npm (scoped)](https://img.shields.io/npm/v/rollup-plugin-chrome-extension.svg)](https://www.npmjs.com/package/rollup-plugin-chrome-extension)
4
+ [![GitHub last commit](https://img.shields.io/github/last-commit/crxjs/chrome-extension-tools.svg?logo=github)](https://github.com/crxjs/rollup-plugin-chrome-extension)
5
+ ![GitHub action badge](https://github.com/crxjs/chrome-extension-tools/actions/workflows/vite-plugin.yml/badge.svg)
7
6
 
8
- <a href="https://www.extend-chrome.dev/rollup-plugin" rel="noopener">
9
- <img width=200px height=200px src="https://imgur.com/wEXnCYK.png" alt="rollup-plugin-chrome-extension logo"></a>
7
+ ## CRXJS Vite Plugin
10
8
 
11
- The bundler configuration for a Chrome Extension can be pretty complex. This
12
- plugin makes it simple.
9
+ > Build a Chrome Extension with [Vite](https://vitejs.dev)⚡
13
10
 
14
- The manifest is front and center. Import your manifest to your config file and
15
- RPCE will do the rest.
11
+ CRXJS brings the Vite developer experience to Chrome Extensions:
16
12
 
17
- RPCE simplifies project config and supports many of Vite's features in the
18
- Chrome Extension environment, including HMR.
13
+ - True HMR for extension pages and content scripts
14
+ - Simple config - everything is in the extension manifest
15
+ - Static asset imports with automatic web-accessible resources
19
16
 
20
- ## Vite Usage (beta)
17
+ ## Getting Started
21
18
 
22
- Vite support is in beta! Check out this
23
- [90 second getting started guide](https://dev.to/jacksteamdev/create-a-vite-react-chrome-extension-in-90-seconds-3df7).
19
+ See the CRXJS documentation to
20
+ [get started in 90 seconds 🚀](https://crxjs.dev/vite-plugin)
24
21
 
25
- ```sh
26
- npm i rollup-plugin-chrome-extension@beta -D
27
- ```
22
+ ## Supporting
28
23
 
29
- ```javascript
30
- // vite.config.js
31
-
32
- import { defineConfig } from 'vite'
33
- import react from '@vitejs/plugin-react'
34
- import { crx } from 'rollup-plugin-chrome-extension'
35
- import manifest from './manifest.json'
36
-
37
- export default defineConfig({
38
- plugins: [react(), crx({ manifest })],
39
- })
40
- ```
41
-
42
- Just add new features to your manifest, and RPCE does the rest.
43
-
44
- ## [Documentation for v3](https://www.extend-chrome.dev/rollup-plugin)
45
-
46
- We have
47
- [v3 boilerplates](https://www.extend-chrome.dev/rollup-plugin#chrome-extension-boilerplates)
48
- for [React JavaScript](https://github.com/crxjs/js-react-boilerplate),
49
- [React TypeScript](https://github.com/crxjs/ts-react-boilerplate) and
50
- [Svelte](https://github.com/kyrelldixon/svelte-tailwind-extension-boilerplate),
51
- as well as [instructions](https://www.extend-chrome.dev/rollup-plugin#usage) for
52
- setting up your project.
53
-
54
- See the [documentation](https://www.extend-chrome.dev/rollup-plugin) for usage
55
- and how to get started.
24
+ If these plugins have helped you ship your product faster, please consider
25
+ [sponsoring me](https://github.com/sponsors/jacksteamdev) on GitHub.
56
26
 
57
27
  ## Contributing
58
28
 
59
- Your help is super welcome!
60
-
61
- 🎯 Ongoing development is for v4+ only.
62
-
63
- 👀 Be sure to take a look at the issues before starting to work on a new
64
- feature.
65
-
66
- 🙏 Please update the tests to cover bug fixes or new features.
67
-
68
- 📕 Documentation for v4 has not yet begun, but you can open an issue for help.
69
-
70
- ✨ If you enjoy using RPCE, please help spread the word!
71
-
72
- ## Development
73
-
74
- This monorepo uses [pnpm](https://pnpm.io/).
29
+ We encourage pull requests! This is a
30
+ [pnpm monorepo](https://pnpm.io/workspaces), so use pnpm instead of Yarn or npm.
package/dist/index.cjs CHANGED
@@ -8,16 +8,16 @@ var crypto = require('crypto');
8
8
  var debug$5 = require('debug');
9
9
  var fg = require('fast-glob');
10
10
  var v8 = require('v8');
11
- var fsExtra = require('fs-extra');
11
+ var fs = require('fs');
12
12
  var MagicString = require('magic-string');
13
13
  var path = require('path');
14
+ var fsExtra = require('fs-extra');
14
15
  var perf_hooks = require('perf_hooks');
15
16
  var colors = require('picocolors');
16
17
  var vite = require('vite');
17
18
  var module$1 = require('module');
18
19
  var cheerio = require('cheerio');
19
20
  var jsesc = require('jsesc');
20
- var fs = require('fs');
21
21
  var injector = require('connect-injector');
22
22
 
23
23
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -43,8 +43,8 @@ function _interopNamespace(e) {
43
43
  var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug$5);
44
44
  var fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
45
45
  var v8__default = /*#__PURE__*/_interopDefaultLegacy(v8);
46
- var fsExtra__default = /*#__PURE__*/_interopDefaultLegacy(fsExtra);
47
46
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
47
+ var fsExtra__default = /*#__PURE__*/_interopDefaultLegacy(fsExtra);
48
48
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
49
49
  var jsesc__default = /*#__PURE__*/_interopDefaultLegacy(jsesc);
50
50
  var injector__default = /*#__PURE__*/_interopDefaultLegacy(injector);
@@ -218,6 +218,7 @@ const preambleId = "/crx-client-preamble";
218
218
  const stubId = "/crx-stub";
219
219
  const workerClientId = "/crx-client-worker";
220
220
 
221
+ const { readFile: readFile$2 } = fs.promises;
221
222
  const debug$4 = _debug("file-writer").extend("chunks");
222
223
  for (const source of [viteClientId, customElementsId]) {
223
224
  setUrlMeta(sourceToUrlMeta(source));
@@ -292,7 +293,7 @@ const pluginFileWriterChunks = () => {
292
293
  this.emitFile({
293
294
  type: "asset",
294
295
  fileName: relative(server.config.root, file),
295
- source: await fsExtra.readFile(file)
296
+ source: await readFile$2(file)
296
297
  });
297
298
  }
298
299
  if (url)
@@ -2304,6 +2305,7 @@ const pluginFileWriterHtml = () => {
2304
2305
  };
2305
2306
  };
2306
2307
 
2308
+ const { readFile: readFile$1 } = fs.promises;
2307
2309
  const pluginFileWriterPublic = () => {
2308
2310
  let config;
2309
2311
  return {
@@ -2317,7 +2319,7 @@ const pluginFileWriterPublic = () => {
2317
2319
  this.addWatchFile(config.publicDir);
2318
2320
  const publicFiles = await fg__default["default"](`${config.publicDir}/**/*`);
2319
2321
  for (const file of publicFiles) {
2320
- const source = await fsExtra.readFile(file);
2322
+ const source = await readFile$1(file);
2321
2323
  const fileName = relative(config.publicDir, file);
2322
2324
  this.emitFile({ type: "asset", fileName, source });
2323
2325
  }
@@ -2328,8 +2330,8 @@ const pluginFileWriterPublic = () => {
2328
2330
 
2329
2331
  const _require = typeof require === "undefined" ? module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))) : require;
2330
2332
  const customElementsPath = _require.resolve(customElementsId);
2331
- const customElementsCode = fsExtra.readFileSync(customElementsPath, "utf8");
2332
- const customElementsMap = fsExtra.readFileSync(`${customElementsPath}.map`, "utf8");
2333
+ const customElementsCode = fs.readFileSync(customElementsPath, "utf8");
2334
+ const customElementsMap = fs.readFileSync(`${customElementsPath}.map`, "utf8");
2333
2335
  const pluginFileWriterPolyfill = () => {
2334
2336
  return {
2335
2337
  name: "crx:file-writer-polyfill",
@@ -2772,6 +2774,7 @@ const pluginHtmlAuditor = () => {
2772
2774
  };
2773
2775
  };
2774
2776
 
2777
+ const { readFile } = fs.promises;
2775
2778
  const pluginManifest = (_manifest) => () => {
2776
2779
  let manifest;
2777
2780
  let plugins;
@@ -2980,7 +2983,7 @@ Public dir: "${config.publicDir}"`);
2980
2983
  this.emitFile({
2981
2984
  type: "asset",
2982
2985
  fileName: f,
2983
- source: await fsExtra.readFile(filename)
2986
+ source: await readFile(filename)
2984
2987
  });
2985
2988
  }
2986
2989
  }));
@@ -3509,7 +3512,9 @@ const pluginBackground = () => {
3509
3512
  if (this.meta.watchMode) {
3510
3513
  if (typeof port === "undefined")
3511
3514
  throw new Error("server port is undefined in watch mode");
3512
- loader = `import 'http://localhost:${port}${workerClientId}';
3515
+ loader = `import 'http:/localhost:${port}/@vite/env';
3516
+ `;
3517
+ loader += `import 'http://localhost:${port}${workerClientId}';
3513
3518
  `;
3514
3519
  if (worker)
3515
3520
  loader += `import 'http://localhost:${port}/${worker}';
package/dist/index.mjs CHANGED
@@ -4,16 +4,16 @@ import { createHash as createHash$1 } from 'crypto';
4
4
  import debug$5 from 'debug';
5
5
  import fg from 'fast-glob';
6
6
  import v8 from 'v8';
7
- import fsExtra, { readFile, readFileSync } from 'fs-extra';
7
+ import { promises, readFileSync, existsSync } from 'fs';
8
8
  import MagicString from 'magic-string';
9
9
  import { posix } from 'path';
10
+ import fsExtra from 'fs-extra';
10
11
  import { performance } from 'perf_hooks';
11
12
  import colors from 'picocolors';
12
13
  import { createLogger } from 'vite';
13
14
  import { createRequire } from 'module';
14
15
  import { load } from 'cheerio';
15
16
  import jsesc from 'jsesc';
16
- import { existsSync } from 'fs';
17
17
  import injector from 'connect-injector';
18
18
 
19
19
  const _debug = (id) => debug$5("crx").extend(id);
@@ -185,6 +185,7 @@ const preambleId = "/crx-client-preamble";
185
185
  const stubId = "/crx-stub";
186
186
  const workerClientId = "/crx-client-worker";
187
187
 
188
+ const { readFile: readFile$2 } = promises;
188
189
  const debug$4 = _debug("file-writer").extend("chunks");
189
190
  for (const source of [viteClientId, customElementsId]) {
190
191
  setUrlMeta(sourceToUrlMeta(source));
@@ -259,7 +260,7 @@ const pluginFileWriterChunks = () => {
259
260
  this.emitFile({
260
261
  type: "asset",
261
262
  fileName: relative(server.config.root, file),
262
- source: await readFile(file)
263
+ source: await readFile$2(file)
263
264
  });
264
265
  }
265
266
  if (url)
@@ -2271,6 +2272,7 @@ const pluginFileWriterHtml = () => {
2271
2272
  };
2272
2273
  };
2273
2274
 
2275
+ const { readFile: readFile$1 } = promises;
2274
2276
  const pluginFileWriterPublic = () => {
2275
2277
  let config;
2276
2278
  return {
@@ -2284,7 +2286,7 @@ const pluginFileWriterPublic = () => {
2284
2286
  this.addWatchFile(config.publicDir);
2285
2287
  const publicFiles = await fg(`${config.publicDir}/**/*`);
2286
2288
  for (const file of publicFiles) {
2287
- const source = await readFile(file);
2289
+ const source = await readFile$1(file);
2288
2290
  const fileName = relative(config.publicDir, file);
2289
2291
  this.emitFile({ type: "asset", fileName, source });
2290
2292
  }
@@ -2739,6 +2741,7 @@ const pluginHtmlAuditor = () => {
2739
2741
  };
2740
2742
  };
2741
2743
 
2744
+ const { readFile } = promises;
2742
2745
  const pluginManifest = (_manifest) => () => {
2743
2746
  let manifest;
2744
2747
  let plugins;
@@ -3476,7 +3479,9 @@ const pluginBackground = () => {
3476
3479
  if (this.meta.watchMode) {
3477
3480
  if (typeof port === "undefined")
3478
3481
  throw new Error("server port is undefined in watch mode");
3479
- loader = `import 'http://localhost:${port}${workerClientId}';
3482
+ loader = `import 'http:/localhost:${port}/@vite/env';
3483
+ `;
3484
+ loader += `import 'http://localhost:${port}${workerClientId}';
3480
3485
  `;
3481
3486
  if (worker)
3482
3487
  loader += `import 'http://localhost:${port}/${worker}';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crxjs/vite-plugin",
3
- "version": "1.0.8",
3
+ "version": "1.0.11",
4
4
  "description": "Build Chrome Extensions with this Vite plugin.",
5
5
  "keywords": [
6
6
  "rollup-plugin",