mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
wip.1 added dev and build modes
This commit is contained in:
parent
ee91ad2feb
commit
de5794ed61
@ -6,10 +6,10 @@
|
||||
"docs": "jsdoc -r ./src/ -c ./jsdoc.conf.json -d ./docs",
|
||||
"serve_docs": "cd docs; ws -p 8088",
|
||||
"serve": "ws -p 3000",
|
||||
"build": "vite build && npm run gen_js",
|
||||
"build": "vite build --mode production && npm run gen_js",
|
||||
"clean": "rm -rf ./lib ./docs",
|
||||
"prepublishOnly": "npm run build; npm run gen_js",
|
||||
"dev": "vite",
|
||||
"dev": "vite build --watch --mode development",
|
||||
"test": "jest --env=jsdom --runInBand --ci --coverage=false",
|
||||
"test_watch": "jest --env=jsdom --watch",
|
||||
"lint": "eslint src/",
|
||||
|
||||
27
vite-plugin-force-terser.js
Normal file
27
vite-plugin-force-terser.js
Normal file
@ -0,0 +1,27 @@
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
import { minify } from 'terser';
|
||||
|
||||
export default function forceTerserPlugin({ filePath }) {
|
||||
return {
|
||||
name: 'vite-plugin-force-terser',
|
||||
apply: 'build',
|
||||
closeBundle: async () => {
|
||||
const code = await readFile(filePath, 'utf-8');
|
||||
|
||||
const result = await minify(code, {
|
||||
compress: true,
|
||||
mangle: true,
|
||||
format: {
|
||||
comments: false
|
||||
}
|
||||
});
|
||||
|
||||
if (result.code) {
|
||||
await writeFile(filePath, result.code, 'utf-8');
|
||||
console.log(`✔ ${filePath} minified with terser`);
|
||||
} else {
|
||||
console.warn('⚠ terser did not return any code');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
66
vite.config.ts
Normal file
66
vite.config.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import path from 'path';
|
||||
import terser from '@rollup/plugin-terser';
|
||||
import {viteStaticCopy} from 'vite-plugin-static-copy'
|
||||
import forceTerserPlugin from './vite-plugin-force-terser.js';
|
||||
|
||||
/**
|
||||
* @param {{ mode: 'development' | 'production' }} param0
|
||||
* @returns {import('vite').UserConfig}
|
||||
*/
|
||||
export default function ({mode}: { mode: 'development' | 'production' }) {
|
||||
const isDev = mode === 'development';
|
||||
|
||||
return {
|
||||
build: {
|
||||
minify: !isDev,
|
||||
lib: {
|
||||
entry: ['./src/index.ts'],
|
||||
name: 'og',
|
||||
fileName: 'og',
|
||||
formats: ['es'],
|
||||
cssFileName: 'og',
|
||||
},
|
||||
emptyOutDir: true,
|
||||
outDir: path.resolve(__dirname, './lib/@openglobus'),
|
||||
sourcemap: isDev,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
entryFileNames: `og.[format].js`,
|
||||
assetFileNames: `[name][extname]`
|
||||
},
|
||||
plugins: [
|
||||
// doesn't work for esm modules
|
||||
terser({
|
||||
compress: true,
|
||||
mangle: true,
|
||||
format: {
|
||||
comments: false
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
// this works for esm modules
|
||||
!isDev && forceTerserPlugin({filePath: "./lib/@openglobus/og.es.js"}),
|
||||
viteStaticCopy({
|
||||
targets: [
|
||||
{
|
||||
src: './res/',
|
||||
dest: './'
|
||||
}
|
||||
]
|
||||
})
|
||||
],
|
||||
server: {
|
||||
fs: {
|
||||
strict: true,
|
||||
allow: ['src']
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
noDiscovery: true,
|
||||
include: []
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user