forked from vuestorefront/vue-storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
549 changed files
with
19,888 additions
and
13,844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,135 @@ | ||
import { Store } from 'vuex' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import Vue from 'vue' | ||
import buildTimeConfig from 'config' | ||
import { isServer } from '@vue-storefront/core/helpers' | ||
import { Logger } from '@vue-storefront/core/lib/logger' | ||
import { Store } from 'vuex'; | ||
import RootState from '@vue-storefront/core/types/RootState'; | ||
import Vue from 'vue'; | ||
import buildTimeConfig from 'config'; | ||
import { isServer } from '@vue-storefront/core/helpers'; | ||
import { Logger } from '@vue-storefront/core/lib/logger'; | ||
|
||
// Plugins | ||
import i18n from '@vue-storefront/i18n' | ||
import VueRouter from 'vue-router' | ||
import VueLazyload from 'vue-lazyload' | ||
import Vuelidate from 'vuelidate' | ||
import Meta from 'vue-meta' | ||
import { sync } from 'vuex-router-sync' | ||
import VueObserveVisibility from 'vue-observe-visibility' | ||
import i18n from '@vue-storefront/i18n'; | ||
import VueRouter from 'vue-router'; | ||
import VueLazyload from 'vue-lazyload'; | ||
import Vuelidate from 'vuelidate'; | ||
import Meta from 'vue-meta'; | ||
import { sync } from 'vuex-router-sync'; | ||
import VueObserveVisibility from 'vue-observe-visibility'; | ||
|
||
// Apollo GraphQL client | ||
import { getApolloProvider } from './scripts/resolvers/resolveGraphQL' | ||
import { getApolloProvider } from './scripts/resolvers/resolveGraphQL'; | ||
|
||
// TODO simplify by removing global mixins, plugins and filters - it can be done in normal 'vue' way | ||
import { registerTheme } from '@vue-storefront/core/lib/themes' | ||
import { themeEntry } from 'theme/index.js' | ||
import { registerModules } from '@vue-storefront/core/lib/module' | ||
import { prepareStoreView } from '@vue-storefront/core/lib/multistore' | ||
import { registerTheme } from '@vue-storefront/core/lib/themes'; | ||
import { themeEntry } from 'theme/index.js'; | ||
import { registerModules } from '@vue-storefront/core/lib/module'; | ||
import { prepareStoreView } from '@vue-storefront/core/lib/multistore'; | ||
|
||
import * as coreMixins from '@vue-storefront/core/mixins' | ||
import * as coreFilters from '@vue-storefront/core/filters' | ||
import * as corePlugins from '@vue-storefront/core/compatibility/plugins' | ||
import * as coreMixins from '@vue-storefront/core/mixins'; | ||
import * as coreFilters from '@vue-storefront/core/filters'; | ||
import * as corePlugins from '@vue-storefront/core/compatibility/plugins'; | ||
|
||
import { once } from '@vue-storefront/core/helpers' | ||
import store from '@vue-storefront/core/store' | ||
import { once } from '@vue-storefront/core/helpers'; | ||
import store from '@vue-storefront/core/store'; | ||
|
||
import { enabledModules } from './modules-entry' | ||
import { enabledModules } from './modules-entry'; | ||
|
||
// Will be deprecated in 1.8 | ||
import { registerExtensions } from '@vue-storefront/core/compatibility/lib/extensions' | ||
import { registerExtensions as extensions } from 'src/extensions' | ||
import { registerExtensions } from '@vue-storefront/core/compatibility/lib/extensions'; | ||
import { registerExtensions as extensions } from 'src/extensions'; | ||
|
||
function createRouter (): VueRouter { | ||
function createRouter(): VueRouter { | ||
return new VueRouter({ | ||
mode: 'history', | ||
base: __dirname, | ||
scrollBehavior: (to, from, savedPosition) => { | ||
if (to.hash) { | ||
return { | ||
selector: to.hash | ||
} | ||
}; | ||
} | ||
if (savedPosition) { | ||
return savedPosition | ||
return savedPosition; | ||
} else { | ||
return {x: 0, y: 0} | ||
return { x: 0, y: 0 }; | ||
} | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
let router: VueRouter = null | ||
let router: VueRouter = null; | ||
|
||
once('__VUE_EXTEND_RR__', () => { | ||
Vue.use(VueRouter) | ||
}) | ||
|
||
const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vue, router: VueRouter, store: Store<RootState>}> => { | ||
router = createRouter() | ||
Vue.use(VueRouter); | ||
}); | ||
|
||
const createApp = async ( | ||
ssrContext, | ||
config, | ||
storeCode = null | ||
): Promise<{ app: Vue; router: VueRouter; store: Store<RootState> }> => { | ||
router = createRouter(); | ||
// sync router with vuex 'router' store | ||
sync(store, router) | ||
sync(store, router); | ||
// TODO: Don't mutate the state directly, use mutation instead | ||
store.state.version = process.env.APPVERSION | ||
store.state.config = config | ||
store.state.__DEMO_MODE__ = (config.demomode === true) ? true : false | ||
if(ssrContext) Vue.prototype.$ssrRequestContext = ssrContext | ||
if (!store.state.config) store.state.config = buildTimeConfig // if provided from SSR, don't replace it | ||
const storeView = prepareStoreView(storeCode) // prepare the default storeView | ||
store.state.storeView = storeView | ||
store.state.version = process.env.APPVERSION; | ||
store.state.config = config; | ||
store.state.__DEMO_MODE__ = config.demomode === true ? true : false; | ||
if (ssrContext) Vue.prototype.$ssrRequestContext = ssrContext; | ||
if (!store.state.config) store.state.config = buildTimeConfig; // if provided from SSR, don't replace it | ||
const storeView = prepareStoreView(storeCode); // prepare the default storeView | ||
store.state.storeView = storeView; | ||
// store.state.shipping.methods = shippingMethods | ||
|
||
|
||
// to depreciate in near future | ||
once('__VUE_EXTEND__', () => { | ||
Vue.use(Vuelidate) | ||
Vue.use(VueLazyload, {attempt: 2, preLoad: 1.5}) | ||
Vue.use(Meta) | ||
Vue.use(VueObserveVisibility) | ||
Vue.use(Vuelidate); | ||
Vue.use(VueLazyload, { attempt: 2, preLoad: 1.5 }); | ||
Vue.use(Meta); | ||
Vue.use(VueObserveVisibility); | ||
|
||
Object.keys(corePlugins).forEach(key => { | ||
Vue.use(corePlugins[key]) | ||
}) | ||
Vue.use(corePlugins[key]); | ||
}); | ||
|
||
Object.keys(coreMixins).forEach(key => { | ||
Vue.mixin(coreMixins[key]) | ||
}) | ||
}) | ||
Vue.mixin(coreMixins[key]); | ||
}); | ||
}); | ||
|
||
Object.keys(coreFilters).forEach(key => { | ||
Vue.filter(key, coreFilters[key]) | ||
}) | ||
Vue.filter(key, coreFilters[key]); | ||
}); | ||
|
||
let vueOptions = { | ||
router, | ||
store, | ||
i18n, | ||
render: h => h(themeEntry) | ||
} | ||
}; | ||
|
||
const apolloProvider = await getApolloProvider() | ||
if (apolloProvider) Object.assign(vueOptions, {provider: apolloProvider}) | ||
const apolloProvider = await getApolloProvider(); | ||
if (apolloProvider) Object.assign(vueOptions, { provider: apolloProvider }); | ||
|
||
const app = new Vue(vueOptions) | ||
const app = new Vue(vueOptions); | ||
|
||
const appContext = { | ||
isServer, | ||
ssrContext | ||
} | ||
}; | ||
|
||
registerModules(enabledModules, appContext) | ||
registerExtensions(extensions, app, router, store, config, ssrContext) | ||
registerTheme(buildTimeConfig.theme, app, router, store, store.state.config, ssrContext) | ||
registerModules(enabledModules, appContext); | ||
registerExtensions(extensions, app, router, store, config, ssrContext); | ||
registerTheme( | ||
buildTimeConfig.theme, | ||
app, | ||
router, | ||
store, | ||
store.state.config, | ||
ssrContext | ||
); | ||
|
||
app.$emit('application-after-init', app) | ||
app.$emit('application-after-init', app); | ||
|
||
return { app, router, store } | ||
} | ||
return { app, router, store }; | ||
}; | ||
|
||
export { router, createApp } | ||
export { router, createApp }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,79 @@ | ||
const path = require('path') | ||
const webpack = require('webpack') | ||
const MFS = require('memory-fs') | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const MFS = require('memory-fs'); | ||
|
||
let baseClientConfig = require('./webpack.client.config') | ||
let baseServerConfig = require('./webpack.server.config') | ||
let baseClientConfig = require('./webpack.client.config'); | ||
let baseServerConfig = require('./webpack.server.config'); | ||
|
||
const themeRoot = require('./theme-path') | ||
const extendedConfig = require(path.join(themeRoot, '/webpack.config.js')) | ||
const themeRoot = require('./theme-path'); | ||
const extendedConfig = require(path.join(themeRoot, '/webpack.config.js')); | ||
|
||
let clientConfig = extendedConfig(baseClientConfig, { isClient: true, isDev: true }).default; | ||
let serverConfig = extendedConfig(baseServerConfig, { isClient: false, isDev: true }).default; | ||
let clientConfig = extendedConfig(baseClientConfig, { | ||
isClient: true, | ||
isDev: true | ||
}).default; | ||
let serverConfig = extendedConfig(baseServerConfig, { | ||
isClient: false, | ||
isDev: true | ||
}).default; | ||
|
||
module.exports = function setupDevServer (app, cb) { | ||
let bundle | ||
let template | ||
module.exports = function setupDevServer(app, cb) { | ||
let bundle; | ||
let template; | ||
|
||
// Modify client config to work with hot middleware | ||
clientConfig.entry.app = ['webpack-hot-middleware/client', ...clientConfig.entry.app] | ||
clientConfig.output.filename = '[name].js' | ||
clientConfig.entry.app = [ | ||
'webpack-hot-middleware/client', | ||
...clientConfig.entry.app | ||
]; | ||
clientConfig.output.filename = '[name].js'; | ||
clientConfig.plugins.push( | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.NoEmitOnErrorsPlugin() | ||
) | ||
); | ||
|
||
// Dev middleware | ||
const clientCompiler = webpack(clientConfig) | ||
const clientCompiler = webpack(clientConfig); | ||
const devMiddleware = require('webpack-dev-middleware')(clientCompiler, { | ||
publicPath: clientConfig.output.publicPath, | ||
stats: { | ||
colors: true, | ||
chunks: false | ||
} | ||
}) | ||
app.use(devMiddleware) | ||
}); | ||
app.use(devMiddleware); | ||
clientCompiler.plugin('done', () => { | ||
const fs = devMiddleware.fileSystem | ||
const filePath = path.join(clientConfig.output.path, 'index.html') | ||
const fs = devMiddleware.fileSystem; | ||
const filePath = path.join(clientConfig.output.path, 'index.html'); | ||
if (fs.existsSync(filePath)) { | ||
template = fs.readFileSync(filePath, 'utf-8') | ||
template = fs.readFileSync(filePath, 'utf-8'); | ||
if (bundle) { | ||
cb(bundle, template) | ||
cb(bundle, template); | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
// Hot middleware | ||
app.use(require('webpack-hot-middleware')(clientCompiler)) | ||
app.use(require('webpack-hot-middleware')(clientCompiler)); | ||
|
||
// watch and update server renderer | ||
const serverCompiler = webpack(serverConfig) | ||
const mfs = new MFS() | ||
serverCompiler.outputFileSystem = mfs | ||
const serverCompiler = webpack(serverConfig); | ||
const mfs = new MFS(); | ||
serverCompiler.outputFileSystem = mfs; | ||
serverCompiler.watch({}, (err, stats) => { | ||
if (err) throw err | ||
stats = stats.toJson() | ||
stats.errors.forEach(err => console.error(err)) | ||
stats.warnings.forEach(err => console.warn(err)) | ||
if (err) throw err; | ||
stats = stats.toJson(); | ||
stats.errors.forEach(err => console.error(err)); | ||
stats.warnings.forEach(err => console.warn(err)); | ||
|
||
// Read bundle generated by vue-ssr-webpack-plugin | ||
const bundlePath = path.join(serverConfig.output.path, 'vue-ssr-bundle.json') | ||
bundle = JSON.parse(mfs.readFileSync(bundlePath, 'utf-8')) | ||
const bundlePath = path.join( | ||
serverConfig.output.path, | ||
'vue-ssr-bundle.json' | ||
); | ||
bundle = JSON.parse(mfs.readFileSync(bundlePath, 'utf-8')); | ||
if (template) { | ||
cb(bundle, template) | ||
cb(bundle, template); | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
const path = require('path') | ||
const detectInstalled = require('detect-installed') | ||
const config = require('./config.json') | ||
const path = require('path'); | ||
const detectInstalled = require('detect-installed'); | ||
const config = require('./config.json'); | ||
|
||
let themePath = '' | ||
let themeName = config.theme | ||
let themePath = ''; | ||
let themeName = config.theme; | ||
|
||
if (detectInstalled.sync(config.theme, { local: true })) { | ||
themePath = path.resolve(__dirname, '../../node_modules/' + themeName) | ||
} | ||
else { | ||
themeName = themeName.replace('@vue-storefront/theme-', '') | ||
themePath = path.resolve(__dirname, '../../src/themes/' + themeName) | ||
themePath = path.resolve(__dirname, '../../node_modules/' + themeName); | ||
} else { | ||
themeName = themeName.replace('@vue-storefront/theme-', ''); | ||
themePath = path.resolve(__dirname, '../../src/themes/' + themeName); | ||
} | ||
|
||
module.exports = themePath | ||
module.exports = themePath; |
Oops, something went wrong.