Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension-sdk: Add a shared vite config for extensions #8407

Merged
merged 5 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions packages/extension-sdk/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// ATTENTION: this is a .mjs (instead of a .ts) file on purpose,
// because we don't want to transpile it before publishing
// c.f. https://github.com/vitejs/vite/issues/5370

import { mergeConfig, searchForWorkspaceRoot } from 'vite'
import { join } from 'path'
import { cwd } from 'process'
import { readFileSync } from 'fs'

import vue from '@vitejs/plugin-vue'
import serve from 'rollup-plugin-serve'

const distDir = 'dist'

export const defineConfig = (overrides = {}) => {
return ({ mode }) => {
const isProduction = mode === 'production'
const isServing = !isProduction

// read package name from vite workspace
const packageJson = JSON.parse(
readFileSync(join(searchForWorkspaceRoot(cwd()), 'package.json')).toString()
)

const name = packageJson.name

// take vite standard config and reuse it for rollup-plugin-serve config
const { https, port = 9210, host = 'localhost' } = overrides?.server
const isHttps = !!https

if (isServing) {
console.log(
`>>> Serving extension at http${isHttps ? 's' : ''}://${host}:${port}/js/${name}.js`
)
}

return mergeConfig(
{
server: {
host,
port,
strictPort: true
},
resolve: {
alias: {
path: 'rollup-plugin-node-polyfills/polyfills/path'
}
},
build: {
cssCodeSplit: true,
minify: isProduction,
rollupOptions: {
external: ['vue', 'vuex', 'luxon', 'web-pkg', 'web-client', 'vue3-gettext'],
preserveEntrySignatures: 'strict',
input: {
[name]: './src/index.ts'
},
output: {
format: 'amd',
dir: distDir,
chunkFileNames: join('js', 'chunks', '[name]-[hash].mjs'),
entryFileNames: join('js', `[name]${isProduction ? '-[hash]' : ''}.js`)
},
plugins: [
isServing &&
serve({
headers: {
'access-control-allow-origin': '*'
},
contentBase: distDir,
...(https && { https }),
...(port && { port })
})
]
}
},
plugins: [
vue({
customElement: false
})
]
},
overrides
)
}
}
25 changes: 25 additions & 0 deletions packages/extension-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@ownclouders/extension-sdk",
"version": "0.0.1-alpha.1",
"description": "ownCloud Web Extension SDK",
"license": "AGPL-3.0",
"main": "index.mjs",
"type": "module",
"private": false,
"author": "ownCloud GmbH <[email protected]>",
"homepage": "https://github.com/owncloud/web/tree/master/packages/extension-sdk",
"repository": {
"type": "git",
"url": "https://github.com/owncloud/web",
"directory": "packages/extension-sdk"
},
"dependencies": {
"@vitejs/plugin-vue": "4.0.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-serve": "^2.0.2"
},
"peerDependencies": {
"vite": "^4.1.1",
"sass": "1.58.0"
}
}
Loading