pack: do not import path methods entirely
This commit is contained in:
1 parent
89a65c9707
commit
1d6d2d0f1e
3 files changed
+22
-22
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import path from 'path'
|
||||
import { join, dirname } from 'path'
|
||||
import packageJson from '../../package.json' assert { type: 'json' }
|
||||
import webpack from 'webpack'
|
||||
|
||||
@@ -10,11 +10,11 @@ import { fileURLToPath } from 'url'
|
||||
process.env.BABEL_ENV = 'main'
|
||||
|
||||
const IS_DEV_ENV = process.env.NODE_ENV !== 'production'
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
export default {
|
||||
entry: {
|
||||
main: path.join(__dirname, '../../src/main/index.js')
|
||||
main: join(__dirname, '../../src/main/index.js')
|
||||
},
|
||||
externals: [
|
||||
...Object.keys(packageJson.dependencies || {})
|
||||
@@ -39,7 +39,7 @@ export default {
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
libraryTarget: 'commonjs2',
|
||||
path: path.join(__dirname, '../../dist/electron')
|
||||
path: join(__dirname, '../../dist/electron')
|
||||
},
|
||||
optimization: {
|
||||
minimize: true,
|
||||
@@ -54,7 +54,7 @@ export default {
|
||||
new webpack.DefinePlugin({
|
||||
...IS_DEV_ENV
|
||||
? {
|
||||
__static: `"${path.join(__dirname, '../../static').replace(/\\/g, '\\\\')}"`
|
||||
__static: `"${join(__dirname, '../../static').replace(/\\/g, '\\\\')}"`
|
||||
}
|
||||
: {},
|
||||
...IS_DEV_ENV
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import path from 'path'
|
||||
import { join, dirname, resolve } from 'path'
|
||||
import packageJson from '../../package.json' assert { type: 'json' }
|
||||
import webpack from 'webpack'
|
||||
|
||||
@@ -12,7 +12,7 @@ import externalsWhiteList from './webpack.renderer.externals.whitelist.mjs'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const IS_DEV_ENV = process.env.NODE_ENV !== 'production'
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
process.env.BABEL_ENV = 'renderer'
|
||||
|
||||
@@ -23,7 +23,7 @@ export default {
|
||||
minimizer: [new TerserPlugin()]
|
||||
},
|
||||
entry: {
|
||||
renderer: path.join(__dirname, '../../src/renderer/main.js')
|
||||
renderer: join(__dirname, '../../src/renderer/main.js')
|
||||
},
|
||||
externals: [
|
||||
...Object.keys(packageJson.dependencies || {}).filter(d => !externalsWhiteList.includes(d))
|
||||
@@ -87,7 +87,7 @@ export default {
|
||||
new VueLoaderPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
filename: 'index.html',
|
||||
template: path.resolve(__dirname, '../../src/index.ejs'),
|
||||
template: resolve(__dirname, '../../src/index.ejs'),
|
||||
templateParameters (compilation, assets, options) {
|
||||
return {
|
||||
compilation,
|
||||
@@ -106,9 +106,9 @@ export default {
|
||||
removeComments: true
|
||||
},
|
||||
isDevelopment: IS_DEV_ENV,
|
||||
staticPath: path.join(__dirname, '/static').replace(/\\/g, '\\\\'),
|
||||
staticPath: join(__dirname, '/static').replace(/\\/g, '\\\\'),
|
||||
nodeModules: IS_DEV_ENV
|
||||
? path.resolve(__dirname, '../../node_modules')
|
||||
? resolve(__dirname, '../../node_modules')
|
||||
: false
|
||||
}),
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
@@ -121,7 +121,7 @@ export default {
|
||||
}),
|
||||
new webpack.DefinePlugin(IS_DEV_ENV
|
||||
? {
|
||||
__static: `"${path.join(__dirname, '../../static').replace(/\\/g, '\\\\')}"`,
|
||||
__static: `"${join(__dirname, '../../static').replace(/\\/g, '\\\\')}"`,
|
||||
__VUE_OPTIONS_API__: false,
|
||||
__VUE_PROD_DEVTOOLS__: false
|
||||
}
|
||||
@@ -136,8 +136,8 @@ export default {
|
||||
: [new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: path.join(__dirname, '../../static'),
|
||||
to: path.join(__dirname, '../../dist/electron/static')
|
||||
from: join(__dirname, '../../static'),
|
||||
to: join(__dirname, '../../dist/electron/static')
|
||||
}
|
||||
]
|
||||
})],
|
||||
@@ -151,11 +151,11 @@ export default {
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
libraryTarget: 'commonjs2',
|
||||
path: path.join(__dirname, '../../dist/electron')
|
||||
path: join(__dirname, '../../dist/electron')
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.join(__dirname, '../../src/renderer'),
|
||||
'@': join(__dirname, '../../src/renderer'),
|
||||
vue$: `vue/dist/vue.esm-browser${IS_DEV_ENV ? '' : '.prod'}`
|
||||
},
|
||||
extensions: ['.js', '.vue', '.json', '.css', '.node']
|
||||
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
import dotenv from 'dotenv'
|
||||
import chalk from 'chalk'
|
||||
import electron from 'electron'
|
||||
import path from 'path'
|
||||
import { dirname, join } from 'path'
|
||||
import { spawn } from 'child_process'
|
||||
import webpack from 'webpack'
|
||||
import WebpackDevServer from 'webpack-dev-server'
|
||||
@@ -13,7 +13,7 @@ import { fileURLToPath } from 'url'
|
||||
|
||||
dotenv.config({ path: '.env.dev' })
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
let electronProcess = null
|
||||
let manualRestart = false
|
||||
|
||||
@@ -36,7 +36,7 @@ function log (processName, data, color = 'yellow') {
|
||||
function startRenderer () {
|
||||
return new Promise(resolve => {
|
||||
(async () => {
|
||||
rendererConfig.entry.renderer = [path.join(__dirname, 'devClient.mjs'), rendererConfig.entry.renderer]
|
||||
rendererConfig.entry.renderer = [join(__dirname, 'devClient.mjs'), rendererConfig.entry.renderer]
|
||||
|
||||
const compiler = webpack({
|
||||
mode: 'development',
|
||||
@@ -52,7 +52,7 @@ function startRenderer () {
|
||||
port: 9080,
|
||||
liveReload: true,
|
||||
static: {
|
||||
directory: path.join(__dirname, '../'),
|
||||
directory: join(__dirname, '../'),
|
||||
watch: {
|
||||
usePolling: true,
|
||||
ignored: /node_modules/
|
||||
@@ -80,7 +80,7 @@ function startRenderer () {
|
||||
|
||||
function startMain () {
|
||||
return new Promise(resolve => {
|
||||
mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js'), mainConfig.entry.main]
|
||||
mainConfig.entry.main = [join(__dirname, '../src/main/index.dev.js'), mainConfig.entry.main]
|
||||
|
||||
const compiler = webpack({
|
||||
mode: 'development',
|
||||
@@ -120,7 +120,7 @@ function startElectron () {
|
||||
electronProcess = spawn(electron, [
|
||||
...[
|
||||
'--inspect=5858',
|
||||
path.join(__dirname, '/../dist/electron/main.js')
|
||||
join(__dirname, '/../dist/electron/main.js')
|
||||
],
|
||||
...process.argv.slice(2)
|
||||
])
|
||||
|
||||
Reference in new issue
Block a user