diff --git a/mode/bin/tauri-build.js b/mode/bin/tauri-build.js index 3840dc19d..733fcbda2 100644 --- a/mode/bin/tauri-build.js +++ b/mode/bin/tauri-build.js @@ -26,7 +26,8 @@ const Runner = require('../runner') const tauri = new Runner({ modeDir: tauriDir }) const tauriConfig = require('../helpers/tauri-config')({ ctx: { - debug: argv.debug + debug: argv.debug, + prod: true } }) diff --git a/mode/helpers/tauri-config.js b/mode/helpers/tauri-config.js index 45275ad4a..5842da594 100644 --- a/mode/helpers/tauri-config.js +++ b/mode/helpers/tauri-config.js @@ -23,6 +23,11 @@ module.exports = cfg => { }, security: { csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' + }, + automaticStart: { + active: false, + devArgs: [], + buildArgs: [] } } }, tauriConf, cfg) diff --git a/mode/webpack/index.js b/mode/webpack/index.js index dc344520f..92b8f178e 100644 --- a/mode/webpack/index.js +++ b/mode/webpack/index.js @@ -1,6 +1,21 @@ const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin') +const tauriConfig = require('../helpers/tauri-config') +const WebpackShellPlugin = require('webpack-shell-plugin') -module.exports.chain = function (chain, cfg) { +const safeTap = (options, cb) => { + if (options !== undefined) { + cb() + } + return options +} + +module.exports.chain = function (chain) { + const cfg = tauriConfig({ + ctx: { + debug: process.env.NODE_ENV !== 'production', + prod: process.env.NODE_ENV === 'production' + } + }) if (!cfg.tauri.embeddedServer.active) { chain.optimization.splitChunks({ chunks: 'all', @@ -41,14 +56,13 @@ module.exports.chain = function (chain, cfg) { chain.module.rule('babel') .use('babel-loader') - .tap(options => { + .tap(options => safeTap(() => { options.plugins.push([ 'system-import-transformer', { // needs constant attention modules: 'common' } ]) - return options - }) + })) } const modules = { @@ -59,10 +73,9 @@ module.exports.chain = function (chain, cfg) { for (const module in modules) { chain.module.rule(module) .use(modules[module]) - .tap(options => { + .tap(options => safeTap(options, () => { options.limit = undefined - return options - }) + })) } } @@ -70,4 +83,15 @@ module.exports.chain = function (chain, cfg) { chain.plugin('html-webpack-inline-source') .use(HtmlWebpackInlineSourcePlugin) } + + if (cfg.tauri.automaticStart.active) { + chain.plugin('webpack-shell-plugin') + .use(WebpackShellPlugin, [{ + onBuildEnd: [ + cfg.ctx.prod + ? `tauri build${cfg.tauri.automaticStart.buildArgs.join(' ')}` + : `tauri dev${cfg.tauri.automaticStart.devArgs.join(' ')}` + ] + }]) + } } diff --git a/package.json b/package.json index 7f55b1e36..a21396c38 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,8 @@ "jest": "24.9.0", "jest-mock-process": "^1.2.0", "lint-staged": "^9.4.2", - "promise": "^8.0.3" + "promise": "^8.0.3", + "webpack-shell-plugin": "^0.5.0" }, "husky": { "hooks": { diff --git a/templates/conf/tauri.conf.js b/templates/conf/tauri.conf.js index f2bb958cc..344bf2e11 100644 --- a/templates/conf/tauri.conf.js +++ b/templates/conf/tauri.conf.js @@ -1,5 +1,6 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './dist') +const + path = require('path'); + const distDir = path.resolve(__dirname, './dist') module.exports = function () { return { @@ -24,6 +25,7 @@ module.exports = function () { security: { csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' } - } + }, + edge: true } } diff --git a/yarn.lock b/yarn.lock index ef12e13f1..c88ec6bf6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6307,6 +6307,11 @@ webpack-merge@^4.2.1: dependencies: lodash "^4.17.5" +webpack-shell-plugin@^0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/webpack-shell-plugin/-/webpack-shell-plugin-0.5.0.tgz#29b8a1d80ddeae0ddb10e729667f728653c2c742" + integrity sha1-Kbih2A3erg3bEOcpZn9yhlPCx0I= + whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3: version "1.0.5" resolved "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0"