Skip to content

Commit

Permalink
Add non-svelte external library
Browse files Browse the repository at this point in the history
  • Loading branch information
cyderize committed Jul 7, 2023
1 parent bda81ab commit a72d6d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ jobs:
library:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup NodeJS LTS
uses: actions/setup-node@v3
with:
node-version: lts/*
- run: npm ci
- run: npm run build
env:
EMBEDDED_PLAYGROUND: "y"
- name: Install dependencies
run: npm ci
- name: Build library
run: npm run build -- --mode library
- name: Build library with external Svelte
run: npm run build -- --mode library-external-svelte
- name: Deploy
if: ${{ github.ref == 'refs/heads/main' }}
run: |
Expand Down
45 changes: 28 additions & 17 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,35 @@ function lezer() {
};
}

const BUILD_LIBRARY = /[yY1]/.test(process.env.EMBEDDED_PLAYGROUND || '');
const libraryBuild = {
lib: {
entry: 'src/embed.js',
name: 'MiniZincPlayground',
},
rollupOptions: {
output: {
globals: (g) => g,
},
},
};

const buildConfigs = {
library: libraryBuild,
'library-external-svelte': {
lib: {
...libraryBuild.lib,
},
rollupOptions: {
...libraryBuild.rollupOptions,
external: ['svelte', /svelte\/.*/],
},
outDir: 'dist/external-svelte',
},
};

// https://vitejs.dev/config/
export default defineConfig({
build: BUILD_LIBRARY
? {
lib: {
entry: 'src/embed.js',
name: 'MiniZincPlayground',
},
rollupOptions: {
external: ['svelte', /svelte\/.*/],
output: {
globals: (g) => g
}
},
}
: undefined,
export default defineConfig(({ mode }) => ({
build: buildConfigs[mode],
base: process.env.BASE_PATH,
plugins: [lezer(), svelte()],
});
}));

0 comments on commit a72d6d9

Please sign in to comment.