* Prepare the file for ESM distribution. * @param {string} file - The file source code to replace * @param {string} version - The version we are publishing * @returns
(file, version, min = true)
| 176 | * @returns |
| 177 | */ |
| 178 | async function prepForDistribution(file, version, min = true) { |
| 179 | let src = file.replace( |
| 180 | /(from|import)\s+['"]@formkit\/([a-z0-9]+)['"]/g, |
| 181 | `$1 '/$2@${version}'` |
| 182 | ) |
| 183 | // const vueImportRegex = /^import\s+(.*)\s+from\s+'vue';?/gm |
| 184 | // const vueMatch = src.match(vueImportRegex) |
| 185 | // if (vueMatch) { |
| 186 | // src = src.replace(vueImportRegex, '') |
| 187 | // const vueImportStatement = `const $1 = await import(\`./vue.js?src=\${(new URL(import.meta.url).searchParams.get('vue') || 'https://cdn.jsdelivr.net/npm/vue@next/%2Besm')}\`);` |
| 188 | // src = src.replace( |
| 189 | // /(^import\s+.*;)(?!\s(import|export))/gm, |
| 190 | // '$1\n' + vueMatch[0] |
| 191 | // ) |
| 192 | // src = src.replace(vueImportRegex, vueImportStatement) |
| 193 | // } |
| 194 | if (!min) return src |
| 195 | |
| 196 | try { |
| 197 | const result = await minify(src, { module: true }) |
| 198 | return result.code |
| 199 | } catch (err) { |
| 200 | console.error(err) |
| 201 | throw err |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Deploy the project to a file store used for iife distribution. This is a |