Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit f7ab9f8

Browse files
committed
Add basic settings dialog shell in Vue
1 parent eb5b8c5 commit f7ab9f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3590
-128
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
22
app/node_modules
3-
app/build/*
3+
app/dist
44
!app/build/.gitkeep
55
app/env/google-application-credentials.json
66
app/npm-debug.log

app/build/css/build.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
132 KB
Binary file not shown.
162 KB
Binary file not shown.

app/build/font-awesome/fontawesome-webfont.svg

Lines changed: 2671 additions & 0 deletions
Loading
162 KB
Binary file not shown.
95.7 KB
Binary file not shown.
75.4 KB
Binary file not shown.

app/build/js/build-home.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build/js/build.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build/setup-dev-server.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const MFS = require('memory-fs')
4+
const webpack = require('webpack')
5+
const chokidar = require('chokidar')
6+
const clientConfig = require('./webpack.client.config')
7+
const serverConfig = require('./webpack.server.config')
8+
9+
const readFile = (fs, file) => {
10+
try {
11+
return fs.readFileSync(path.join(clientConfig.output.path, file), 'utf-8')
12+
} catch (e) {}
13+
}
14+
15+
module.exports = function setupDevServer (app, templatePath, cb) {
16+
let bundle
17+
let template
18+
let clientManifest
19+
20+
let ready
21+
const readyPromise = new Promise(r => { ready = r })
22+
const update = () => {
23+
if (bundle && clientManifest) {
24+
ready()
25+
cb(bundle, {
26+
template,
27+
clientManifest
28+
})
29+
}
30+
}
31+
32+
// read template from disk and watch
33+
template = fs.readFileSync(templatePath, 'utf-8')
34+
chokidar.watch(templatePath).on('change', () => {
35+
template = fs.readFileSync(templatePath, 'utf-8')
36+
console.log('index.html template updated.')
37+
update()
38+
})
39+
40+
// modify client config to work with hot middleware
41+
clientConfig.entry.app = ['webpack-hot-middleware/client', clientConfig.entry.app]
42+
clientConfig.output.filename = '[name].js'
43+
clientConfig.plugins.push(
44+
new webpack.HotModuleReplacementPlugin(),
45+
new webpack.NoEmitOnErrorsPlugin()
46+
)
47+
48+
// dev middleware
49+
const clientCompiler = webpack(clientConfig)
50+
const devMiddleware = require('webpack-dev-middleware')(clientCompiler, {
51+
publicPath: clientConfig.output.publicPath,
52+
noInfo: true
53+
})
54+
app.use(devMiddleware)
55+
clientCompiler.plugin('done', stats => {
56+
stats = stats.toJson()
57+
stats.errors.forEach(err => console.error(err))
58+
stats.warnings.forEach(err => console.warn(err))
59+
if (stats.errors.length) return
60+
clientManifest = JSON.parse(readFile(
61+
devMiddleware.fileSystem,
62+
'vue-ssr-client-manifest.json'
63+
))
64+
update()
65+
})
66+
67+
// hot middleware
68+
app.use(require('webpack-hot-middleware')(clientCompiler, { heartbeat: 5000 }))
69+
70+
// watch and update server renderer
71+
const serverCompiler = webpack(serverConfig)
72+
const mfs = new MFS()
73+
serverCompiler.outputFileSystem = mfs
74+
serverCompiler.watch({}, (err, stats) => {
75+
if (err) throw err
76+
stats = stats.toJson()
77+
if (stats.errors.length) return
78+
79+
// read bundle generated by vue-ssr-webpack-plugin
80+
bundle = JSON.parse(readFile(mfs, 'vue-ssr-server-bundle.json'))
81+
update()
82+
})
83+
84+
return readyPromise
85+
}

app/build/vue-loader.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
extractCSS: process.env.NODE_ENV === 'production',
3+
preserveWhitespace: false,
4+
postcss: [
5+
require('autoprefixer')({
6+
browsers: ['last 3 versions']
7+
})
8+
]
9+
}

app/build/webpack.base.config.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const path = require('path')
2+
const webpack = require('webpack')
3+
const vueConfig = require('./vue-loader.config')
4+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
5+
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
6+
7+
const isProd = process.env.NODE_ENV === 'production'
8+
9+
module.exports = {
10+
devtool: isProd
11+
? false
12+
: '#cheap-module-source-map',
13+
output: {
14+
path: path.resolve(__dirname, '../dist'),
15+
publicPath: '/dist/',
16+
filename: '[name].[chunkhash].js'
17+
},
18+
resolve: {
19+
alias: {
20+
'public': path.resolve(__dirname, '../public')
21+
}
22+
},
23+
module: {
24+
noParse: /es6-promise\.js$/, // avoid webpack shimming process
25+
rules: [
26+
{
27+
test: /\.vue$/,
28+
loader: 'vue-loader',
29+
options: vueConfig
30+
},
31+
{
32+
test: /\.js$/,
33+
loader: 'babel-loader',
34+
exclude: /node_modules/
35+
},
36+
{
37+
test: /\.(png|jpg|gif|svg|ttf|woff|woff2|eot)$/,
38+
loader: 'url-loader',
39+
options: {
40+
limit: 10000,
41+
name: '[name].[ext]?[hash]'
42+
}
43+
},
44+
{
45+
test: /\.css$/,
46+
use: isProd
47+
? ExtractTextPlugin.extract({
48+
use: 'css-loader?minimize',
49+
fallback: 'vue-style-loader'
50+
})
51+
: ['vue-style-loader', 'css-loader']
52+
},
53+
{
54+
test: /\.scss$/,
55+
loader: 'sass-loader'
56+
},
57+
]
58+
},
59+
performance: {
60+
maxEntrypointSize: 300000,
61+
hints: isProd ? 'warning' : false
62+
},
63+
plugins: isProd
64+
? [
65+
new webpack.optimize.UglifyJsPlugin({
66+
compress: { warnings: false }
67+
}),
68+
new webpack.optimize.ModuleConcatenationPlugin(),
69+
new ExtractTextPlugin({
70+
filename: 'common.[chunkhash].css'
71+
})
72+
]
73+
: [
74+
new FriendlyErrorsPlugin()
75+
]
76+
}

app/build/webpack.client.config.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const webpack = require('webpack')
2+
const merge = require('webpack-merge')
3+
const base = require('./webpack.base.config')
4+
const SWPrecachePlugin = require('sw-precache-webpack-plugin')
5+
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')
6+
7+
const config = merge(base, {
8+
entry: {
9+
app: './src/entry-client.js'
10+
},
11+
resolve: {
12+
alias: {
13+
'create-api': './create-api-client.js'
14+
}
15+
},
16+
plugins: [
17+
// strip dev-only code in Vue source
18+
new webpack.DefinePlugin({
19+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
20+
'process.env.VUE_ENV': '"client"'
21+
}),
22+
// extract vendor chunks for better caching
23+
new webpack.optimize.CommonsChunkPlugin({
24+
name: 'vendor',
25+
minChunks: function (module) {
26+
// a module is extracted into the vendor chunk if...
27+
return (
28+
// it's inside node_modules
29+
/node_modules/.test(module.context) &&
30+
// and not a CSS file (due to extract-text-webpack-plugin limitation)
31+
!/\.css$/.test(module.request)
32+
)
33+
}
34+
}),
35+
// extract webpack runtime & manifest to avoid vendor chunk hash changing
36+
// on every build.
37+
new webpack.optimize.CommonsChunkPlugin({
38+
name: 'manifest'
39+
}),
40+
new VueSSRClientPlugin()
41+
]
42+
})
43+
44+
if (process.env.NODE_ENV === 'production') {
45+
config.plugins.push(
46+
// auto generate service worker
47+
new SWPrecachePlugin({
48+
cacheId: 'vue-hn',
49+
filename: 'service-worker.js',
50+
minify: true,
51+
dontCacheBustUrlsMatching: /./,
52+
staticFileGlobsIgnorePatterns: [/\.map$/, /\.json$/],
53+
runtimeCaching: [
54+
{
55+
urlPattern: '/',
56+
handler: 'networkFirst'
57+
},
58+
{
59+
urlPattern: /\/(top|new|show|ask|jobs)/,
60+
handler: 'networkFirst'
61+
},
62+
{
63+
urlPattern: '/item/:id',
64+
handler: 'networkFirst'
65+
},
66+
{
67+
urlPattern: '/user/:id',
68+
handler: 'networkFirst'
69+
}
70+
]
71+
})
72+
)
73+
}
74+
75+
module.exports = config

app/build/webpack.server.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const webpack = require('webpack')
2+
const merge = require('webpack-merge')
3+
const base = require('./webpack.base.config')
4+
const nodeExternals = require('webpack-node-externals')
5+
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
6+
7+
module.exports = merge(base, {
8+
target: 'node',
9+
devtool: '#source-map',
10+
entry: './src/entry-server.js',
11+
output: {
12+
filename: 'server-bundle.js',
13+
libraryTarget: 'commonjs2'
14+
},
15+
resolve: {
16+
alias: {
17+
'create-api': './create-api-server.js'
18+
}
19+
},
20+
// https://webpack.js.org/configuration/externals/#externals
21+
// https://github.com/liady/webpack-node-externals
22+
externals: nodeExternals({
23+
// do not externalize CSS files in case we need to import it from a dep
24+
whitelist: /\.css$/
25+
}),
26+
plugins: [
27+
new webpack.DefinePlugin({
28+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
29+
'process.env.VUE_ENV': '"server"'
30+
}),
31+
new VueSSRServerPlugin()
32+
]
33+
})

0 commit comments

Comments
 (0)