Skip to content

Commit

Permalink
Fix esm support (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
montalvomiguelo authored Apr 23, 2023
1 parent f149743 commit 3b41544
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/vite-shopify-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "vite-shopify-example",
"private": true,
"type": "module",
"scripts": {
"dev": "cross-env DEBUG=vite-plugin-shopify:* vite",
"build": "cross-env DEBUG=vite-plugin-shopify:* vite build",
Expand Down
1 change: 1 addition & 0 deletions examples/vite-shopify-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"node_modules"
],
"compilerOptions": {
"lib": ["esnext", "dom"],
"baseUrl": ".",
"paths": {
"@/*": ["frontend/*"],
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"target": "es2017",
"target": "es2020",
"module": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
Expand Down
8 changes: 7 additions & 1 deletion packages/vite-plugin-shopify/src/html.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs'
import path from 'node:path'
import { AddressInfo } from 'node:net'
import { fileURLToPath } from 'node:url'
import { Manifest, Plugin, ResolvedConfig, normalizePath } from 'vite'
import createDebugger from 'debug'

Expand All @@ -9,6 +10,11 @@ import type { Options, DevServerUrl } from './types'

const debug = createDebugger('vite-plugin-shopify:html')

// __dirname polyfill for ESM
const _dirname = typeof __dirname !== 'undefined'
? __dirname
: path.dirname(fileURLToPath(import.meta.url))

// Plugin for generating vite-tag liquid theme snippet with entry points for JS and CSS assets
export default function shopifyHTML (options: Required<Options>): Plugin {
let config: ResolvedConfig
Expand Down Expand Up @@ -55,7 +61,7 @@ export default function shopifyHTML (options: Required<Options>): Plugin {
res.statusCode = 404

res.end(
fs.readFileSync(path.join(__dirname, 'dev-server-index.html')).toString()
fs.readFileSync(path.join(_dirname, 'dev-server-index.html')).toString()
)
}

Expand Down

0 comments on commit 3b41544

Please sign in to comment.