vuecli4配置vue.config.js
constCopyWebpackPlugin=require('copy-webpack-plugin');constHtmlWebpackPlugin=require('html-webpack-plugin')constpath=require('path');console.log(1111111111111,process.env.NODE_ENV)mo...
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path');
console.log(1111111111111, process.env.NODE_ENV)
module.exports = {
publicPath: './', //基本路径
outputDir: 'dist', //输出文件目录
assetsDir: 'static', //css js 等静态文件目录
productionSourceMap: false, //生产环境的 source map,默认true
devServer: {
host: 'localhost',
port: 1000,
open: false,
// proxy: {
// '/api': {
// target: '<url>', //代理地址
// ws: true, //允许代理 websockets 协议
// changeOrigin: true //需要虚拟托管的站点要设计为true。建议设为 true,开发时大部分情况都是虚拟托管的站点
// }
// }
},
configureWebpack: {
plugins: [
// new CopyWebpackPlugin([ //vuecli4打包时public文件夹下内容会无改动复制到打包目录
// {
// from: path.resolve(__dirname, 'static'),
// to: path.resolve(__dirname, 'dist'),
// ignore: ['.*']
// }
// ]),
new HtmlWebpackPlugin({
filename: 'index.html',
template: (() => {
let temp = './public/index.html';
if (process.env.NODE_ENV === 'development') {
temp = './public/index.html'
} else if (process.env.NODE_ENV === 'production') {
temp = './public/index.pro.html'
}
return temp
})(),
inject: true,
url: process.env.BASE_URL,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
}),
],
// externals: {
// /**
// *key: main.js中全局引入的路径
// *value: 全局暴露出来的对象名
// */
// // 'vue': 'Vue'
// },
externals: [function (context, request, callback) {
/*
开发环境不忽略文件,直接使用本地,避免cdn影响开发效率
*/
console.log(request)
if (process.env.NODE_ENV === 'development') {
return callback();
} else {
/* 在此处添加忽略依赖包 */
if(request === 'vue') {
return callback(null,'Vue')
}
}
callback()
}]
},
}
更多推荐
所有评论(0)