美文网首页vue源码分析
"vue-cli-service serve" 文件运行及pro

"vue-cli-service serve" 文件运行及pro

作者: Wendy81 | 来源:发表于2020-10-28 17:04 被阅读0次

    node_modules > @vue > cli-service > lib > commands > serve.js

    //设置服务器host及port
    const defaults = {
      host: '0.0.0.0',
      port: 8080,
      https: false
    }
    
    //文件输出运行....
    module.exports = (api, options) => {
      //查看api对象属性,如下码所示
      console.log(api)
      api.registerCommand('serve', {
      ......
    

    api对象属性,如下码所示

    PluginAPI {
      id: 'built-in:commands/serve',
      service:
       Service {
         initialized: true,
         context: 'path/works/vue-cli2/hello-world',
         inlineOptions: undefined,
         webpackChainFns: [],
         webpackRawConfigFns: [],
         devServerConfigFns: [],
         commands: {},
         pkgContext: 'path/works/vue-cli2/hello-world',
         pkg:
          { name: 'hello-world',
            version: '0.1.0',
            private: true,
            scripts: [Object],
            dependencies: [Object],
            devDependencies: [Object],
            eslintConfig: [Object],
            browserslist: [Array],
            readme: 'ERROR: No README data found!',
            _id: 'hello-world@0.1.0' },
         plugins:
          [ [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object] ],
         pluginsToSkip: Set {},
         modes:
          { serve: 'development',
            build: 'production',
            inspect: 'development' },
         mode: 'development',
         projectOptions:
          { publicPath: '/',
            outputDir: 'dist',
            assetsDir: '',
            indexPath: 'index.html',
            filenameHashing: true,
            runtimeCompiler: false,
            transpileDependencies: [],
            productionSourceMap: true,
            parallel: true,
            pages: undefined,
            crossorigin: undefined,
            integrity: false,
            css: {},
            lintOnSave: 'default',
            devServer: {} } } }
    

    在上面的api对象中我们可以看到,各命令对应的mode,即process.env.NODE_ENV

      modes:
          { serve: 'development',
            build: 'production',
            inspect: 'development' }
    

    上面的api对应的属性projectOptions可在 node_modules > @vue > cli-service > lib> options.js 文件中查看到

    exports.defaults = () => ({
      // project deployment base
      publicPath: '/',
    
      // where to output built files
      outputDir: 'dist',
    
      // where to put static assets (js/css/img/font/...)
      assetsDir: '',
    
      // filename for index.html (relative to outputDir)
      indexPath: 'index.html',
    
      // whether filename will contain hash part
      filenameHashing: true,
    
      // boolean, use full build?
      runtimeCompiler: false,
    
      // deps to transpile
      transpileDependencies: [
        /* string or regex */
      ],
    
      // sourceMap for production build?
      productionSourceMap: !process.env.VUE_CLI_TEST,
    
      // use thread-loader for babel & TS in production build
      // enabled by default if the machine has more than 1 cores
      parallel: hasMultipleCores(),
    
      // multi-page config
      pages: undefined,
    
      // <script type="module" crossorigin="use-credentials">
      // #1656, #1867, #2025
      crossorigin: undefined,
    
      // subresource integrity
      integrity: false,
    
      css: {
        // extract: true,
        // modules: false,
        // sourceMap: false,
        // loaderOptions: {}
      },
    
      // whether to use eslint-loader
      lintOnSave: 'default',
    
      devServer: {
        /*
        open: process.platform === 'darwin',
        host: '0.0.0.0',
        port: 8080,
        https: false,
        hotOnly: false,
        proxy: null, // string | Object
        before: app => {}
      */
      }
    })
    

    相关文章

      网友评论

        本文标题:"vue-cli-service serve" 文件运行及pro

        本文链接:https://www.haomeiwen.com/subject/qxlcvktx.html