Skip to content

Commit

Permalink
Merge pull request #133 from JulianMar/master
Browse files Browse the repository at this point in the history
Fix SSR
  • Loading branch information
Wlada committed Mar 6, 2020
2 parents 43dbb60 + 398fdc6 commit e9e5928
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 129 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
build/*.js
dist/*.js
config/*.js
20 changes: 20 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = (api) => {
const isTest = api.env('test')

const config = {
presets: [
['@babel/preset-env', {
targets: {
'browsers': ['last 2 versions', 'IE 11']
},
useBuiltIns: 'usage'
}]
]
}

if (isTest) {
api.cache.never()
}

return config
}
38 changes: 26 additions & 12 deletions config/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const webpack = require('webpack');
const npmCfg = require('../package.json');
const projectRoot = path.resolve(__dirname, '../');

const { VueLoaderPlugin } = require('vue-loader');

var banner = [
'vue-carousel-3d v' + npmCfg.version,
'(c) ' + (new Date().getFullYear()) + ' ' + npmCfg.author,
Expand All @@ -20,35 +22,47 @@ module.exports = {
libraryTarget: 'umd'
},
resolve: {
extensions: ['', '.js', '.vue'],
fallback: [path.join(__dirname, '../node_modules')],
extensions: ['.js', '.vue'],
modules: [
path.join(__dirname, 'node_modules')
],
alias: {
'vue$': 'vue/dist/vue.common.js',
}
},
resolveLoader: {
fallback: [path.join(__dirname, '../node_modules')]
modules: [
path.join(__dirname, '..', 'node_modules')
]
},
module: {
loaders: [
rules: [
{
test: /\.vue$/,
loader: 'vue'
loader: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel',
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env']
],
comments: false
}
},
include: projectRoot,
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [ 'vue-style-loader', 'css-loader' ]
}
]
},
vue: {
loaders: {
js: 'babel'
}
},
plugins: [
new webpack.BannerPlugin(banner)
new webpack.BannerPlugin(banner),
new VueLoaderPlugin()
]
}
9 changes: 6 additions & 3 deletions config/webpack.min.conf.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/* eslint-disable */

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const base = require('./webpack.base.conf')

var config = Object.assign({}, base)

config.output.filename = 'vue-carousel-3d.min.js'

config.plugins = (config.plugins || []).concat([
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
new UglifyJsPlugin({
sourceMap: false
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
})
])

config.mode = 'production'

