Skip to content

Commit

Permalink
fix(cli): fix commonjs compiler
Browse files Browse the repository at this point in the history
affects: @varlet/cli
  • Loading branch information
haoziqaq committed Nov 20, 2021
1 parent c51625b commit c5c2b12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/varlet-cli/src/compiler/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export async function compileCommonJSEntry(dir: string, publicDirs: string[]) {
const publicComponent = bigCamelize(dirname)

publicComponents.push(publicComponent)
requires.push(`const ${publicComponent} = require('./${dirname}')`)
requires.push(`var ${publicComponent} = require('./${dirname}')['default']`)
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`)
cssRequires.push(`require('./${dirname}/style')`)
lessRequires.push(`require('./${dirname}/style/less')`)
Expand Down
4 changes: 3 additions & 1 deletion packages/varlet-cli/src/config/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { injectHtml } from 'vite-plugin-html'
import {
CWD,
ES_DIR,
LIB_DIR,
SITE_CONFIG,
SITE_DIR,
SITE_MOBILE_ROUTES,
Expand All @@ -17,7 +18,7 @@ import {
import { InlineConfig, PluginOption } from 'vite'
import { get, kebabCase } from 'lodash'
import { resolve } from 'path'
import { readFileSync, removeSync, writeFileSync } from 'fs-extra'
import { copyFileSync, readFileSync, removeSync, writeFileSync } from 'fs-extra'

export function getDevConfig(varletConfig: Record<string, any>): InlineConfig {
const defaultLanguage = get(varletConfig, 'defaultLanguage')
Expand Down Expand Up @@ -88,6 +89,7 @@ function inlineCSS(fileName: string, dir: string): PluginOption {
const injectCode = `;(function(){var style=document.createElement('style');style.type='text/css';\
style.rel='stylesheet';style.appendChild(document.createTextNode(\`${cssCode.replace(/\\/g, '\\\\')}\`));\
var head=document.querySelector('head');head.appendChild(style)})();`
copyFileSync(cssFile, resolve(LIB_DIR, 'style.css'))
removeSync(cssFile)
writeFileSync(jsFile, `${injectCode}${jsCode}`)
},
Expand Down

0 comments on commit c5c2b12

Please sign in to comment.