Skip to content

Commit 8352a1e

Browse files
authored
refactor: build config (#408)
* refactor: build config * chore: fix conflict * fix: 404 page path
1 parent 9b3b445 commit 8352a1e

Some content is hidden

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

64 files changed

+4353
-5619
lines changed

.eslintignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
.git/
1+
.git
22
packages/docsify-server-renderer/build.js
3-
node_modules
3+
node_modules
4+
build
5+
server.js

.eslintrc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
{
2-
"extends": [
3-
"vue"
4-
],
5-
"parserOptions": {
6-
"ecmaVersion": 8
7-
},
8-
"env": {
9-
"browser": true
2+
"extends": "xo-space/browser",
3+
"rules": {
4+
"semi": [2, "never"],
5+
"no-return-assign": "off",
6+
"no-unused-expressions": "off",
7+
"no-new-func": "off",
8+
"no-multi-assign": "off",
9+
"no-mixed-operators": "off",
10+
"max-params": "off",
11+
"no-script-url": "off",
12+
"camelcase": "off",
13+
"no-warning-comments": "off"
1014
},
1115
"globals": {
1216
"Docsify": true,
13-
"$docsify": true
17+
"$docsify": true,
18+
"process": true
1419
}
1520
}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Move to [awesome-docsify](https://github.com/QingWei-Li/awesome-docsify)
7171

7272
```bash
7373
npm run bootstrap && npm run dev
74-
open http://localhost:3000
7574
```
7675

7776
## Backers

app.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

build/build-css.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

build/build.js

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
var rollup = require('rollup')
2-
var buble = require('rollup-plugin-buble')
3-
var commonjs = require('rollup-plugin-commonjs')
4-
var nodeResolve = require('rollup-plugin-node-resolve')
5-
var string = require('rollup-plugin-string')
6-
var uglify = require('rollup-plugin-uglify')
7-
var replace = require('rollup-plugin-replace')
8-
var isProd = process.argv[process.argv.length - 1] !== '--dev'
9-
var version = process.env.VERSION || require('../package.json').version
1+
const rollup = require('rollup')
2+
const buble = require('rollup-plugin-buble')
3+
const commonjs = require('rollup-plugin-commonjs')
4+
const nodeResolve = require('rollup-plugin-node-resolve')
5+
const uglify = require('rollup-plugin-uglify')
6+
const replace = require('rollup-plugin-replace')
7+
const isProd = process.env.NODE_ENV === 'production'
8+
const version = process.env.VERSION || require('../package.json').version
9+
const chokidar = require('chokidar')
10+
const path = require('path')
1011

11-
var build = function (opts) {
12+
const build = function(opts) {
1213
rollup
1314
.rollup({
14-
input: 'src/' + opts.entry,
15+
input: opts.input,
1516
plugins: (opts.plugins || []).concat([
16-
string({ include: '**/*.css' }),
1717
buble(),
1818
commonjs(),
1919
nodeResolve(),
@@ -23,8 +23,8 @@ var build = function (opts) {
2323
})
2424
])
2525
})
26-
.then(function (bundle) {
27-
var dest = 'lib/' + (opts.output || opts.entry)
26+
.then(function(bundle) {
27+
var dest = 'lib/' + (opts.output || opts.input)
2828

2929
console.log(dest)
3030
bundle.write({
@@ -33,45 +33,86 @@ var build = function (opts) {
3333
strict: false
3434
})
3535
})
36-
.catch(function (err) {
36+
.catch(function(err) {
3737
console.error(err)
3838
})
3939
}
40-
41-
build({
42-
entry: 'core/index.js',
43-
output: 'docsify.js'
44-
})
45-
46-
var plugins = [
47-
{ name: 'search', entry: 'search/index.js' },
48-
{ name: 'ga', entry: 'ga.js' },
49-
{ name: 'emoji', entry: 'emoji.js' },
50-
{ name: 'external-script', entry: 'external-script.js' },
51-
{ name: 'front-matter', entry: 'front-matter/index.js' },
52-
{ name: 'zoom-image', entry: 'zoom-image.js' },
53-
{ name: 'disqus', entry: 'disqus.js' },
54-
{ name: 'gitalk', entry: 'gitalk.js' }
55-
]
56-
57-
plugins.forEach(item => {
40+
const buildCore = function() {
5841
build({
59-
entry: 'plugins/' + item.entry,
60-
output: 'plugins/' + item.name + '.js'
42+
input: 'src/core/index.js',
43+
output: 'docsify.js'
6144
})
62-
})
6345

64-
if (isProd) {
65-
build({
66-
entry: 'core/index.js',
67-
output: 'docsify.min.js',
68-
plugins: [uglify()]
69-
})
70-
plugins.forEach(item => {
46+
if (isProd) {
7147
build({
72-
entry: 'plugins/' + item.entry,
73-
output: 'plugins/' + item.name + '.min.js',
48+
input: 'src/core/index.js',
49+
output: 'docsify.min.js',
7450
plugins: [uglify()]
7551
})
52+
}
53+
}
54+
const buildAllPlugin = function() {
55+
var plugins = [
56+
{name: 'search', input: 'search/index.js'},
57+
{name: 'ga', input: 'ga.js'},
58+
{name: 'emoji', input: 'emoji.js'},
59+
{name: 'external-script', input: 'external-script.js'},
60+
{name: 'front-matter', input: 'front-matter/index.js'},
61+
{name: 'zoom-image', input: 'zoom-image.js'},
62+
{name: 'disqus', input: 'disqus.js'},
63+
{name: 'gitalk', input: 'gitalk.js'}
64+
]
65+
66+
plugins.forEach(item => {
67+
build({
68+
input: 'src/plugins/' + item.input,
69+
output: 'plugins/' + item.name + '.js'
70+
})
7671
})
72+
73+
if (isProd) {
74+
plugins.forEach(item => {
75+
build({
76+
input: 'src/plugins/' + item.input,
77+
output: 'plugins/' + item.name + '.min.js',
78+
plugins: [uglify()]
79+
})
80+
})
81+
}
82+
}
83+
84+
if (!isProd) {
85+
chokidar
86+
.watch(['src/core', 'src/plugins'], {
87+
atomic: true,
88+
awaitWriteFinish: {
89+
stabilityThreshold: 1000,
90+
pollInterval: 100
91+
}
92+
})
93+
.on('change', p => {
94+
console.log('[watch] ', p)
95+
const dirs = p.split(path.sep)
96+
if (dirs[1] === 'core') {
97+
buildCore()
98+
} else if (dirs[2]) {
99+
const name = path.basename(dirs[2], '.js')
100+
const input = `src/plugins/${name}${
101+
/\.js/.test(dirs[2]) ? '' : '/index'
102+
}.js`
103+
104+
build({
105+
input,
106+
output: 'plugins/' + name + '.js'
107+
})
108+
}
109+
})
110+
.on('ready', () => {
111+
console.log('[start]')
112+
buildCore()
113+
buildAllPlugin()
114+
})
115+
} else {
116+
buildCore()
117+
buildAllPlugin()
77118
}
File renamed without changes.
File renamed without changes.

docs/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ window.$docsify = {
420420

421421
List of languages that will fallback to the default language when a page is request and didn't exists for the given local.
422422

423-
Example:
424-
423+
Example:
424+
425425
- try to fetch the page of `/de/overview`. If this page exists, it'll be displayed
426426
- then try to fetch the default page `/overview` (depending on the default language). If this page exists, it'll be displayed
427427
- then display 404 page.

dev.html renamed to index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>docsify</title>
@@ -14,6 +15,7 @@
1415
}
1516
</style>
1617
</head>
18+
1719
<body>
1820
<div id="app"></div>
1921
<script>
@@ -22,6 +24,7 @@
2224
'.*?/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG',
2325
'/.*/_navbar.md': '/_navbar.md'
2426
},
27+
notFoundPage: '_404.html',
2528
auto2top: true,
2629
basePath: '/docs/',
2730
executeScript: true,
@@ -33,11 +36,11 @@
3336
mergeNavbar: true,
3437
formatUpdated: '{MM}/{DD} {HH}:{mm}',
3538
plugins: [
36-
function(hook, vm) {
39+
function (hook, vm) {
3740
hook.beforeEach(function (html) {
3841
var url = 'https://github.com/QingWei-Li/docsify/blob/master/' + vm.route.file
3942
var editHtml = '[:memo: Edit Document](' + url + ')\n'
40-
43+
4144
return editHtml
4245
+ html
4346
+ '\n----\n'
@@ -50,4 +53,5 @@
5053
</script>
5154
<script src="/lib/docsify.js"></script>
5255
</body>
53-
</html>
56+
57+
</html>

0 commit comments

Comments
 (0)