naive-ui/vite.config.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

const path = require('path')
const alias = require('@rollup/plugin-alias')
const { babel } = require('@rollup/plugin-babel')
const rollupCssRenderPlugin = require('./build/rollup-plugin-css-render')
const rollupDemoPlugin = require('./build/rollup-plugin-demo')
const viteCssRenderPlugin = require('./build/vite-plugin-css-render')
const viteDemoPlugin = require('./build/vite-plugin-demo')
module.exports = {
root: __dirname,
2020-11-02 15:40:23 +08:00
plugins: [
viteDemoPlugin(),
viteCssRenderPlugin()
2020-11-02 15:40:23 +08:00
],
2020-11-05 15:36:27 +08:00
outDir: 'site',
optimizeDeps: {
2020-11-01 19:35:00 +08:00
include: [
'highlight.js/lib/core',
2020-11-01 19:35:00 +08:00
'highlight.js/lib/languages/cpp',
'highlight.js/lib/languages/javascript',
'highlight.js/lib/languages/python',
'vooks'
]
},
alias: {
'/@naive-ui/': path.resolve(__dirname, './src'),
2020-11-03 11:53:37 +08:00
src: path.resolve(__dirname, './src')
},
define: {
'process.env.NODE_ENV': `'${process.env.NODE_ENV}'`,
2020-11-03 11:53:37 +08:00
__DEV__: process.env.NODE_ENV !== 'production'
},
2020-11-02 15:40:23 +08:00
rollupPluginVueOptions: {
include: /\.(vue|md|demo.md|demo-entry.md|entry)$/
},
rollupInputOptions: {
plugins: [
alias({
entries: [
2020-11-02 15:40:23 +08:00
{
find: /^naive-ui$/g,
replacement: './src/index.js'
}
]
}),
rollupDemoPlugin(),
rollupCssRenderPlugin(),
babel({
babelHelpers: 'bundled'
})
]
2020-11-02 21:41:40 +08:00
},
indexHtmlTransforms: [
{
apply: 'pre',
transform ({ code }) {
2020-11-11 20:48:42 +08:00
const isTusimple = !!process.env.TUSIMPLE
2020-11-02 21:41:40 +08:00
switch (process.env.NODE_ENV) {
case 'production':
2020-11-11 20:48:42 +08:00
return code.replace(
/__INDEX__/,
'/demo/index.' + (isTusimple ? 'ts-prod.js' : 'prod.js')
)
2020-11-02 21:41:40 +08:00
default:
2020-11-11 20:48:42 +08:00
return code.replace(
/__INDEX__/,
'/demo/index.' + (isTusimple ? 'ts-dev.js' : 'dev.js')
)
2020-11-02 21:41:40 +08:00
}
}
}
]
}