1- module . exports = api => {
1+ module . exports = ( api , options ) => {
2+ // If plugin options are provided in vue.config.js, those will be used. Otherwise it is empty object
3+ const pluginOptions =
4+ options . pluginOptions && options . pluginOptions . electronBuilder
5+ ? options . pluginOptions . electronBuilder
6+ : { }
7+
8+ api . chainWebpack ( cfg => {
9+ if ( process . env . TAURI_BUILD ) {
10+ // Setup require for no-server mode
11+ const TauriRequirePlugin = require ( '@tauri-apps/tauri-webpack/plugins/tauri-require' )
12+ . plugin
13+ cfg . plugin ( 'tauri-require' ) . use ( TauriRequirePlugin )
14+
15+ // Set IS_TAURI
16+ if ( cfg . plugins . has ( 'define' ) ) {
17+ cfg . plugin ( 'define' ) . tap ( args => {
18+ args [ 0 ] [ 'process.env' ] . IS_TAURI = true
19+ return args
20+ } )
21+ } else {
22+ cfg . plugin ( 'define' ) . use ( DefinePlugin , [
23+ {
24+ 'process.env' : { IS_TAURI : true }
25+ }
26+ ] )
27+ }
28+
29+ // Apply custom config from user
30+ if ( pluginOptions . chainWebpack ) {
31+ pluginOptions . chainWebpack ( cfg )
32+ }
33+ }
34+ } )
35+
236 api . registerCommand (
337 'tauri:serve' ,
438 {
@@ -7,25 +41,15 @@ module.exports = api => {
741 usage : 'todo'
842 } ,
943 async ( ) => {
10- const { tauriDir } = require ( 'tauri/helpers/app-paths' )
11- const Runner = require ( 'tauri/runner' )
12- const tauri = new Runner ( )
44+ const dev = require ( 'tauri/api/dev' )
1345
1446 const server = await api . service . run ( 'serve' )
1547
16- const tauriConfig = require ( 'tauri/helpers/tauri-config' ) ( {
17- ctx : {
18- debug : true
19- } ,
48+ return dev ( {
2049 build : {
2150 devPath : server . url
2251 }
2352 } )
24-
25- require ( 'tauri/generator' ) . generate ( tauriConfig . tauri )
26- require ( 'tauri/entry' ) . generate ( tauriDir , tauriConfig )
27-
28- tauri . run ( tauriConfig )
2953 }
3054 )
3155
@@ -37,33 +61,31 @@ module.exports = api => {
3761 usage : 'todo'
3862 } ,
3963 async args => {
40- const { tauriDir } = require ( 'tauri/helpers/app-paths' )
41- const Runner = require ( 'tauri/runner' )
42- const tauri = new Runner ( )
43- const tauriConfig = require ( 'tauri/helpers/tauri-config' ) ( {
44- ctx : {
45- debug : args . debug ,
46- modeDir : tauriDir
47- } ,
64+ const build = require ( 'tauri/api/build' )
65+
66+ // Use custom config for webpack
67+ process . env . TAURI_BUILD = true
68+ // Set publicPath so that scripts are properly imported
69+ options . publicPath = './'
70+
71+ if ( ! args . skipBundle ) {
72+ try {
73+ await api . service . run ( 'build' , {
74+ dest : 'dist_tauri/bundled'
75+ } )
76+ } catch ( e ) {
77+ error (
78+ 'Vue CLI build failed. Please resolve any issues with your build and try again.'
79+ )
80+ process . exit ( 1 )
81+ }
82+ }
83+
84+ build ( {
4885 build : {
4986 distDir : 'dist_tauri/bundled'
5087 }
5188 } )
52- require ( 'tauri/generator' ) . generate ( tauriConfig . tauri )
53- require ( 'tauri/entry' ) . generate ( tauriDir , tauriConfig )
54-
55- try {
56- await api . service . run ( 'build' , {
57- dest : 'dist_tauri/bundled'
58- } )
59- } catch ( e ) {
60- error (
61- 'Vue CLI build failed. Please resolve any issues with your build and try again.'
62- )
63- process . exit ( 1 )
64- }
65-
66- tauri . build ( tauriConfig )
6789 }
6890 )
6991}
0 commit comments