Browse Source

build

master
1549469775 4 years ago
parent
commit
8a934f81b0
  1. 18
      script/build.ts
  2. 3
      script/dev-runner.ts
  3. 35
      script/webpack/runMain.js
  4. 5
      script/webpack/webpack.main.config.js

18
script/build.ts

@ -8,6 +8,8 @@ import * as ora from "ora"
import * as chalk from "chalk" import * as chalk from "chalk"
import * as minimist from "minimist" import * as minimist from "minimist"
const {buildMain} = require("./webpack/runMain")
import { exec, spawn, ChildProcess } from "child_process" import { exec, spawn, ChildProcess } from "child_process"
import { watch, rollup, OutputOptions } from "rollup" import { watch, rollup, OutputOptions } from "rollup"
import { waitOn } from "./utils" import { waitOn } from "./utils"
@ -62,14 +64,14 @@ function tscCheck() {
} }
}) })
} }
async function buildMain() { // async function buildMain() {
try { // try {
const build = await rollup(opts) // const build = await rollup(opts)
build.write(opts.output as OutputOptions) // build.write(opts.output as OutputOptions)
} catch (error) { // } catch (error) {
console.log(`\n${TAG} ${chalk.red("构建报错")}\n`, error, "\n") // console.log(`\n${TAG} ${chalk.red("构建报错")}\n`, error, "\n")
} // }
} // }
function buildElectron() { function buildElectron() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

3
script/dev-runner.ts

@ -13,8 +13,7 @@ import { watch, rollup, OutputOptions } from "rollup"
import { waitOn } from "./utils" import { waitOn } from "./utils"
import options from "./rollup.config" import options from "./rollup.config"
const startMain = require("./webpack/runMain") const {startMain} = require("./webpack/runMain")
console.log(startMain);
// 注入环境变量 // 注入环境变量
dotenv.config({ path: join(__dirname, "../.env") }) dotenv.config({ path: join(__dirname, "../.env") })

35
script/webpack/runMain.js

@ -36,7 +36,34 @@ function logStats (proc, data) {
console.log(log) console.log(log)
} }
module.exports = function startMain (callback) { function buildMain () {
return new Promise((resolve, reject) => {
mainConfig.mode = 'production'
webpack(mainConfig, (err, stats) => {
if (err) reject(err.stack || err)
else if (stats.hasErrors()) {
let err = ''
stats.toString({
chunks: false,
colors: true
})
.split(/\r?\n/)
.forEach(line => {
err += ` ${line}\n`
})
reject(err)
} else {
resolve(stats.toString({
chunks: false,
colors: true
}))
}
})
})
}
function startMain (callback) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
mainConfig.entry.main = [path.join(__dirname, '../../src/main/index.ts')]//.concat(mainConfig.entry.main) mainConfig.entry.main = [path.join(__dirname, '../../src/main/index.ts')]//.concat(mainConfig.entry.main)
mainConfig.mode = 'development' mainConfig.mode = 'development'
@ -56,12 +83,16 @@ module.exports = function startMain (callback) {
logStats('Main', stats) logStats('Main', stats)
callback&&callback() callback && callback()
resolve() resolve()
}) })
}) })
} }
module.exports = {
startMain,
buildMain,
}
function electronLog (data, color) { function electronLog (data, color) {

5
script/webpack/webpack.main.config.js

@ -29,9 +29,10 @@ let mainConfig = {
} }
] ]
}, },
// https://www.webpackjs.com/configuration/node/
node: { node: {
__dirname: process.env.NODE_ENV !== 'production', // __dirname: process.env.NODE_ENV !== 'production', // 不转化为字符串
__filename: process.env.NODE_ENV !== 'production' // __filename: process.env.NODE_ENV !== 'production' // 不转化为字符串
}, },
output: { output: {
filename: 'entry.js', // [name] filename: 'entry.js', // [name]

Loading…
Cancel
Save