Skip to content

Commit b364da9

Browse files
feat: keysAsFunctions
1 parent d0740d5 commit b364da9

File tree

6 files changed

+52
-52
lines changed

6 files changed

+52
-52
lines changed

lib/plugins/mdsvex/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports.default = {
1919
svelte: {
2020
preprocess: [
2121
mdsvex({
22+
extension: '.md',
2223
...app.config.mdsvex,
2324
...params
2425
})

lib/plugins/postcss/index.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
export default {
23
dependencies: {
34
'preprocess': () => import('../preprocess')
@@ -6,10 +7,14 @@ export default {
67
{
78
event: 'start',
89
action: async (app, params) => {
10+
const postcssImport = (await import('postcss-import')).default
911
app.merge({
1012
config: {
1113
postcss: {
12-
plugins: []
14+
pluginsMap: { postcssImport },
15+
plugins: {
16+
postcssImport: {}
17+
}
1318
}
1419
}
1520
})
@@ -18,22 +23,25 @@ export default {
1823
{
1924
event: 'before:bundle',
2025
action: async (app, params) => {
26+
const { keysAsFunctions } = (await import('../../utils'))
27+
const { plugins, pluginsMap } = app.config.postcss
2128
const postcss = (await import('rollup-plugin-postcss')).default
2229
const autoPreprocess = (await import('svelte-preprocess')).default
23-
const postcssImport = (await import('postcss-import')).default
24-
const postcssCfg = { plugins: [postcssImport()] }
30+
app.config.postcss.plugins = await keysAsFunctions(plugins, pluginsMap)
31+
delete app.config.postcss.pluginsMap
2532

2633
app.merge({
2734
config: {
2835
rollup: {
29-
plugins: [
30-
postcss(postcssCfg)
31-
]
36+
pluginsMap: { postcss },
37+
plugins: {
38+
postcss: app.config.postcss
39+
}
3240
},
3341
svelte: {
3442
preprocess: [
3543
autoPreprocess({
36-
postcss: postcssCfg,
44+
postcss: app.config.postcss,
3745
defaults: { style: 'postcss' }
3846
})
3947
]

lib/plugins/rollup/rollup.compile.js

+6-30
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
11
/// <reference path="../../../typedef.js" />
22

3-
import svelte from 'rollup-plugin-svelte-hot'
4-
import resolve from '@rollup/plugin-node-resolve'
5-
import commonjs from '@rollup/plugin-commonjs'
6-
import { terser } from 'rollup-plugin-terser'
7-
import Hmr from 'rollup-plugin-hot'
8-
import livereload from 'rollup-plugin-livereload'
3+
const { keysAsFunctions } = require('../../utils')
94

105
/**@param {RoxiApp} app */
11-
export default function rollupConfig(app, params, ctx) {
12-
const { pluginsCfg } = app.config.rollup
13-
const { distDir, bundler } = app.config.roxi //todo no longer valid
14-
const { production } = app.state
15-
const isNollup = bundler === 'nollup'
16-
delete app.config.rollup.pluginsCfg
17-
18-
app.merge({
19-
config: {
20-
rollup: {
21-
plugins: [
22-
pluginsCfg.mainJsTransform,
23-
svelte(app.config.svelte),
24-
25-
// resolve matching modules from current working directory
26-
resolve(pluginsCfg.resolve),
27-
commonjs(),
28-
production && terser(), // minify
29-
// !production && isNollup && Hmr(pluginsCfg.hmr), // refresh only updated code
30-
!production && !isNollup && livereload(distDir), // refresh entire window when code is updated
31-
]
32-
}
33-
}
34-
})
6+
export default async function rollupConfig(app, params, ctx) {
7+
const { plugins, pluginsMap } = app.config.rollup
8+
delete app.config.rollup.pluginsMap
9+
app.config.rollup.plugins.svelte = app.config.svelte
10+
app.config.rollup.plugins = await keysAsFunctions(plugins, pluginsMap)
3511
}

lib/plugins/rollup/rollup.template.js

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11

2-
2+
const svelte = require('rollup-plugin-svelte-hot')
3+
const resolve = require('@rollup/plugin-node-resolve').default
4+
const commonjs = require('@rollup/plugin-commonjs')
5+
const { terser } = require('rollup-plugin-terser')
6+
const hmr = require('rollup-plugin-hot')
7+
const livereload = require('rollup-plugin-livereload')
38
const { readFileSync } = require('fs-extra')
49

510
/** @type {RoxiPluginHookFunction} */
611
module.exports = function rollup(app, params) {
12+
const isNollup = app.config.roxi.plugins.find(p => p.name === 'nollup')
713
const { buildDir, staticDir } = app.config.roxi
814
const { production } = app.state
915

@@ -14,13 +20,23 @@ module.exports = function rollup(app, params) {
1420
input: `src/main.js`,
1521
preserveEntrySignatures: false,
1622
output: {
17-
name: 'routify_app',
23+
name: 'roxi_app',
1824
sourcemap: true,
1925
format: 'esm', dir: buildDir
2026
},
21-
plugins: [],
22-
pluginsCfg: {
23-
mainJsTransform: {
27+
pluginsMap: { svelte, resolve, commonjs, terser, hmr, livereload },
28+
plugins: {
29+
terser: production && {},
30+
svelte: app.config.svelte,
31+
// resolve matching modules from current working directory
32+
resolve: {
33+
browser: true,
34+
dedupe: importee => !!importee.match(/svelte(\/|$)/)
35+
},
36+
commonjs: {},
37+
terser: production && {}, // minify
38+
livereload: !production && !isNollup && distDir,
39+
_mainJsTransform: {
2440
transform: (code, id) => {
2541
if (id.match(/[/\\]src[/\\]main.js$/)) {
2642
const tmpl = readFileSync(__dirname + '/../../shared/main.template.js', 'utf-8')
@@ -31,11 +47,8 @@ module.exports = function rollup(app, params) {
3147
}
3248
}
3349
},
34-
resolve: {
35-
browser: true,
36-
dedupe: importee => !!importee.match(/svelte(\/|$)/)
37-
},
38-
hmr: { inMemory: true, public: staticDir }
50+
51+
hmr: production && { inMemory: true, public: staticDir }
3952
},
4053
watch: {
4154
clearScreen: false,

lib/plugins/spassr/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ module.exports.default = {
1212
const spassr = {
1313
assetsDir: staticDir,
1414
entrypoint: template,
15-
inlineDynamicImports: true,
15+
ssrOptions: {
16+
inlineDynamicImports: true,
17+
},
1618
port,
1719
host,
1820
script,
@@ -34,11 +36,11 @@ module.exports.default = {
3436
action: (app, params) => {
3537
// run spassr. Params are from roxi.config.yaml
3638

37-
require('spassr').spassr({
38-
39+
const conf = {
3940
...app.config.spassr,
4041
...params
41-
})
42+
}
43+
require('spassr').spassr(conf)
4244
}
4345
}
4446
]

lib/utils/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function keysAsFunctions(obj, map) {
5353
`there's no map method named ${key}. Available methods: ${Object.keys(map)}.` +
5454
`\nRenaming to "_${key}" will hide this message.`
5555
)
56-
return fn ? fn(value) : value
56+
return fn && value ? fn(value) : value
5757
})
5858
return Promise.all(promises)
5959
}

0 commit comments

Comments
 (0)