Skip to content

Commit 1a1d25b

Browse files
committed
feat: 修改example
1 parent 8d3bcec commit 1a1d25b

26 files changed

+11971
-1
lines changed

.npmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
node_modules/
3+
/dist/
4+
/demo
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
/test/unit/coverage/
9+
/test/e2e/reports/
10+
selenium-debug.log
11+
.example/
12+
example/
13+
test/
14+
15+
16+
# Editor directories and files
17+
.idea
18+
.vscode
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln

example/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

example/.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/build/
2+
/config/
3+
/dist/
4+
/*.js
5+
/test/unit/coverage/

example/.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
extends: [
3+
'standard',
4+
'plugin:vue/recommended'
5+
],
6+
rules: {
7+
8+
},
9+
globals: {
10+
__webpack_public_path__: true
11+
}
12+
}

example/.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.DS_Store
2+
node_modules/
3+
/dist/
4+
/demo
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
/test/unit/coverage/
9+
/test/e2e/reports/
10+
selenium-debug.log
11+
.example/
12+
13+
# Editor directories and files
14+
.idea
15+
.vscode
16+
*.suo
17+
*.ntvs*
18+
*.njsproj
19+
*.sln

example/.postcssrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// https://github.com/michael-ciniawsky/postcss-load-config
2+
3+
module.exports = {
4+
"plugins": {
5+
"postcss-import": {},
6+
"postcss-url": {},
7+
// to edit target browsers: use "browserslist" field in package.json
8+
"autoprefixer": {}
9+
}
10+
}

example/.stylelintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "stylelint-config-standard",
3+
"ignoreFiles": ["./node_modules/**/*.css","./dist/**/*.css"]
4+
}

