12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
- const tauriConfig = require('../helpers/tauri-config')
- const WebpackShellPlugin = require('webpack-shell-plugin')
- 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',
- minSize: 0,
- maxSize: Infinity,
- maxAsyncRequests: 1,
- maxInitialRequests: 1,
- automaticNameDelimiter: '~',
- name: true,
- cacheGroups: {
- styles: {
- name: 'styles',
- chunks: 'all'
- },
- commons: {
- name: 'vendors',
- chunks: 'all'
- }
- }
- })
- chain.output.filename('js/app.js')
- if (cfg.ctx.prod) {
- if (cfg.build.extractCSS) {
- chain.plugin('mini-css-extract')
- .tap(options => {
- options[0].filename = 'css/app.css'
- return options
- })
- }
- chain.plugin('html-webpack')
- .tap(options => {
- options[0].inlineSource = '.(js|css)$'
- return options
- })
- chain.module.rule('babel')
- .use('babel-loader')
- .tap(options => safeTap(options, () => {
- options.plugins.push([
- 'system-import-transformer', { // needs constant attention
- modules: 'common'
- }
- ])
- }))
- }
- const modules = {
- images: 'url-loader',
- fonts: 'url-loader',
- media: 'url-loader'
- }
- for (const module in modules) {
- chain.module.rule(module)
- .use(modules[module])
- .tap(options => safeTap(options, () => {
- options.limit = undefined
- }))
- }
- }
- if (cfg.ctx.prod && !cfg.tauri.embeddedServer.active) {
- 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(' ')}`
- ]
- }])
- }
- }
|