mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-21 14:55:04 +00:00
posixify import paths
This commit is contained in:
@@ -3,6 +3,10 @@ const path = require('path');
|
|||||||
const route_manager = require('../route_manager.js');
|
const route_manager = require('../route_manager.js');
|
||||||
const { src, dest, server_routes, dev } = require('../config.js');
|
const { src, dest, server_routes, dev } = require('../config.js');
|
||||||
|
|
||||||
|
function posixify(file) {
|
||||||
|
return file.replace(/[\/\\]/g, '/');
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function create_app() {
|
module.exports = function create_app() {
|
||||||
const { routes } = route_manager;
|
const { routes } = route_manager;
|
||||||
|
|
||||||
@@ -17,13 +21,14 @@ module.exports = function create_app() {
|
|||||||
'{}' :
|
'{}' :
|
||||||
`{ ${route.dynamic.map((part, i) => `${part}: match[${i + 1}]`).join(', ') } }`;
|
`{ ${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}') }`
|
const file = posixify(`${src}/${route.file}`);
|
||||||
|
return `{ pattern: ${route.pattern}, params: match => (${params}), load: () => import(/* webpackChunkName: "${route.id}" */ '${file}') }`
|
||||||
})
|
})
|
||||||
.join(', ')
|
.join(', ')
|
||||||
}]`;
|
}]`;
|
||||||
|
|
||||||
let main = template
|
let main = template
|
||||||
.replace(/__app__/g, path.resolve(__dirname, '../../runtime/app.js'))
|
.replace(/__app__/g, posixify(path.resolve(__dirname, '../../runtime/app.js')))
|
||||||
.replace(/__routes__/g, code)
|
.replace(/__routes__/g, code)
|
||||||
.replace(/__dev__/g, String(dev));
|
.replace(/__dev__/g, String(dev));
|
||||||
|
|
||||||
@@ -44,9 +49,10 @@ module.exports = function create_app() {
|
|||||||
function create_server_routes() {
|
function create_server_routes() {
|
||||||
const imports = routes
|
const imports = routes
|
||||||
.map(route => {
|
.map(route => {
|
||||||
|
const file = posixify(`${src}/${route.file}`);
|
||||||
return route.type === 'page' ?
|
return route.type === 'page' ?
|
||||||
`import ${route.id} from '${src}/${route.file}';` :
|
`import ${route.id} from '${file}';` :
|
||||||
`import * as ${route.id} from '${src}/${route.file}';`;
|
`import * as ${route.id} from '${file}';`;
|
||||||
})
|
})
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user