const pageOptions = { // html模版变量,pages.index里的全部变量均可在htmlWebpackPlugin.options下得到
title: 'vueTest', // template 中的 title 标签须要是 <title><%= htmlWebpackPlugin.options.title %></title>
}
module.exports = {
pages: {
index: {
entry: 'src/main.js', // 项目入口文件
template: './public/index.html', // 项目模板
filename: `${buildRootPath}index.html`, // 打包后生产的html文件名
chunks: ['chunk-vendors', 'chunk-common', 'index'],
...pageOptions,
// 在这个页面中包含的块,默认状况下会包含
// 提取出来的通用 chunk 和 vendor chunk。
// chunks: ['chunk-vendors', 'chunk-common', 'index']
},
},
};
复制代码
module.exports = {
css: { // 样式配置
loaderOptions: { // 与CSS相关的loader配置都在这里
postcss: { // postcss配置例子
plugins: [ // 添加插件
require('postcss-pxtorem')({ // px转换为rem 须要npm i postcss-pxtorem -D
rootValue: 100, // 换算的基数
selectorBlackList: ['weui', 'mu'], // 忽略转换正则匹配项
propList: ['*'],
}),
]
},
sass: { // sass配置例子
data: `
@import "@/sass/theme-variables.scss";
@import "@/sass/init.scss";
@import "@/sass/tool.scss";
`
// 倒入多个scss文件
},
less: { // less配置例子
globalVars: { // 设置全局变量,设置完后background: @primary;便可
primary: '#f38'
}
}
}
},
};
复制代码
module.exports = {
devServer: { // 和webpack的devServer配置如出一辙
https: false, // ture启用https,false启用http
host: '0.0.0.0',
port: 8001,
},
}
复制代码
module.exports = {
configureWebpack: { // Webpack原生配置项,该对象会经过webpack-merge合并到最终的配置中,若有冲突configureWebpack被vue-cli其余覆盖
devServer: {
https: false, // ture启用https,false启用http
host: '0.0.0.0',
port: 8001,
},
},
};
复制代码
module.exports = {
configureWebpack: {
resolve: {
extensions: ['.js', '.vue', '.json'], // 导入文件若是不加后缀名,设置该属性自动补上,顺序是从左到右
},
},
};
复制代码
module.exports = {
configureWebpack: {
resolve: {
alias: {
'vue$': 'vue/dist/vue.min.js',
'@': resolve('src'), // @直接表明src目录,
// 例子:import TodosMenu from '@/pages/TodosMenu.vue';
'pages': resolve('src/pages'), // @直接表明src目录下的pages目录,
// 例子:import TodosMenu from 'pages/TodosMenu.vue';
},
},
},
};
复制代码
module.exports = {
configureWebpack: { // Webpack原生配置项,该对象会经过webpack-merge合并到最终的配置中,若有冲突configureWebpack被vue-cli其余覆盖
plugins: [ // 引入webpack插件
new webpack.ProvidePlugin({
// webpack自动帮你加上import _ from 'lodash',记得在.eslintrc.js的globals里加上_属性为true,globals: { _: true, }
_: 'lodash'
})
]
},
};
复制代码
最后给出一份上面暗🌰的配置css
const path = require('path');
const webpack = require('webpack');
const resolve = dir => path.join(__dirname, dir);
const buildRootPath = './'
const buildConfig = { // 打包配置
// outputDir: './dist', // 打包后项目存放位置
publicPath: '/', // 打包后的引用资源路径(css、js)
assetsDir: `${buildRootPath}`, // 打包后资源(css、js、img等)存放目录
indexPath: `${buildRootPath}index.html`, // 指定生成的 index.html 的输出路径
filenameHashing: false, // 打包后资源文件名自动加上哈希值 true\false
}
const pageOptions = { // html模版变量
title: 'vueTest', // template 中的 title 标签须要是 <title><%= htmlWebpackPlugin.options.title %></title>
}
module.exports = {
...buildConfig,
pages: {
index: {
entry: 'src/main.js', // 项目入口文件
template: './public/index.html', // 项目模板
filename: `${buildRootPath}index.html`, // 打包后生产的html文件名
chunks: ['chunk-vendors', 'chunk-common', 'index'],
...pageOptions,
// 在这个页面中包含的块,默认状况下会包含
// 提取出来的通用 chunk 和 vendor chunk。
// chunks: ['chunk-vendors', 'chunk-common', 'index']
},
},
lintOnSave: true, // 校验eslint语法,若是值为'error'要就不符合就报错
devServer: { // 和webpack的devServer配置如出一辙
https: false, // ture启用https,false启用http
host: '0.0.0.0',
port: 8001,
},
css: { // 样式配置
loaderOptions: { // CSS相关的loader配置
postcss: {
plugins: [ // 添加插件
require('postcss-pxtorem')({ // px转换为rem 须要npm i postcss-pxtorem -D
rootValue: 100, // 换算的基数
selectorBlackList: ['weui', 'mu'], // 忽略转换正则匹配项
propList: ['*'],
}),
]
}
// less: { // less配置例子
// globalVars: { // 设置全局变量,设置完后background: @primary;便可
// primary: '#f38'
// }
// }
}
},
configureWebpack: { // Webpack原生配置项,该对象会经过webpack-merge合并到最终的配置中,若有冲突configureWebpack被vue-cli其余覆盖
resolve: {
extensions: ['.js', '.vue', '.json'], // 导入文件若是不加后缀名,设置该属性自动补上,顺序是从左到右
alias: {
'vue$': 'vue/dist/vue.min.js',
'@': resolve('src'), // @直接表明src目录,
// 例子:import TodosMenu from '@/pages/TodosMenu.vue';
'pages': resolve('src/pages'), // @直接表明src目录下的pages目录,
// 例子:import TodosMenu from 'pages/TodosMenu.vue';
},
},
plugins: [ // 引入webpack插件
new webpack.ProvidePlugin({
// webpack自动帮你加上import _ from 'lodash',记得在.eslintrc.js的globals里加上_属性为true,globals: { _: true, }
_: 'lodash'
})
]
},
};
复制代码