config =>index.js
'use strict'
// Template version: 1.2.5
// see http://vuejs-templates.github.io/webpack for documentation.
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
// 自动打开浏览器
// 修改为 true, 在 npm run dev 之后会自动打开浏览器。
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
// Use Eslint Loader?
// If true, your code will be linted during bundling and
// linting errors and warnings will be shown in the console.
useEslint: true,
// If true, eslint errors and warnings will also be shown in the error overlay
// in the browser.
showEslintErrorsInOverlay: false,
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false,
},
// 编译配置
// 打包配置
build: {
// Template for index.html
// 模板
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
// 路径
// 资源根路径
assetsRoot: path.resolve(__dirname, '../dist'),
// 资源的子文件夹
assetsSubDirectory: 'static',
// 资源的公共路径
// 打包后的文件路径
// 我们可能需要将配置修改为 assetsPublicPath: './',
assetsPublicPath: '/',
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
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
}
}
这一篇的纯属废话!
一个修改的第一个配置点:
build: {
// 我们可能需要将配置修改为 assetsPublicPath: './',
// 可以解决在某些部署服务器后界面显示不了的问题
// 路径前缀修改为 ' ./ '(原本为 ' / '),是因为打包之后,外部引入 js 和 css 文件时,如果路径以 ' / ' 开头,在本地是无法找到对应文件的(服务器上没问题)。
// 所以如果需要在本地打开打包后的文件,就得修改文件路径。
assetsPublicPath: '/'
}
第二个修改的配置点:
dev: {
// 可以修改为不常用的端口。(开始学习的时候可以使用默认配置)
port: 8080
}
第三个修改的配置点:
dev: {
// 自动打开浏览器
// 修改为 true, 在 npm run dev 之后会自动打开浏览器。
autoOpenBrowser: false,
}