mirror of https://github.com/tauri-apps/tauri
Feature/webpack (#62)
* feat(webpack) chain with safe tap & load tauri config * feat(config) add automaticStart option * mergefix * fix2
This commit is contained in:
parent
098033a6c8
commit
dc06913def
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(' ')}`
|
||||
]
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue