# 全局安裝 vue-cli $ npm install --global vue-cli # 建立一個基於 webpack 模板的新項目 $ vue init webpack palanWebsite # 安裝依賴,走你 $ cd palanWebsite $ npm install $ npm run dev
建立過程參考:https://www.2cto.com/kf/201711/695061.html,單元測試選擇的是jestcss
建立好的項目結構以下:html
下面就重點分析build和config目錄下各個配置文件的解析:vue
config目錄下的各項配置都是爲了服務webpack的配置,給不一樣的編譯條件提供配置webpack
config/index.jsweb
'use strict' const path = require('path') module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: {}, // Various Dev Server settings host: 'localhost', // can be overwritten by process.env.HOST port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, notifyOnErrors: true, poll: false, useEslint: true, showEslintErrorsInOverlay: false, /** * Source Maps */ // https://webpack.js.org/configuration/devtool/#development devtool: 'cheap-module-eval-source-map', cacheBusting: true, cssSourceMap: true }, build: { // 在任何模塊文件內部,可使用__dirname變量獲取當前模塊文件所在目錄的完整絕對路徑。 index: path.resolve(__dirname, '../dist/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: '/', /** * Source Maps */ productionSourceMap: true, // https://webpack.js.org/configuration/devtool/#production devtool: '#source-map', productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report } }
詳解:http://www.cnblogs.com/whkl-m/p/6627864.htmlnpm