1 Star 0 Fork 0

七月有风 / webpack 配置

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
webpack.config.js 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
const path = require('path')
const HTMLPlugin = require('html-webpack-plugin')
const webpack = require('webpack');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const isDev = process.env.NODE_ENV === 'development'
const config = {
target: 'web', // webpack-dev-sever中使用
entry: path.join(__dirname, 'src/index.js'), //入口
output: {
filename: 'bundle.js',
path: path.join(__dirname, 'dist')
},
module: {
rules: [{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.css$/,
use: [
'css-loader'
]
},
{
test: /\.(gif|jpg|jpeg|png|svg)$/,
use: [{
loader: 'url-loader',
options: {
limit: 1024,
name: '[name]-aaa.[ext]'
}
}]
}, {
test: /\.styl/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: true,
}
},
'stylus-loader'
]
}
]
},
plugins: [
new VueLoaderPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: isDev ? '"development"' : '"production"'
// 里面的双引号一定要加
}
}),
new HTMLPlugin()
]
}
if (isDev) {
// es6 代码调试时做映射
config.devtool = '#cheap-module-eval-source-map'
config.devServer = {
port: 8081,
// 使用ip就可以访问
host: '0.0.0.0',
// 有错误显示在网页
overlay: {
errors: true,
},
// 热加载,改了某个组件后数据只会渲染某个组件的数据,不会渲染其他的数据
// 在ionic中因为没有这个功能,让开发变的及其痛苦
hot: true
},
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
)
}
module.exports = config
JavaScript
1
https://gitee.com/tanyplzu/webpack_configuration.git
git@gitee.com:tanyplzu/webpack_configuration.git
tanyplzu
webpack_configuration
webpack 配置
master

搜索帮助