mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 11:15:14 +00:00
expose main.js
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { main_built } = require('../config.js');
|
||||
|
||||
const template = fs.readFileSync(path.resolve(__dirname, '../../templates/main.js'), 'utf-8');
|
||||
const template = fs.readFileSync('templates/main.js', 'utf-8');
|
||||
|
||||
module.exports = function create_app(src, dest, routes, options) {
|
||||
// TODO in dev mode, watch files
|
||||
|
||||
const code = routes
|
||||
.filter(route => route.type === 'page')
|
||||
.map(route => {
|
||||
const params = route.dynamic.length === 0 ?
|
||||
'{}' :
|
||||
`{ ${route.dynamic.map((part, i) => `${part}: match[${i + 1}]`).join(', ') } }`;
|
||||
const code = `[${
|
||||
routes
|
||||
.filter(route => route.type === 'page')
|
||||
.map(route => {
|
||||
const params = route.dynamic.length === 0 ?
|
||||
'{}' :
|
||||
`{ ${route.dynamic.map((part, i) => `${part}: match[${i + 1}]`).join(', ') } }`;
|
||||
|
||||
return `{ pattern: ${route.pattern}, params: match => (${params}), load: () => import(/* webpackChunkName: "${route.id}" */ '${src}/${route.file}') }`
|
||||
})
|
||||
.join(',\n\t');
|
||||
return `{ pattern: ${route.pattern}, params: match => (${params}), load: () => import(/* webpackChunkName: "${route.id}" */ '${src}/${route.file}') }`
|
||||
})
|
||||
.join(', ')
|
||||
}]`;
|
||||
|
||||
const main = template
|
||||
.replace('__app__', path.resolve(__dirname, '../../runtime/app.js'))
|
||||
.replace('__selector__', options.selector || 'main')
|
||||
.replace('__routes__', code);
|
||||
const main = template.replace('__routes__', code);
|
||||
|
||||
fs.writeFileSync(path.join(dest, 'main.js'), main);
|
||||
fs.writeFileSync(main_built, main);
|
||||
};
|
||||
Reference in New Issue
Block a user