mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 10:37:20 +02:00
chore: prettier & eslint
This commit is contained in:
parent
56dfec19ea
commit
e8e1d5e097
7 changed files with 55 additions and 45 deletions
|
@ -15,5 +15,7 @@ module.exports = {
|
||||||
'func-names': OFF,
|
'func-names': OFF,
|
||||||
'react/jsx-filename-extension': OFF,
|
'react/jsx-filename-extension': OFF,
|
||||||
'react/jsx-one-expression-per-line': OFF,
|
'react/jsx-one-expression-per-line': OFF,
|
||||||
|
'import/no-unresolved': WARNING, // because it couldn't resolve webpack alias
|
||||||
|
'react/prefer-stateless-function': WARNING,
|
||||||
},
|
},
|
||||||
};
|
};
|
|
@ -1,4 +1,5 @@
|
||||||
module.exports = async function build(sourceDir, cliOptions = {}) {
|
module.exports = async function build(sourceDir, cliOptions = {}) {
|
||||||
process.env.NODE_ENV = 'production';
|
process.env.NODE_ENV = 'production';
|
||||||
|
console.log(cliOptions);
|
||||||
console.log('Build');
|
console.log('Build');
|
||||||
};
|
};
|
||||||
|
|
15
lib/dev.js
15
lib/dev.js
|
@ -12,7 +12,7 @@ const serveStatic = require('koa-static');
|
||||||
const history = require('connect-history-api-fallback');
|
const history = require('connect-history-api-fallback');
|
||||||
const load = require('./loader');
|
const load = require('./loader');
|
||||||
const createDevConfig = require('./webpack/dev');
|
const createDevConfig = require('./webpack/dev');
|
||||||
const logPlugin = require('./webpack/plugin/log')
|
const logPlugin = require('./webpack/log');
|
||||||
|
|
||||||
module.exports = async function dev(sourceDir, cliOptions = {}) {
|
module.exports = async function dev(sourceDir, cliOptions = {}) {
|
||||||
const logger = ora(chalk.blue('Start development server')).start();
|
const logger = ora(chalk.blue('Start development server')).start();
|
||||||
|
@ -40,13 +40,14 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
|
||||||
let config = createDevConfig(props);
|
let config = createDevConfig(props);
|
||||||
|
|
||||||
const port = cliOptions.port || 8080;
|
const port = cliOptions.port || 8080;
|
||||||
|
const {publicPath} = props;
|
||||||
|
|
||||||
config
|
config.plugin('blogi-log').use(logPlugin, [
|
||||||
.plugin('blogi-log')
|
{
|
||||||
.use(logPlugin, [{
|
|
||||||
port,
|
port,
|
||||||
publicPath: props.publicPath
|
publicPath
|
||||||
}]);
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
// create compiler from generated webpack config
|
// create compiler from generated webpack config
|
||||||
config = config.toConfig();
|
config = config.toConfig();
|
||||||
|
@ -62,7 +63,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
|
||||||
open: true,
|
open: true,
|
||||||
devMiddleware: {
|
devMiddleware: {
|
||||||
logLevel: 'warn',
|
logLevel: 'warn',
|
||||||
publicPath: props.publicPath
|
publicPath
|
||||||
},
|
},
|
||||||
hotClient: {
|
hotClient: {
|
||||||
port: port + 1,
|
port: port + 1,
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module.exports = function theme() {
|
module.exports = function theme() {
|
||||||
return 'theme';
|
return 'themes';
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ const path = require('path');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
module.exports = function createBaseConfig(props) {
|
module.exports = function createBaseConfig(props) {
|
||||||
const {outDir, themePath, sourceDir} = props;
|
const {outDir, themePath, sourceDir, publicPath} = props;
|
||||||
|
|
||||||
const config = new Config();
|
const config = new Config();
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
@ -18,6 +18,7 @@ module.exports = function createBaseConfig(props) {
|
||||||
.set('symlinks', true)
|
.set('symlinks', true)
|
||||||
.alias.set('@theme', themePath)
|
.alias.set('@theme', themePath)
|
||||||
.set('@source', sourceDir)
|
.set('@source', sourceDir)
|
||||||
|
.set('@generated', path.resolve(__dirname, '../generated'))
|
||||||
.set('@core', path.resolve(__dirname, '../core'))
|
.set('@core', path.resolve(__dirname, '../core'))
|
||||||
.end();
|
.end();
|
||||||
|
|
||||||
|
|
34
lib/webpack/log.js
Normal file
34
lib/webpack/log.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const ora = require('ora');
|
||||||
|
|
||||||
|
function clearScreen() {
|
||||||
|
process.stdout.write('\x1Bc');
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = class LogPlugin {
|
||||||
|
constructor(options) {
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
apply(compiler) {
|
||||||
|
const logger = ora();
|
||||||
|
compiler.hooks.done.tap('blogi-log', stats => {
|
||||||
|
clearScreen();
|
||||||
|
|
||||||
|
const {port, publicPath} = this.options;
|
||||||
|
const time = new Date().toTimeString().match(/^[\d:]+/)[0];
|
||||||
|
|
||||||
|
logger.succeed(
|
||||||
|
`${chalk.gray(`[${time}]`)} Build ${chalk.green(
|
||||||
|
stats.hash.slice(0, 8)
|
||||||
|
)} finished in ${chalk.green(stats.endTime - stats.startTime)} ms!`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`\n${chalk.blue('Development server available at ')}${chalk.cyan(
|
||||||
|
`http://localhost:${port}${publicPath}`
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
compiler.hooks.invalid.tap('blogi-log', clearScreen);
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,29 +0,0 @@
|
||||||
const chalk = require('chalk');
|
|
||||||
const ora = require('ora');
|
|
||||||
module.exports = class LogPlugin {
|
|
||||||
constructor (options) {
|
|
||||||
this.options = options
|
|
||||||
}
|
|
||||||
|
|
||||||
apply (compiler) {
|
|
||||||
const logger = ora();
|
|
||||||
let isFirst = true
|
|
||||||
compiler.hooks.done.tap('blogi-log', stats => {
|
|
||||||
clearScreen()
|
|
||||||
|
|
||||||
const { port, publicPath } = this.options
|
|
||||||
const time = new Date().toTimeString().match(/^[\d:]+/)[0]
|
|
||||||
|
|
||||||
logger.succeed(`${chalk.gray(`[${time}]`)} Build ${chalk.yellow(stats.hash.slice(0, 6))} finished in ${chalk.green(stats.endTime - stats.startTime)} ms!`)
|
|
||||||
if (isFirst) {
|
|
||||||
isFirst = false
|
|
||||||
console.log(`\n${chalk.gray('>')} Blogi dev server listening at ${chalk.cyan(`http://localhost:${port}${publicPath}`)}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
compiler.hooks.invalid.tap('blogi-log', clearScreen)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearScreen () {
|
|
||||||
process.stdout.write('\x1Bc')
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue