shopify-accelerate-app 1.0.33 → 1.0.35
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/package.json +1 -1
- package/src/esbuild/esbuild.ts +45 -35
package/package.json
CHANGED
package/src/esbuild/esbuild.ts
CHANGED
|
@@ -114,6 +114,36 @@ export const transformContent = (input, final = false, cssOutput = "") => {
|
|
|
114
114
|
|
|
115
115
|
const current = { timeout: null };
|
|
116
116
|
|
|
117
|
+
import { Plugin } from "esbuild";
|
|
118
|
+
|
|
119
|
+
export const aliasReactPlugin: Plugin = {
|
|
120
|
+
name: "alias-react",
|
|
121
|
+
setup(build) {
|
|
122
|
+
const resolvePath = (mod: string) => path.dirname(require.resolve(`${mod}/package.json`, { paths: [process.cwd()] }));
|
|
123
|
+
|
|
124
|
+
const compatDir = resolvePath("preact");
|
|
125
|
+
|
|
126
|
+
const createAlias = (from: string, to: string) => {
|
|
127
|
+
build.onResolve({ filter: new RegExp(`^${from}$`) }, () => ({
|
|
128
|
+
path: to,
|
|
129
|
+
namespace: "alias",
|
|
130
|
+
}));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
createAlias("react", "preact/compat");
|
|
134
|
+
createAlias("react-dom", "preact/compat");
|
|
135
|
+
createAlias("react-dom/test-utils", "preact/test-utils");
|
|
136
|
+
|
|
137
|
+
build.onLoad({ filter: /.*/, namespace: "alias" }, async (args) => {
|
|
138
|
+
return {
|
|
139
|
+
contents: `export * from '${args.path}'; export { default } from '${args.path}';`,
|
|
140
|
+
resolveDir: compatDir,
|
|
141
|
+
loader: "js",
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
117
147
|
const runBlockJsEsbuild = async (entryFile, block: ShopifyAppBlock & { path: string; folder: string }) => {
|
|
118
148
|
const startTime = Date.now();
|
|
119
149
|
const folder = block.folder;
|
|
@@ -141,6 +171,19 @@ const runBlockJsEsbuild = async (entryFile, block: ShopifyAppBlock & { path: str
|
|
|
141
171
|
.at(-1)
|
|
142
172
|
.replace(/\.(ts)x?$/gi, "")}.js`
|
|
143
173
|
);
|
|
174
|
+
|
|
175
|
+
await build({
|
|
176
|
+
entryPoints: [path.resolve(process.env.SHOPIFY_ACCELERATE_ROOT, "preact-runtime.ts")],
|
|
177
|
+
outfile: path.join(config.extension_path, "assets", `preact-runtime.js`),
|
|
178
|
+
bundle: true,
|
|
179
|
+
format: "iife",
|
|
180
|
+
globalName: "preact",
|
|
181
|
+
jsx: "transform",
|
|
182
|
+
jsxFactory: "h",
|
|
183
|
+
jsxImportSource: "preact",
|
|
184
|
+
minify: true,
|
|
185
|
+
});
|
|
186
|
+
|
|
144
187
|
await build({
|
|
145
188
|
entryPoints: [entryFile],
|
|
146
189
|
// bundle: true,
|
|
@@ -161,41 +204,8 @@ const runBlockJsEsbuild = async (entryFile, block: ShopifyAppBlock & { path: str
|
|
|
161
204
|
jsxImportSource: "preact",
|
|
162
205
|
jsxSideEffects: false,
|
|
163
206
|
keepNames: false,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
name: "alias-react",
|
|
167
|
-
setup(build) {
|
|
168
|
-
const resolveFromNodeModules = (mod: string) => path.dirname(require.resolve(`${mod}/package.json`, { paths: [process.cwd()] }));
|
|
169
|
-
|
|
170
|
-
build.onResolve({ filter: /^react$/ }, () => ({
|
|
171
|
-
path: "preact/compat",
|
|
172
|
-
namespace: "alias",
|
|
173
|
-
}));
|
|
174
|
-
|
|
175
|
-
build.onResolve({ filter: /^react-dom$/ }, () => ({
|
|
176
|
-
path: "preact/compat",
|
|
177
|
-
namespace: "alias",
|
|
178
|
-
}));
|
|
179
|
-
|
|
180
|
-
build.onResolve({ filter: /^react-dom\/test-utils$/ }, () => ({
|
|
181
|
-
path: "preact/test-utils",
|
|
182
|
-
namespace: "alias",
|
|
183
|
-
}));
|
|
184
|
-
|
|
185
|
-
build.onLoad({ filter: /.*!/, namespace: "alias" }, async (args) => {
|
|
186
|
-
const actualPath = require.resolve(args.path, {
|
|
187
|
-
paths: [process.cwd()],
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
contents: `export * from '${args.path}'; export { default } from '${args.path}';`,
|
|
192
|
-
resolveDir: path.dirname(actualPath),
|
|
193
|
-
loader: "js",
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
],*/
|
|
207
|
+
plugins: [aliasReactPlugin],
|
|
208
|
+
external: ["preact"], // ← VERY IMPORTANT
|
|
199
209
|
|
|
200
210
|
// splitting: true,
|
|
201
211
|
})
|