module.exports = config
4 changes: 2 additions & 2 deletions dist/vue-carousel-3d.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/themes/vue/source/js/vue-carousel-3d.min.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,20 @@
},
"homepage": "https://github.com/wlada/vue-carousel-3d#readme",
"devDependencies": {
"babel-core": "^6.21.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-plugin-webpack-alias": "^2.1.2",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-1": "^6.22.0",
"babel-preset-stage-2": "^6.18.0",
"babel-register": "^6.18.0",
"@babel/core": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-loader": "^8.0.1",
"chai": "^3.5.0",
"copy-webpack-plugin": "^4.6.0",
"coveralls": "^2.11.15",
"css-loader": "^0.26.1",
"css-loader": "^1.0.0",
"eslint": "^3.13.1",
"eslint-config-airbnb-base": "^11.0.1",
"eslint-config-ssense": "^0.1.0",
"eslint-config-vue": "^2.0.1",
"eslint-plugin-fp": "^2.3.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-vue": "^1.0.0",
"html-webpack-plugin": "^2.24.1",
"html2jade": "^0.8.6",
Expand All @@ -68,12 +62,18 @@
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",
"vue": "^2.6.10",
"vue-loader": "^10.0.2",
"vue-play": "2.2.0",
"vue-play-cli": "1.0.4",
"vue-style-loader": "github:toddlawton/vue-style-loader",
"vue-loader": "^15.3.0",
"vue-play": "3.2.1",
"vue-play-cli": "1.1.1",
"vue-style-loader": "^4.1.2",
"uglifyjs-webpack-plugin": "^1.3.0",
"vue-template-compiler": "^2.6.10",
"webpack": "^1.14.0",
"webpack-merge": "^1.1.2"
"webpack": "^4.16.0",
"webpack-cli": "^3.3.0",
"webpack-merge": "^4.2.0"
},
"dependencies": {
"core-js": "^2.0.0",
"webpack-bundle-analyzer": "^3.6.0"
}
}
13 changes: 5 additions & 8 deletions src/Carousel3d.vue
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@
}
}
},
/**
* Stop listening to mutation changes
*/
detachMutationObserver () {
if (this.mutationObserver) {
this.mutationObserver.disconnect()
Expand Down Expand Up @@ -416,10 +414,9 @@
},
mounted () {
this.computeData(true)
this.attachMutationObserver()
if (!this.$isServer) {
if (!process.server) {
this.computeData(true)
this.attachMutationObserver()
window.addEventListener('resize', this.setSize)
if ('ontouchstart' in window) {
Expand All @@ -435,7 +432,7 @@
},
beforeDestroy () {
if (!this.$isServer) {
if (!process.server) {
this.detachMutationObserver()
if ('ontouchstart' in window) {
Expand Down
10 changes: 5 additions & 5 deletions src/mixins/autoplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const autoplay = {
}
},
destroyed () {
this.pauseAutoplay()
if (!process.server) {
this.pauseAutoplay()

if (!this.$isServer) {
this.$el.removeEventListener('mouseenter', this.pauseAutoplay)
this.$el.removeEventListener('mouseleave', this.startAutoplay)
}
Expand All @@ -50,12 +50,12 @@ const autoplay = {
}
},
mounted () {
if (!this.$isServer && this.autoplayHoverPause) {
if (!process.server && this.autoplayHoverPause) {
this.$el.addEventListener('mouseenter', this.pauseAutoplay)
this.$el.addEventListener('mouseleave', this.startAutoplay)
}

this.startAutoplay()
this.startAutoplay()
}
}
}

Expand Down
48 changes: 24 additions & 24 deletions tests/client/utils.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
"use strict"
'use strict'

const Vue = require('vue');
const Html2jade = require('html2jade');
const Vue = require('vue')
const Html2jade = require('html2jade')

/** convert html to pug as a Promise */
function html2pug(html) {
return new Promise((resolve, reject) => {
Html2jade.convertHtml(html, {bodyless: true}, (err, jade) => {
if (err) {
reject(err)
} else {
resolve(jade)
}
function html2pug (html) {
return new Promise((resolve, reject) => {
Html2jade.convertHtml(html, { bodyless: true }, (err, jade) => {
if (err) {
reject(err)
} else {
resolve(jade)
}
})
})
})
}

/** call vm.nextTick() as a Promise */
function nextTick(vm) {
return new Promise((resolve, reject) => {
Vue.nextTick(() => resolve())
})
function nextTick (vm) {
return new Promise((resolve, reject) => {
Vue.nextTick(() => resolve())
})
}

/** call vm.nextTick() and check the snapshot as a Promise */
function expectToMatchSnapshot(vm, element) {
return new Promise((resolve, reject) => {
nextTick(vm).then(() => html2pug((element || vm.$el).innerHTML)).then((jade) => {
expect(jade).toMatchSnapshot()
resolve()
}).catch((err)=>(reject(err)))
})
function expectToMatchSnapshot (vm, element) {
return new Promise((resolve, reject) => {
nextTick(vm).then(() => html2pug((element || vm.$el).innerHTML)).then((jade) => {
expect(jade).toMatchSnapshot()
resolve()
}).catch((err) => (reject(err)))
})
}

exports.expectToMatchSnapshot = expectToMatchSnapshot;
exports.expectToMatchSnapshot = expectToMatchSnapshot

0 comments on commit e9e5928

Please sign in to comment.