Skip to content

Commit

Permalink
🚀 Add Example && Upgrade Eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
pdsuwwz committed Oct 6, 2020
1 parent 26aa82c commit 7274671
Show file tree
Hide file tree
Showing 13 changed files with 2,156 additions and 300 deletions.
66 changes: 34 additions & 32 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
const eslintConfig = {
"root": true,
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
root: true,
parserOptions: {
parser: '@babel/eslint-parser',
ecmaVersion: 7,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
"env": {
"browser": true,
"es6": true,
"node": true
env: {
browser: true,
es6: true,
node: true
},
"globals":{
"console": true
globals: {
console: true
},
"extends": [
"plugin:vue/essential",
"standard"
extends: [
'plugin:vue/essential',
'plugin:vue/recommended',
'@vue/standard'
],
"plugins": [
"vue"
plugins: [
'@babel',
'vue'
],
"rules": {
"no-var": 1,
"no-alert": 1,
"no-ternary": 0,
"no-self-assign": 0,
"standard/no-callback-literal": 0,
"func-call-spacing": 0,
"prefer-promise-reject-errors": 0,
"no-unused-vars": 1,
"no-debugger": 1,
"no-console": 1,
'no-useless-constructor': "off"
rules: {
'no-var': 1,
'no-alert': 1,
'no-ternary': 0,
'no-self-assign': 0,
'standard/no-callback-literal': 0,
'func-call-spacing': 0,
'prefer-promise-reject-errors': 0,
'no-unused-vars': 1,
'no-debugger': 1,
'no-console': 1,
'no-useless-constructor': 'off'
}
};
}

module.exports = eslintConfig;
module.exports = eslintConfig
File renamed without changes.
6 changes: 3 additions & 3 deletions webpack.config.js → build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
const notifier = require('node-notifier')

function resolve (dir) {
return path.join(__dirname, '.', dir)
return path.join(process.cwd(), dir)
}

module.exports = {
mode: 'production',
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './lib'),
path: resolve('./lib'),
publicPath: '/lib/',
filename: 'hoc-el-affix.js',
libraryTarget: 'umd'
Expand Down Expand Up @@ -69,7 +69,7 @@ module.exports = {
use: {
loader: 'babel-loader',
options: {
extends: resolve('babelrc.js')
extends: resolve('babel.config.js')
}
}
},
Expand Down
118 changes: 118 additions & 0 deletions build/webpack.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')

const VueLoaderPlugin = require('vue-loader/lib/plugin');

function resolve (dir) {
return path.join(process.cwd(), dir)
}

const webpackConfig = {
mode: process.env.NODE_ENV,
entry: './example/main.js',
output: {
path: resolve('./example/dist'),
filename: '[name].[hash:7].js',
},
resolve: {
alias: {
vue$: 'vue/dist/vue.esm.js',
'source': resolve('./src'),
'@': resolve('./example/src')
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
publicPath: '/',
port: 8085,
quiet: true,
hot: true,
open: true,
openPage: 'affix-example'
},
performance: {
hints: false
},
module: {
rules: [
{
enforce: 'pre',
test: /\.(vue|jsx?)$/,
exclude: /node_modules/,
loader: 'eslint-loader'
},
{
test: /\.(jsx?|babel|es6)$/,
include: process.cwd(),
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
extends: resolve('babel.config.js')
}
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
compilerOptions: {
preserveWhitespace: false
}
}
},
{
test: /\.(scss|css)$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.(svg|otf|ttf|woff2?|eot|gif|png|jpe?g)(\?\S*)?$/,
loader: 'url-loader',
query: {
limit: 10000,
name: '[name].[hash:7].[ext]'
}
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './example/index.html',
}),
new VueLoaderPlugin(),
new webpack.LoaderOptionsPlugin({
vue: {
compilerOptions: {
preserveWhitespace: false
}
}
}),
new FriendlyErrorsWebpackPlugin({
clearConsole: false,
onErrors: (severity, errors) => {
if (severity !== 'error') {
return
}
const error = errors[0]
notifier.notify({
title: 'Webpack error',
message: `${severity}: ${error.name}`,
subtitle: error.file || ''
})
}
})
],
optimization: {
minimizer: []
},
devtool: '#eval-source-map'
};

module.exports = webpackConfig;
13 changes: 13 additions & 0 deletions example/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
<router-view />
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style lang="scss">
</style>
16 changes: 16 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="renderer" content="webkit" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
</head>
<body>
<div id="app"></div>
</body>
</html>
12 changes: 12 additions & 0 deletions example/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Vue from 'vue'
import router from './router.js'

import HocElementAffix from 'source/main.js'
import App from './App.vue'

Vue.use(HocElementAffix)

new Vue({
router,
render: h => h(App)
}).$mount('#app')
24 changes: 24 additions & 0 deletions example/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Vue from 'vue'
import VueRouter from 'vue-router'

const Layout = () => import('@/components/Layout')
const importModule = (filePath) => {
return () => import(`@/${filePath}`)
}

const routes = [{
path: '/',
component: Layout,
children: [
{
path: 'affix-example',
component: importModule('views/ExampleAffix')
}
]
}]

Vue.use(VueRouter)
export default new VueRouter({
routes,
mode: 'history'
})
28 changes: 28 additions & 0 deletions example/src/components/Layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div>
<router-view />
</div>
</template>
<script>
export default {
name: 'Layout'
}
</script>

<style>
* {
margin: 0;
padding: 0;
}
body {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
html {
box-sizing: border-box;
font-size: 14px;
}
</style>
69 changes: 69 additions & 0 deletions example/src/views/ExampleAffix.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<template>
<div class="box-container">
<div class="content">
<div class="long-list">
<div
v-for="(item, index) in 50"
:key="index"
class="long"
>
<template
v-if="index === 2"
>
<hoc-el-affix>
<div class="box">
吸顶
</div>
</hoc-el-affix>
</template>
<template
v-else-if="index === 7"
>
<hoc-el-affix
:offset-top="120"
>
<div class="box">
距离顶部120px时固定
</div>
</hoc-el-affix>
</template>
<template
v-else
>
{{ index === 99 ? '到底了' : `占位符${index + 1}` }}
</template>
</div>
</div>
</div>
</div>
</template>

<script>
export default {
name: 'ExampleAffix'
}
</script>

<style lang="scss" scoped>
.box-container {
.content {
position: relative;
width: 300px;
margin: 0 auto;
text-align: center;
.box {
width: 300px;
height: 50px;
line-height: 50px;
border: 1px solid #000;
}
.long-list {
.long {
height: 50px;
line-height: 50px;
font-size: 16px;
}
}
}
}
</style>
Loading

0 comments on commit 7274671

Please sign in to comment.