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'
})
]
},
};
複製代碼