-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
74 lines (72 loc) · 2.34 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const path = require('path')
const fs = require('fs')
const _devtools_templates = [
"devtools_app",
"inspector",
"js_app",
"ndb_app",
"node_app",
"worker_app",
"device_mode_emulation_frame",
]
export default {
build:{
target: 'esnext',
minify: false,
// assetsDir: 'static',
sourcemap: false,
rollupOptions: {
input: _devtools_templates.map(it => path.resolve(__dirname, it + '.html')),
output: {
chunkFileNames: 'js/[name].js',
entryFileNames: '[name].js',
assetFileNames: 'static/[name].[ext]',
// manualChunks(id) { // 静态资源分拆打包
// if (id.includes('node_modules')) {
// return 'lib/' + id.toString().split('node_modules/')[1].split('/')[0].toString()
// }
// if (id.includes('/front_end/')) {
// return (id.toString().split('/front_end/')[1].split('.')[0].toString())
// }
// }
}
},
},
base: './',
plugins: [
{
// enforce: 'pre',
name: 'chrome-dev',
resolveId(source, importer, options) {
if (source.endsWith('.css.legacy.js') || source.endsWith('.css.js') ){
const css = source.replace('.js', '').replace('.legacy', '')
var ap = path.resolve(path.dirname(importer), css + '.js') + '?css=js'
if (source.endsWith('.css.legacy.js')) ap += '&legacy'
return ap
}
return null
},
load(id) {
// if (id.endsWith('.css.legacy.js') || id.endsWith('.css.js') ){
// const stylesheetContents = fs.readFileSync(id.replace('.js', '').replace('.legacy', ''), {encoding:'utf8', flag:'r'})
if (id.endsWith('?css=js') || id.endsWith('?css=js&legacy') ) {
const content = fs.readFileSync(id.split('?')[0].replace('.js', ''), {encoding:'utf8', flag:'r'})
const stylesheetContents = content.replace(/\`/g, '\\\'').replace(/\\/g, '\\\\')
.replace(/\/\*.+?\*\//gs, '')
let exportStatement;
if (id.endsWith('?css=js&legacy')) {
exportStatement = `export default {
cssContent: \`${stylesheetContents}\`
}`
} else {
exportStatement = `const styles = new CSSStyleSheet()
styles.replaceSync(\`${stylesheetContents}\`)
export default styles`
}
return exportStatement
}
return null;
}
}
]
}