diff --git a/.eslintrc.js b/.eslintrc.js index da650e9416..6f297e956d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,5 +15,7 @@ module.exports = { 'func-names': OFF, 'react/jsx-filename-extension': OFF, 'react/jsx-one-expression-per-line': OFF, + 'import/no-unresolved': WARNING, // because it couldn't resolve webpack alias + 'react/prefer-stateless-function': WARNING, }, }; \ No newline at end of file diff --git a/lib/build.js b/lib/build.js index 5b1054a533..34dd734731 100644 --- a/lib/build.js +++ b/lib/build.js @@ -1,4 +1,5 @@ -module.exports = async function build(sourceDir, cliOptions = {}) { - process.env.NODE_ENV = 'production'; - console.log('Build'); -}; +module.exports = async function build(sourceDir, cliOptions = {}) { + process.env.NODE_ENV = 'production'; + console.log(cliOptions); + console.log('Build'); +}; diff --git a/lib/dev.js b/lib/dev.js index 0187c07279..8b2985053c 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -12,7 +12,7 @@ const serveStatic = require('koa-static'); const history = require('connect-history-api-fallback'); const load = require('./loader'); const createDevConfig = require('./webpack/dev'); -const logPlugin = require('./webpack/plugin/log') +const logPlugin = require('./webpack/log'); module.exports = async function dev(sourceDir, cliOptions = {}) { const logger = ora(chalk.blue('Start development server')).start(); @@ -40,13 +40,14 @@ module.exports = async function dev(sourceDir, cliOptions = {}) { let config = createDevConfig(props); const port = cliOptions.port || 8080; + const {publicPath} = props; - config - .plugin('blogi-log') - .use(logPlugin, [{ - port, - publicPath: props.publicPath - }]); + config.plugin('blogi-log').use(logPlugin, [ + { + port, + publicPath + } + ]); // create compiler from generated webpack config config = config.toConfig(); @@ -62,7 +63,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) { open: true, devMiddleware: { logLevel: 'warn', - publicPath: props.publicPath + publicPath }, hotClient: { port: port + 1, diff --git a/lib/theme/index.js b/lib/theme/index.js index 5da5e8bf31..cae5be8cc5 100644 --- a/lib/theme/index.js +++ b/lib/theme/index.js @@ -1,3 +1,3 @@ -module.exports = function theme() { - return 'theme'; -}; +module.exports = function theme() { + return 'themes'; +}; diff --git a/lib/webpack/base.js b/lib/webpack/base.js index c7970dfcfd..995f7f22de 100644 --- a/lib/webpack/base.js +++ b/lib/webpack/base.js @@ -3,7 +3,7 @@ const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = function createBaseConfig(props) { - const {outDir, themePath, sourceDir} = props; + const {outDir, themePath, sourceDir, publicPath} = props; const config = new Config(); const isProd = process.env.NODE_ENV === 'production'; @@ -18,6 +18,7 @@ module.exports = function createBaseConfig(props) { .set('symlinks', true) .alias.set('@theme', themePath) .set('@source', sourceDir) + .set('@generated', path.resolve(__dirname, '../generated')) .set('@core', path.resolve(__dirname, '../core')) .end(); diff --git a/lib/webpack/log.js b/lib/webpack/log.js new file mode 100644 index 0000000000..6ca1677e71 --- /dev/null +++ b/lib/webpack/log.js @@ -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); + } +}; diff --git a/lib/webpack/plugin/log.js b/lib/webpack/plugin/log.js deleted file mode 100644 index 60420ea7f8..0000000000 --- a/lib/webpack/plugin/log.js +++ /dev/null @@ -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') -} \ No newline at end of file