Repository: egoist/vue-compile Branch: master Commit: 03853f96898b Files: 33 Total size: 38.5 KB Directory structure: gitextract_b7opvyms/ ├── .editorconfig ├── .eslintrc ├── .gitattributes ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── babel.js ├── circle.yml ├── jest.config.js ├── package.json ├── src/ │ ├── babel/ │ │ └── preset.ts │ ├── cli.ts │ ├── compileScript.ts │ ├── compileStyles.ts │ ├── compileTemplate.ts │ ├── importLocal.ts │ ├── index.ts │ ├── script-compilers/ │ │ └── babel.ts │ ├── style-compilers/ │ │ ├── postcss.ts │ │ ├── sass.ts │ │ └── stylus.ts │ ├── types.ts │ ├── utils.ts │ └── writeSFC.ts ├── test/ │ ├── fixture/ │ │ ├── custom-blocks/ │ │ │ └── foo.vue │ │ ├── keep-async-function/ │ │ │ └── foo.vue │ │ ├── keep-ts-block/ │ │ │ └── foo.vue │ │ ├── script-block/ │ │ │ └── foo.vue │ │ └── script-setup/ │ │ └── foo.vue │ └── index.test.ts ├── tsconfig.build.json └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false [*.test.ts] trim_trailing_whitespace = false ================================================ FILE: .eslintrc ================================================ { "extends": ["xo-typescript", "rem", "prettier"], "plugins": ["prettier"], "env": { "jest": true }, "rules": { "unicorn/filename-case": "off", "unicorn/no-abusive-eslint-disable": "off", "@typescript-eslint/no-var-requires": "off", "@typescript-eslint/restrict-template-expressions": "off" } } ================================================ FILE: .gitattributes ================================================ * text=auto ================================================ FILE: .gitignore ================================================ node_modules test/fixture/output *.log dist/ ================================================ FILE: .prettierrc ================================================ "@egoist/prettier-config" ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) egoist <0x142857@gmail.com> (https://github.com/egoist) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # vue-compile Compile the blocks in Vue single-file components to JS/CSS from Babel/Sass/Stylus. ## Why This Approach You may want to publish `.vue` files instead of transformed `.js` files on npm because the `.vue` file is preferred in some scenarioes, e.g. `vue-server-renderer` can inline critical CSS from ` ``` Out: ```vue ``` ### Compile Standalone CSS Files CSS files like `.css` `.scss` `.sass` `.styl` will be compiled to output directory with `.css` extension, all relevant `import` statements in `.js` `.ts` or ``, ) }) if (styles.length > 0) { for (const style of styles) { const attrs = { ...style.attrs } delete attrs.lang if (style.src) { attrs.src = style.src.replace(cssExtensionsRe, '.css') parts.push(``) } else { parts.push( `\n${style.content.trim()}\n`, ) } } } if (customBlocks) { for (const block of customBlocks) { parts.push( `<${block.type}${stringifyAttrs(block.attrs)}>${ block.content ? block.content.trim() : '' }`, ) } } await fs.ensureDir(path.dirname(outFile)) await fs.writeFile(outFile, parts.join('\n\n'), 'utf8') } ================================================ FILE: test/fixture/custom-blocks/foo.vue ================================================ this is a custom block ================================================ FILE: test/fixture/keep-async-function/foo.vue ================================================ ================================================ FILE: test/fixture/keep-ts-block/foo.vue ================================================ ================================================ FILE: test/fixture/script-block/foo.vue ================================================ ================================================ FILE: test/fixture/script-setup/foo.vue ================================================ ================================================ FILE: test/index.test.ts ================================================ import path from 'path' import fs from 'fs-extra' import { createCompiler } from '../src' const fixture = (...args: string[]): string => path.resolve(__dirname, 'fixture', ...args) const tmp = (name: string): string => fixture('output', name) test('script block', async () => { const outDir = tmp('script-block') const compiler = createCompiler({ input: fixture('script-block'), output: outDir, }) await compiler.normalize() const content = await fs.readFile(path.join(outDir, 'foo.vue'), 'utf8') expect(content).toMatchInlineSnapshot(` "" `) }) test('script setup', async () => { const outDir = tmp('script-setup') const compiler = createCompiler({ input: fixture('script-setup'), output: outDir, }) await compiler.normalize() const content = await fs.readFile(path.join(outDir, 'foo.vue'), 'utf8') expect(content).toMatchInlineSnapshot(` " " `) }) test('custom blocks', async () => { const outDir = tmp('custom-blocks') const compiler = createCompiler({ input: fixture('custom-blocks'), output: outDir, }) await compiler.normalize() const content = await fs.readFile(path.join(outDir, 'foo.vue'), 'utf8') expect(content).toMatchInlineSnapshot(` " this is a custom block" `) }) test('keep ts block', async () => { const outDir = tmp('keep-ts-block') const compiler = createCompiler({ input: fixture('keep-ts-block'), output: outDir, preserveTsBlock: true, }) await compiler.normalize() const content = await fs.readFile(path.join(outDir, 'foo.vue'), 'utf8') expect(content).toMatchInlineSnapshot(` "" `) }) test('keep-async-function', async () => { const outDir = tmp('keep-async-function') const compiler = createCompiler({ input: fixture('keep-async-function'), output: outDir, preserveTsBlock: true, }) await compiler.normalize() const content = await fs.readFile(path.join(outDir, 'foo.vue'), 'utf8') expect(content).toMatchInlineSnapshot(` "" `) }) ================================================ FILE: tsconfig.build.json ================================================ { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./dist", "declaration": true, "skipLibCheck": true }, "include": ["src"] } ================================================ FILE: tsconfig.json ================================================ { "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ "target": "es2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ "strict": true /* Enable all strict type-checking options. */, "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, "strictNullChecks": true /* Enable strict null checks. */, "strictFunctionTypes": true /* Enable strict checking of function types. */, "strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */, "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, /* Additional Checks */ "noUnusedLocals": true /* Report errors on unused locals. */, "noUnusedParameters": true /* Report errors on unused parameters. */, "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ /* Module Resolution Options */ "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ /* Source Map Options */ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ } }