mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-04-26 14:36:56 +08:00
chore: delete useless files
This commit is contained in:
parent
a3e423f7e2
commit
ebd8dbae62
@ -1,60 +0,0 @@
|
|||||||
import { join } from 'path'
|
|
||||||
import { RollupOptions } from 'rollup'
|
|
||||||
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
||||||
import commonjs from '@rollup/plugin-commonjs'
|
|
||||||
import esbuild from 'rollup-plugin-esbuild'
|
|
||||||
import alias from '@rollup/plugin-alias'
|
|
||||||
import json from '@rollup/plugin-json'
|
|
||||||
import { builtins } from './utils'
|
|
||||||
|
|
||||||
export default (env = 'production') => {
|
|
||||||
const options: RollupOptions = {
|
|
||||||
input: join(__dirname, '../src/main/index.ts'),
|
|
||||||
output: {
|
|
||||||
file: join(__dirname, '../dist/main/_.js'),
|
|
||||||
format: 'cjs',
|
|
||||||
name: 'ElectronMainBundle',
|
|
||||||
sourcemap: true,
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
nodeResolve({ preferBuiltins: true, browser: true }), // 消除碰到 node.js 模块时⚠警告
|
|
||||||
commonjs(),
|
|
||||||
json(),
|
|
||||||
esbuild({
|
|
||||||
// All options are optional
|
|
||||||
include: /\.[jt]sx?$/, // default, inferred from `loaders` option
|
|
||||||
exclude: /node_modules/, // default
|
|
||||||
// watch: process.argv.includes('--watch'), // rollup 中有配置
|
|
||||||
sourceMap: false, // default
|
|
||||||
minify: env === 'production',
|
|
||||||
target: 'es2017', // default, or 'es20XX', 'esnext'
|
|
||||||
jsxFactory: 'React.createElement',
|
|
||||||
jsxFragment: 'React.Fragment',
|
|
||||||
// Like @rollup/plugin-replace
|
|
||||||
define: {
|
|
||||||
__VERSION__: '"x.y.z"'
|
|
||||||
},
|
|
||||||
tsconfig: 'tsconfig.json', // default
|
|
||||||
// Add extra loaders
|
|
||||||
loaders: {
|
|
||||||
// Add .json files support
|
|
||||||
// require @rollup/plugin-commonjs
|
|
||||||
'.json': 'json',
|
|
||||||
// Enable JSX in .js files too
|
|
||||||
'.js': 'jsx'
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
alias({
|
|
||||||
entries: [
|
|
||||||
{ find: '@main', replacement: join(__dirname, '../src/main'), },
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
external: [
|
|
||||||
...builtins(),
|
|
||||||
'electron',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
return options
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
import path from 'path'
|
|
||||||
import acorn from 'acorn'
|
|
||||||
import { Plugin as RollupPlugin } from 'rollup'
|
|
||||||
import { Plugin as VitePlugin } from 'vite'
|
|
||||||
import { vue_js_ts_extensions } from './utils'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cjs2esm
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
export function cjs2esm() {
|
|
||||||
return {
|
|
||||||
name: '@rollup/plugin-cjs2esm',
|
|
||||||
transform(code: string, filename: string) {
|
|
||||||
if (filename.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
|
|
||||||
const cjsRegexp = /(const|let|var)[\n\s]+(\w+)[\n\s]*=[\n\s]*require\(["|'](.+)["|']\)/g
|
|
||||||
const res = code.match(cjsRegexp)
|
|
||||||
if (res) {
|
|
||||||
// const Store = require('electron-store') -> import Store from 'electron-store'
|
|
||||||
code = code.replace(cjsRegexp, `import $2 from '$3'`)
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** esm2cjs */
|
|
||||||
export function esm2cjs(moduleList: string[]): VitePlugin {
|
|
||||||
const filter = {
|
|
||||||
include: (id: string) => vue_js_ts_extensions.includes(path.parse(id).ext)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: 'cxmh:esm2cjs',
|
|
||||||
transform(code, id) {
|
|
||||||
if (filter.include(id)) {
|
|
||||||
const node: any = acorn.parse(code, {
|
|
||||||
ecmaVersion: 'latest',
|
|
||||||
sourceType: 'module',
|
|
||||||
})
|
|
||||||
|
|
||||||
const parsed = path.parse(id)
|
|
||||||
|
|
||||||
let codeRet = code
|
|
||||||
node.body.reverse().forEach((item) => {
|
|
||||||
if (item.type !== 'ImportDeclaration') return
|
|
||||||
if (!moduleList.includes(item.source.value)) return // 跳过不要转换的模块
|
|
||||||
|
|
||||||
const statr = codeRet.substring(0, item.start)
|
|
||||||
const end = codeRet.substring(item.end)
|
|
||||||
const deft = item.specifiers.find(({ type }) => type === 'ImportDefaultSpecifier')
|
|
||||||
const deftModule = deft ? deft.local.name : ''
|
|
||||||
const nameAs = item.specifiers.find(({ type }) => type === 'ImportNamespaceSpecifier')
|
|
||||||
const nameAsModule = nameAs ? nameAs.local.name : ''
|
|
||||||
const modules = item.
|
|
||||||
specifiers
|
|
||||||
.filter((({ type }) => type === 'ImportSpecifier'))
|
|
||||||
.reduce((acc, cur) => acc.concat(cur.imported.name), [])
|
|
||||||
|
|
||||||
// console.log(deftModule, '|', nameAsModule, '|', modules, '\n----')
|
|
||||||
|
|
||||||
if (nameAsModule) {
|
|
||||||
// import * as name from
|
|
||||||
codeRet = `${statr}const ${nameAsModule} = require(${item.source.raw})${end}`
|
|
||||||
} else if (deftModule && !modules.length) {
|
|
||||||
// import name from 'mod'
|
|
||||||
codeRet = `${statr}const ${deftModule} = require(${item.source.raw})${end}`
|
|
||||||
} else if (deftModule && modules.length) {
|
|
||||||
// import name, { name2, name3 } from 'mod'
|
|
||||||
codeRet = `${statr}const ${deftModule} = require(${item.source.raw})
|
|
||||||
const { ${modules.join(', ')} } = ${deftModule}${end}`
|
|
||||||
} else {
|
|
||||||
// import { name1, name2 } from 'mod'
|
|
||||||
codeRet = `${statr}const { ${modules.join(', ')} } = require(${item.source.raw})${end}`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return codeRet
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ensure cwd crrect
|
|
||||||
* TODO: __dirname 会被编译成字符串
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
export function ensureCwdCrrect(filename: string): RollupPlugin {
|
|
||||||
return {
|
|
||||||
name: 'cxmh:ensure-cwd-crrect',
|
|
||||||
transform(code, id) {
|
|
||||||
if (id === filename) {
|
|
||||||
return `
|
|
||||||
// !!! ensure cwd crrect
|
|
||||||
process.chdir(__dirname)
|
|
||||||
|
|
||||||
${code}
|
|
||||||
`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
/** HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.css -> HelloWorld.vue */
|
|
||||||
export function cleanUrl(url: string) {
|
|
||||||
return url.replace(/(\?|#).*$/, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
export const vue_js_ts_extensions = ['.vue', '.js', '.jsx', '.ts', '.tsx']
|
|
Loading…
x
Reference in New Issue
Block a user