example/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [vue-code-diff](https://www.npmjs.com/package/vue-code-diff)
2+
3+
> 代码比对展示 [demo](http://diff.xjie.me/)
4+
5+
## 安装
6+
```shell
7+
yarn add vue-code-diff
8+
```
9+
10+
## 使用
11+
```vue
12+
<template>
13+
<div>
14+
<code-diff :old-string="oldStr" :new-string="newStr" :context="10" />
15+
</div>
16+
</template>
17+
18+
import CodeDiff from 'vue-code-diff'
19+
export default {
20+
components: {CodeDiff},
21+
data(){
22+
return {
23+
oldStr: 'old code',
24+
newStr: 'new code'
25+
}
26+
}
27+
}
28+
```
29+
30+
## 参数说明
31+
32+
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
33+
|---------- |-------- |---------- |------------- |-------- |
34+
| old-string| 陈旧的字符串| string |||
35+
| new-string| 新的字符串| string |||
36+
| context| 不同地方上下间隔多少行不隐藏 | number |||
37+
| outputFormat| 展示的方式 | string | line-by-line,side-by-side | line-by-line |
38+
| drawFileList | 展示对比文件列表 | boolean | - | false |
39+
| renderNothingWhenEmpty | 当无对比时不渲染 | boolean | - | false |
40+
| diffStyle | 每行中对比差异级别 | string | word, char | word |
41+
| fileName | 文件名 | string | - | |
42+
| isShowNoChange | 当无对比时展示源代码 | boolean | - | false |
43+
44+
45+
## 效果展示
46+
47+
### line-by-line
48+
![image](https://github.com/ddchef/vue-code-diff/blob/master/2018-06-01.png?raw=true)
49+
50+
### side-by-side
51+
![image](https://github.com/ddchef/vue-code-diff/blob/master/2018050615272.png?raw=true)
52+
53+
## LICENSE
54+
[MIT](LICENSE)

example/babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@vue/app'
5+
]
6+
],
7+
plugins: [
8+
[
9+
'@babel/plugin-transform-runtime',{
10+
corejs: 3,
11+
}
12+
]
13+
]
14+
}

example/build/build.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const webpack = require('webpack')
2+
const ora = require('ora')
3+
const chalk = require('chalk')
4+
const webpackConfig = require('./config')
5+
6+
webpackConfig().then(({ prodConfig }) => {
7+
const isAnalyzer = process.argv[2] === 'analyzer'
8+
if (isAnalyzer) {
9+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
10+
prodConfig.plugins.push(
11+
new BundleAnalyzerPlugin()
12+
)
13+
}
14+
const spinner = ora('Builing for production...').start()
15+
webpack(prodConfig, (err, stats) => {
16+
spinner.stop()
17+
if (err) throw err
18+
process.stdout.write(stats.toString({
19+
modules: false,
20+
colors: true,
21+
// 添加 children 信息
22+
children: false,
23+
// 添加 chunk 信息(设置为 `false` 能允许较少的冗长输出)
24+
chunks: false,
25+
// 将构建模块信息添加到 chunk 信息
26+
chunkModules: false
27+
}) + '\n\n')
28+
if (stats.hasErrors()) {
29+
console.log(chalk.red('Build failed with errors.\n'))
30+
process.exit(1)
31+
}
32+
console.log(chalk.cyan('Build complete.\n'))
33+
if (!isAnalyzer) process.exit(0)
34+
})
35+
})

example/build/config/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const portfinder = require('portfinder')
2+
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
3+
const ProgressBarWebpackPlugin = require('progress-bar-webpack-plugin')
4+
const chalk = require('chalk')
5+
const webpackProdConfig = require('./webpack.prod')
6+
const webpackDevConfig = require('./webpack.dev')
7+
8+
module.exports = async () => {
9+
portfinder.basePort = 3010
10+
const port = await portfinder.getPortPromise()
11+
webpackDevConfig.devServer.port = port
12+
13+
webpackDevConfig.plugins.push(
14+
new FriendlyErrorsWebpackPlugin(
15+
{
16+
compilationSuccessInfo: {
17+
messages: [`You application is running here http://localhost:${port}`]
18+
}
19+
}
20+
)
21+
)
22+
webpackDevConfig.plugins.push(new ProgressBarWebpackPlugin({
23+
format: `:msg [${chalk.green(':bar')}]${chalk.yellow.bold(':percent')} (:elapseds)`,
24+
complete: ':',
25+
incomplete: ' '
26+
}))
27+
return {
28+
devConfig: webpackDevConfig,
29+
prodConfig: webpackProdConfig
30+
}
31+
}

example/build/config/utils.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2+
const cssLoader = {
3+
less: {
4+
loader: 'less-loader',
5+
options: {
6+
javascriptEnabled: true,
7+
strictMath: false
8+
}
9+
},
10+
scss: {
11+
loader: 'sass-loader'
12+
},
13+
postcss: {
14+
loader: 'postcss-loader'
15+
}
16+
}
17+
function baseCssLoader (type, prod) {
18+
return {
19+
test: new RegExp(`\.(${type})$`),
20+
use: [
21+
prod
22+
? {
23+
loader: MiniCssExtractPlugin.loader,
24+
options: {
25+
publicPath: '../../'
26+
}
27+
}
28+
: 'style-loader',
29+
'css-loader',
30+
'postcss-loader',
31+
cssLoader[type]
32+
]
33+
}
34+
}
35+
36+
function setBaseCssLoaders (types = [], prod = false) {
37+
return [
38+
{
39+
test: /\.(css)$/,
40+
use: [
41+
prod
42+
? {
43+
loader: MiniCssExtractPlugin.loader,
44+
options: {
45+
publicPath: '../../'
46+
}
47+
}
48+
: 'style-loader',
49+
'css-loader'
50+
]
51+
},
52+
...types.map(type => baseCssLoader(type, prod))
53+
]
54+
}
55+
56+
module.exports = {
57+
setBaseCssLoaders
58+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
2+
const prodConfig = require('./webpack.prod')
3+
4+
prodConfig.plugins.push(
5+
new BundleAnalyzerPlugin()
6+
)
7+
8+
module.exports = prodConfig

example/build/config/webpack.base.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
const path = require('path')
2+
const { VueLoaderPlugin } = require('vue-loader')
3+
const { ProvidePlugin } = require('webpack')
4+
const EslintPlugin = require('eslint-webpack-plugin')
5+
const StyleLintPlugin = require('stylelint-webpack-plugin')
6+
7+
const basePath = process.cwd()
8+
9+
module.exports = () => ({
10+
entry: {
11+
main: '/src/main.js'
12+
},
13+
output: {
14+
path: path.join(basePath, 'dist'),
15+
filename: `static/js/[name].js`
16+
},
17+
module: {
18+
rules: [
19+
{
20+
test: /\.(vue)$/,
21+
use: [
22+
'vue-loader'
23+
]
24+
},
25+
{
26+
test: /\.(js|jsx)$/,
27+
use: [
28+
{
29+
loader: 'babel-loader?cacheDirectory'
30+
}
31+
],
32+
exclude (filePath) {
33+
return (
34+
/node_modules/.test(filePath) &&
35+
!/@ailpha(\\|\/)ml/.test(filePath)
36+
)
37+
}
38+
},
39+
{
40+
test: /\.(png|jpg|gif|jpeg)$/i,
41+
use: [
42+
{
43+
loader: 'url-loader',
44+
options: {
45+
limit: 8 * 1024,
46+
outputPath: 'static/images',
47+
esModule: false
48+
}
49+
}
50+
]
51+
},
52+
{
53+
test: /\.(svg|woff|woff2|ttf|otf|eot)$/,
54+
use: [
55+
{
56+
loader: 'file-loader',
57+
options: {
58+
outputPath: 'static/fonts'
59+
}
60+
}
61+
]
62+
}
63+
]
64+
},
65+
resolve: {
66+
alias: {
67+
'@': path.join(process.cwd(), 'src'),
68+
vue$: process.env.NODE_ENV === 'production' ? 'vue/dist/vue.runtime.js' : 'vue/dist/vue.esm.js'
69+
},
70+
fallback: {
71+
timers: false,
72+
http: false,
73+
url: false,
74+
util: false,
75+
os: false,
76+
stream: require.resolve('stream-browserify'),
77+
crypto: require.resolve('crypto-browserify')
78+
},
79+
extensions: ['.js', '.vue', '.json', '.jsx', '.css']
80+
},
81+
plugins: [
82+
new StyleLintPlugin({
83+
files: ['**/*.{vue,htm,html,css,sss,less,scss,sass}']
84+
}),
85+
new EslintPlugin(),
86+
new ProvidePlugin({
87+
process: 'process',
88+
Buffer: ['buffer', 'Buffer']
89+
}),
90+
new VueLoaderPlugin()
91+
],
92+
optimization: {
93+
}
94+
})

0 commit comments

Comments
 (0)