start on upgrading sapper
This commit is contained in:
parent
536fa97060
commit
3d6124fcc9
|
@ -6,3 +6,6 @@ templates/.*
|
||||||
assets/*.css
|
assets/*.css
|
||||||
/mastodon
|
/mastodon
|
||||||
mastodon.log
|
mastodon.log
|
||||||
|
/app/manifest
|
||||||
|
/build
|
||||||
|
/export
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { init } from 'sapper/runtime.js'
|
import { init } from 'sapper/runtime.js'
|
||||||
|
import { routes } from './manifest/client.js'
|
||||||
import { loadPolyfills } from '../routes/_utils/loadPolyfills'
|
import { loadPolyfills } from '../routes/_utils/loadPolyfills'
|
||||||
import '../routes/_utils/serviceWorkerClient'
|
import '../routes/_utils/serviceWorkerClient'
|
||||||
import '../routes/_utils/historyEvents'
|
import '../routes/_utils/historyEvents'
|
||||||
|
@ -7,5 +8,9 @@ import '../routes/_utils/loadingMask'
|
||||||
loadPolyfills().then(() => {
|
loadPolyfills().then(() => {
|
||||||
console.log('init()')
|
console.log('init()')
|
||||||
// `routes` is an array of route objects injected by Sapper
|
// `routes` is an array of route objects injected by Sapper
|
||||||
init(document.querySelector('#sapper'), __routes__)
|
init(document.querySelector('#sapper'), routes)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (module.hot) {
|
||||||
|
module.hot.accept()
|
||||||
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
const app = require('express')()
|
import express from 'express'
|
||||||
const compression = require('compression')
|
import compression from 'compression'
|
||||||
const sapper = require('sapper')
|
import sapper from 'sapper'
|
||||||
const serveStatic = require('serve-static')
|
import serveStatic from 'serve-static'
|
||||||
|
import { routes } from './manifest/server.js'
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
|
||||||
const { PORT = 4002 } = process.env
|
const { PORT = 4002 } = process.env
|
||||||
|
|
||||||
|
@ -16,7 +19,7 @@ app.use(compression({ threshold: 0 }))
|
||||||
|
|
||||||
app.use(serveStatic('assets'))
|
app.use(serveStatic('assets'))
|
||||||
|
|
||||||
app.use(sapper())
|
app.use(sapper({ routes }))
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`listening on port ${PORT}`)
|
console.log(`listening on port ${PORT}`)
|
|
@ -1,16 +1,16 @@
|
||||||
const timestamp = '__timestamp__'
|
import { timestamp, assets, shell, routes } from './manifest/service-worker.js'
|
||||||
|
|
||||||
const ASSETS = `cache${timestamp}`
|
const ASSETS = `cache${timestamp}`
|
||||||
|
|
||||||
// `shell` is an array of all the files generated by webpack,
|
// `shell` is an array of all the files generated by webpack,
|
||||||
// `assets` is an array of everything in the `assets` directory
|
// `assets` is an array of everything in the `assets` directory
|
||||||
const toCache = __shell__.concat(__assets__)
|
const toCache = shell.concat(assets)
|
||||||
.filter(filename => !filename.endsWith('.map'))
|
.filter(filename => !filename.endsWith('.map'))
|
||||||
.filter(filename => !filename.startsWith('apple-icon'))
|
.filter(filename => !filename.startsWith('apple-icon'))
|
||||||
const cached = new Set(toCache)
|
const cached = new Set(toCache)
|
||||||
|
|
||||||
// `routes` is an array of `{ pattern: RegExp }` objects that
|
// `routes` is an array of `{ pattern: RegExp }` objects that
|
||||||
// match the pages in your app
|
// match the pages in your app
|
||||||
const routes = __routes__
|
|
||||||
|
|
||||||
self.addEventListener('install', event => {
|
self.addEventListener('install', event => {
|
||||||
event.waitUntil((async function () {
|
event.waitUntil((async function () {
|
|
@ -103,7 +103,7 @@ body.offline,body.theme-hotpants.offline,body.theme-majesty.offline,body.theme-o
|
||||||
</svg><!-- end insert svg here -->
|
</svg><!-- end insert svg here -->
|
||||||
</svg>
|
</svg>
|
||||||
<!-- The application will be rendered inside this element,
|
<!-- The application will be rendered inside this element,
|
||||||
because `templates/main.js` references it -->
|
because `templates/client.js` references it -->
|
||||||
<div id='sapper'>%sapper.html%</div>
|
<div id='sapper'>%sapper.html%</div>
|
||||||
|
|
||||||
<!-- Toast.html gets rendered here -->
|
<!-- Toast.html gets rendered here -->
|
||||||
|
@ -115,9 +115,9 @@ body.offline,body.theme-hotpants.offline,body.theme-majesty.offline,body.theme-o
|
||||||
<!-- LoadingMask.html gets rendered here -->
|
<!-- LoadingMask.html gets rendered here -->
|
||||||
<div id="loading-mask" aria-hidden="true"></div>
|
<div id="loading-mask" aria-hidden="true"></div>
|
||||||
|
|
||||||
<!-- Sapper creates a <script> tag containing `templates/main.js`
|
<!-- Sapper creates a <script> tag containing `templates/client.js`
|
||||||
and anything else it needs to hydrate the app and
|
and anything else it needs to hydrate the app and
|
||||||
initialise the router -->
|
initialise the router -->
|
||||||
<script src='%sapper.main%'></script>
|
%sapper.scripts%
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -16,13 +16,13 @@ const now = require('performance-now')
|
||||||
const globalScss = path.join(__dirname, '../scss/global.scss')
|
const globalScss = path.join(__dirname, '../scss/global.scss')
|
||||||
const defaultThemeScss = path.join(__dirname, '../scss/themes/_default.scss')
|
const defaultThemeScss = path.join(__dirname, '../scss/themes/_default.scss')
|
||||||
const offlineThemeScss = path.join(__dirname, '../scss/themes/_offline.scss')
|
const offlineThemeScss = path.join(__dirname, '../scss/themes/_offline.scss')
|
||||||
const html2xxFile = path.join(__dirname, '../templates/2xx.html')
|
const html2xxFile = path.join(__dirname, '../app/template.html')
|
||||||
const scssDir = path.join(__dirname, '../scss')
|
const scssDir = path.join(__dirname, '../scss')
|
||||||
const themesScssDir = path.join(__dirname, '../scss/themes')
|
const themesScssDir = path.join(__dirname, '../scss/themes')
|
||||||
const assetsDir = path.join(__dirname, '../assets')
|
const assetsDir = path.join(__dirname, '../assets')
|
||||||
|
|
||||||
function doWatch () {
|
function doWatch () {
|
||||||
var start = now()
|
let start = now()
|
||||||
chokidar.watch(scssDir).on('change', debounce(() => {
|
chokidar.watch(scssDir).on('change', debounce(() => {
|
||||||
console.log('Recompiling SCSS...')
|
console.log('Recompiling SCSS...')
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
|
|
@ -28,7 +28,7 @@ async function main () {
|
||||||
|
|
||||||
result = `<svg xmlns="http://www.w3.org/2000/svg" style="display:none;">\n${result}\n</svg>`
|
result = `<svg xmlns="http://www.w3.org/2000/svg" style="display:none;">\n${result}\n</svg>`
|
||||||
|
|
||||||
let html2xxFilepath = path.join(__dirname, '../templates/2xx.html')
|
let html2xxFilepath = path.join(__dirname, '../app/template.html')
|
||||||
let html2xxFile = await readFile(html2xxFilepath, 'utf8')
|
let html2xxFile = await readFile(html2xxFilepath, 'utf8')
|
||||||
html2xxFile = html2xxFile.replace(
|
html2xxFile = html2xxFile.replace(
|
||||||
/<!-- insert svg here -->[\s\S]+<!-- end insert svg here -->/,
|
/<!-- insert svg here -->[\s\S]+<!-- end insert svg here -->/,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
|
@ -5,9 +5,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "standard",
|
"lint": "standard",
|
||||||
"dev": "npm run build-svg && run-p --race build-sass-watch serve",
|
"dev": "npm run build-svg && run-p --race build-sass-watch serve",
|
||||||
"serve": "node server.js",
|
"serve": "PORT=4002 sapper dev",
|
||||||
"build": "npm run globalize-css && npm run build-sass && npm run build-svg && sapper build && npm run deglobalize-css",
|
"build": "npm run globalize-css && npm run build-sass && npm run build-svg && sapper build && npm run deglobalize-css",
|
||||||
"start": "cross-env NODE_ENV=production node server.js",
|
"start": "PORT=4002 sapper start",
|
||||||
"build-and-start": "run-s build start",
|
"build-and-start": "run-s build start",
|
||||||
"build-svg": "node ./bin/build-svg.js",
|
"build-svg": "node ./bin/build-svg.js",
|
||||||
"build-sass": "node ./bin/build-sass.js",
|
"build-sass": "node ./bin/build-sass.js",
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
"pify": "^3.0.0",
|
"pify": "^3.0.0",
|
||||||
"quick-lru": "^1.1.0",
|
"quick-lru": "^1.1.0",
|
||||||
"requestidlecallback": "^0.3.0",
|
"requestidlecallback": "^0.3.0",
|
||||||
"sapper": "nolanlawson/sapper#monkey-patches",
|
"sapper": "nolanlawson/sapper#ignore-source-maps-built",
|
||||||
"serve-static": "^1.13.1",
|
"serve-static": "^1.13.1",
|
||||||
"standard": "^10.0.3",
|
"standard": "^10.0.3",
|
||||||
"stringz": "^0.4.0",
|
"stringz": "^0.4.0",
|
||||||
|
@ -116,6 +116,7 @@
|
||||||
"NODE_ENV": "production"
|
"NODE_ENV": "production"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
"app",
|
||||||
"assets",
|
"assets",
|
||||||
"bin",
|
"bin",
|
||||||
"original-assets",
|
"original-assets",
|
||||||
|
@ -124,9 +125,7 @@
|
||||||
"templates",
|
"templates",
|
||||||
"package.json",
|
"package.json",
|
||||||
"package-lock.json",
|
"package-lock.json",
|
||||||
"server.js",
|
"webpack"
|
||||||
"webpack.client.config.js",
|
|
||||||
"webpack.server.config.js"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
{{#each $loggedInInstancesAsList as instance}}
|
{{#each $loggedInInstancesAsList as instance}}
|
||||||
<SettingsListItem offsetForIcon="{{instance.name !== $currentInstance}}"
|
<SettingsListItem offsetForIcon="{{instance.name !== $currentInstance}}"
|
||||||
icon="{{instance.name === $currentInstance ? '#fa-star' : ''}}"
|
icon="{{instance.name === $currentInstance ? '#fa-star' : ''}}"
|
||||||
href="/settings/instances/{{instance.name}}"
|
href="/settings/instances/list/{{instance.name}}"
|
||||||
label="{{instance.name}}"
|
label="{{instance.name}}"
|
||||||
ariaLabel="{{instance.name}} {{instance.name === $currentInstance ? '(current instance)' : ''}}" />
|
ariaLabel="{{instance.name}} {{instance.name === $currentInstance ? '(current instance)' : ''}}" />
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -91,18 +91,18 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
import { store } from '../../../_store/store'
|
import { store } from '../../../../_store/store'
|
||||||
import SettingsLayout from '../../../_components/settings/SettingsLayout.html'
|
import SettingsLayout from '../../../../_components/settings/SettingsLayout.html'
|
||||||
import ExternalLink from '../../../_components/ExternalLink.html'
|
import ExternalLink from '../../../../_components/ExternalLink.html'
|
||||||
import Avatar from '../../../_components/Avatar.html'
|
import Avatar from '../../../../_components/Avatar.html'
|
||||||
import { importDialogs } from '../../../_utils/asyncModules'
|
import { importDialogs } from '../../../../_utils/asyncModules'
|
||||||
import {
|
import {
|
||||||
changeTheme,
|
changeTheme,
|
||||||
switchToInstance,
|
switchToInstance,
|
||||||
logOutOfInstance,
|
logOutOfInstance,
|
||||||
updateVerifyCredentialsForInstance
|
updateVerifyCredentialsForInstance
|
||||||
} from '../../../_actions/instances'
|
} from '../../../../_actions/instances'
|
||||||
import { themes } from '../../../_static/themes'
|
import { themes } from '../../../../_static/themes'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
|
@ -5,9 +5,9 @@
|
||||||
<LazyPage :pageComponent :params />
|
<LazyPage :pageComponent :params />
|
||||||
</Layout>
|
</Layout>
|
||||||
<script>
|
<script>
|
||||||
import Layout from '../../_components/Layout.html'
|
import Layout from '../../../_components/Layout.html'
|
||||||
import LazyPage from '../../_components/LazyPage.html'
|
import LazyPage from '../../../_components/LazyPage.html'
|
||||||
import pageComponent from '../../_pages/settings/instances/[instanceName].html'
|
import pageComponent from '../../../_pages/settings/instances/list/[instanceName].html'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
|
@ -44,7 +44,7 @@ test('Logs in and logs out of localhost:3000', async t => {
|
||||||
.click(settingsButton)
|
.click(settingsButton)
|
||||||
.click($('a').withText('Instances'))
|
.click($('a').withText('Instances'))
|
||||||
.click($('a').withText('localhost:3000'))
|
.click($('a').withText('localhost:3000'))
|
||||||
.expect(getUrl()).contains('/settings/instances/localhost:3000')
|
.expect(getUrl()).contains('/settings/instances/list/localhost:3000')
|
||||||
.expect($('.instance-name-h1').innerText).eql('localhost:3000')
|
.expect($('.instance-name-h1').innerText).eql('localhost:3000')
|
||||||
.expect($('.acct-handle').innerText).eql('@foobar')
|
.expect($('.acct-handle').innerText).eql('@foobar')
|
||||||
.expect($('.acct-display-name').innerText).eql('foobar')
|
.expect($('.acct-display-name').innerText).eql('foobar')
|
||||||
|
|
|
@ -3,15 +3,16 @@ const config = require('sapper/webpack/config.js')
|
||||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
||||||
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
|
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
|
||||||
|
|
||||||
const isDev = config.dev
|
const mode = process.env.NODE_ENV
|
||||||
|
const isDev = mode === 'development'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: config.client.entry(),
|
entry: config.client.entry(),
|
||||||
output: config.client.output(),
|
output: config.client.output(),
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js', '.html']
|
extensions: ['.js', '.json', '.html']
|
||||||
},
|
},
|
||||||
mode: isDev ? 'development' : 'production',
|
mode,
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
|
@ -21,50 +22,28 @@ module.exports = {
|
||||||
loader: 'svelte-loader',
|
loader: 'svelte-loader',
|
||||||
options: {
|
options: {
|
||||||
hydratable: true,
|
hydratable: true,
|
||||||
emitCss: !isDev,
|
|
||||||
cascade: false,
|
cascade: false,
|
||||||
store: true
|
store: true,
|
||||||
|
hotReload: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
isDev && {
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [
|
|
||||||
{ loader: 'style-loader' },
|
|
||||||
{ loader: 'css-loader' }
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
!isDev && {
|
|
||||||
test: /\.css$/,
|
|
||||||
/* disable while https://github.com/sveltejs/sapper/issues/79 is open */
|
|
||||||
/* use: ExtractTextPlugin.extract({
|
|
||||||
fallback: 'style-loader',
|
|
||||||
use: [{ loader: 'css-loader', options: { sourceMap:isDev } }]
|
|
||||||
}) */
|
|
||||||
use: [
|
|
||||||
{ loader: 'style-loader' },
|
|
||||||
{ loader: 'css-loader' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
].filter(Boolean)
|
|
||||||
},
|
|
||||||
node: {
|
node: {
|
||||||
setImmediate: false
|
setImmediate: false
|
||||||
},
|
},
|
||||||
plugins: isDev ? [
|
plugins: [
|
||||||
new webpack.HotModuleReplacementPlugin()
|
isDev && new webpack.HotModuleReplacementPlugin(),
|
||||||
] : [
|
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.browser': true,
|
'process.browser': true,
|
||||||
'process.env.NODE_ENV': '"production"'
|
'process.env.NODE_ENV': JSON.stringify(mode)
|
||||||
}),
|
}),
|
||||||
/* disable while https://github.com/sveltejs/sapper/issues/79 is open */
|
|
||||||
// new ExtractTextPlugin('main.css'),
|
|
||||||
new LodashModuleReplacementPlugin({
|
new LodashModuleReplacementPlugin({
|
||||||
collections: true,
|
collections: true,
|
||||||
caching: true
|
caching: true
|
||||||
}),
|
}),
|
||||||
new BundleAnalyzerPlugin({ // generates report.html and stats.json
|
!isDev && new BundleAnalyzerPlugin({ // generates report.html and stats.json
|
||||||
analyzerMode: 'static',
|
analyzerMode: 'static',
|
||||||
generateStatsFile: true,
|
generateStatsFile: true,
|
||||||
statsOptions: {
|
statsOptions: {
|
||||||
|
@ -74,6 +53,6 @@ module.exports = {
|
||||||
openAnalyzer: false,
|
openAnalyzer: false,
|
||||||
logLevel: 'silent' // do not bother Webpacker, who runs with --json and parses stdout
|
logLevel: 'silent' // do not bother Webpacker, who runs with --json and parses stdout
|
||||||
})
|
})
|
||||||
],
|
].filter(Boolean),
|
||||||
devtool: isDev ? 'cheap-module-source-map' : 'source-map'
|
devtool: isDev ? 'inline-source-map' : 'source-map'
|
||||||
}
|
}
|
|
@ -1,12 +1,14 @@
|
||||||
const config = require('sapper/webpack/config.js')
|
const config = require('sapper/webpack/config.js')
|
||||||
|
const pkg = require('../package.json')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: config.server.entry(),
|
entry: config.server.entry(),
|
||||||
output: config.server.output(),
|
output: config.server.output(),
|
||||||
target: 'node',
|
target: 'node',
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js', '.html']
|
extensions: ['.js', '.json', '.html']
|
||||||
},
|
},
|
||||||
|
externals: Object.keys(pkg.dependencies),
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
|
@ -23,5 +25,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
mode: process.env.NODE_ENV,
|
||||||
|
performance: {
|
||||||
|
hints: false // it doesn't matter if server.js is large
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
const config = require('sapper/webpack/config.js')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: config.serviceworker.entry(),
|
||||||
|
output: config.serviceworker.output(),
|
||||||
|
mode: process.env.NODE_ENV
|
||||||
|
}
|
Loading…
Reference in New Issue