1.0.12 • Published 3 years ago

dait-service v1.0.12

Weekly downloads
8
License
ISC
Repository
-
Last release
3 years ago

dait-service

dait-service 是为 dait 提供服务的核心模块。

dait-service 做了什么

  • 集成了 webpack 自动化构建及其不同的环境配置。
  • 集成了 eslint 检验
  • 封装 MarkedEssay 插件,用于显示 markdown 的内容
  • 读写 articles.json 支撑主题对 markdown 文件数据的依赖
  • 提供可配置文件 dait.config.js

MarkedEssay

dait-service 封装了 MarkedEssay 组件用于显示 markdown 的内容。 可以直接在主题入口文件中 main.js 引入

import MarkedEssay from 'dait-service/components/MarkedEssay'

Vue.use(MarkedEssay)

props

属性是否必填描述类型默认值
fileNamemarkdown 的文件名。例如 'readme.md'String-
more是否在 more 注释处截至展示Booleanfalse
showMoreStyle博文截至样式的渲染函数。参数为 render 函数Function-
splitWord博文截至显示的注释语句string

dait.config.js

dait.config.js 需要遵循 commonJs 规范向外导出一个对象

config.site

site:object。为当前博客的站点信息。

属性名类型描述
titlestring网站的标题
authorstring网站的站长
subtitlestring网站的副标题
descriptionstring网站的描述
keywordsstring网站的关键字,以逗号分割
languagestring网站的语言。 默认 zh-CN

config.theme

theme:string。为网站选用的主题名称。

config.configureWebpack

configureWebpack:object。为 webpack 自动化构建的配置对象

属性名类型描述
entrystring文件编译的入口路径,必须是一个绝对路径。
outputstring文件编译的输出路径,必须是一个绝对路径。
aliasobject全局的路径别名对象。
rulesarraywebpack 模块加载器(loader)的配置规则。
pluginsarraywebpack 的插件使用
defineDataobject全局注入的数据对象。键为变量名称,值必须是一个字符串。
devobject开发模式下的配置对象。详细见下表。
prodobject测试环境下的配置对象。详细见下表。
dev
属性名类型描述
devtoolstring开发模式下的 source-map 模式类型
devServerobjectwebpack-dev-server 的配置对象
rulesarray开发模式下的模块加载器(loader)的配置规则。
pluginsarray开发模式下的插件使用
prod
属性名类型描述
devtoolstring生产模式下的 source-map 模式类型
optimizationobject生产模式下的配置优化对象
rulesarray生产模式下的模块加载器(loader)的配置规则。
pluginsarray生产模式下的插件使用

config.configurePostcss

configurePostcss:object。为 postcss 的配置对象

dait-service 默认配置

module.exports = {
  site: {
    title: 'blog',
    author: '',
    subtitle: 'my new blog',
    description: '',
    keywords: 'dait, blog, vue, gitee',
    language: 'zh-CN'
  },
  theme: 'default',
  configureWebpack: {
    entry: path.join(themePath, 'main.js'),
    output: path.join(cwd, './dist'),
    alias: {
      '@': path.join(cwd, './'),
      '@theme': themePath
    },
    rules: [],
    plugins: [],
    defineData: {},
    dev: {
      devtool: 'cheap-module-eval-source-map',
      devServer: {
        open: false,
        hot: true,
        port: 6800,
        clientLogLevel: 'warning'
      },
      rules: [
        {
          test: /\.css$/,
          use: [
            'vue-style-loader',
            {
              loader: 'css-loader',
              options: {
                esModule: false
              }
            },
            {
              loader: 'postcss-loader',
              options: {
                postcssOptions: {
                  config: path.join(__dirname, './postcss.config.js')
                }
              }
            }
          ]
        },
        {
          test: /\.less$/,
          use: [
            'vue-style-loader',
            {
              loader: 'css-loader',
              options: {
                esModule: false
              }
            },
            {
              loader: 'postcss-loader',
              options: {
                postcssOptions: {
                  config: path.join(__dirname, './postcss.config.js')
                }
              }
            },
            'less-loader'
          ]
        },
        {
          test: /\.vue$/,
          enforce: 'pre',
          exclude: [
            path.join(cwd, './node_modules'),
            path.resolve('./node_modules')
          ],
          loader: 'eslint-loader'
        },
        {
          test: /\.js$/,
          enforce: 'pre',
          exclude: [
            path.join(cwd, './node_modules'),
            path.resolve('./node_modules')
          ],
          loader: 'eslint-loader'
        }
      ],
      plugins: [
        new webpack.HotModuleReplacementPlugin()
      ]
    },
    prod: {
      devtool: 'none',
      optimization: {
        minimize: true,
        minimizer: [
          new OptimizeCssPlugin(),
          new TerserWebpackPlugin()
        ],
        splitChunks: {
          chunks: 'all',
          cacheGroups: {
            libs: {
              name: 'depend/chunk-libs',
              test: /[\\/]node_modules[\\/]/,
              priority: 10,
              chunks: 'initial' // 只打包初始时依赖的第三方
            },
            elementUI: {
              name: 'depend/chunk-elementUI', // 单独将 elementUI 拆包
              priority: 20, // 权重
              test: /[\\/]node_modules[\\/]element-ui[\\/]/
            },
            vueLibs: {
              name: 'depend/chunk-vue', // 单独将 vue 开头的依赖 拆包
              priority: 15, // 权重
              test: /[\\/]node_modules[\\/]vue/
            }
          }
        },
        runtimeChunk: 'single'
      },
      rules: [
        {
          test: /\.css$/,
          use: [
            CssExtractPlugin.loader,
            'css-loader',
            {
              loader: 'postcss-loader',
              options: {
                postcssOptions: {
                  config: path.join(__dirname, './postcss.config.js')
                }
              }
            }
          ]
        },
        {
          test: /\.less$/,
          use: [
            CssExtractPlugin.loader,
            'css-loader',
            {
              loader: 'postcss-loader',
              options: {
                postcssOptions: {
                  config: path.join(__dirname, './postcss.config.js')
                }
              }
            },
            'less-loader'
          ]
        }
      ],
      plugins: [
        new CleanPlugin(),
        new CssExtractPlugin({
          filename: 'css/[name]-[contenthash:8].css'
        })
      ]
    }
  },
  configurePostcss: {
    plugins: [
      require('autoprefixer'),
    ]
  }
}