1 Star 0 Fork 0

一月/webpack-config

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.dev.config.js 3.12 KB
一键复制 编辑 原始数据 按行查看 历史
wangguofeng 提交于 2021-09-22 15:34 . 初始化
// noinspection DuplicatedCode
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const {resolve} = require('path')
const postcssLoader = {
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [require('autoprefixer')]
}
}
}
const cssLoader = [
'style-loader',
'css-loader',
postcssLoader
]
module.exports = {
mode: 'development',
entry: ['./src/js/index', './index.html'],
output: {
path: resolve(__dirname, 'dest'),
filename: 'index.js'
},
module: {
rules: [
{
test: /\.jsx?/i,
exclude: /node_modules/,
enforce: 'pre',
use: 'eslint-loader'
},
{
oneOf: [
{
test: /\.css$/,
use: cssLoader
},
{
test: /\.less$/i,
use: [
...cssLoader,
'less-loader'
]
},
{
test: /\.s[ac]ss$/i,
use: [
...cssLoader,
{
loader: 'sass-loader',
options: {
additionalData: '@import \'./src/css/variable.scss\';'
}
}
]
},
{
test: /\.(jpe?g|png|gif)$/i,
use: {
loader: 'url-loader',
options: {
name: '[name].[hash:8].[ext]', // 重命名
outputPath: 'images', // 图片都放到output.path的images目录下
limit: 8 * 1024 // 小于8k的生成base64
}
}
},
{
test: /\.html$/i,
use: 'html-loader' // 配合html-webpack-plugin处理img标签的链接
},
{
test: /\.(svg|ttf|eot|woff|woff2)/i,
use: {
loader: 'file-loader',
options: {
name: '[name].[hash:8].[ext]',
outputPath: 'assets',
}
}
},
{
test: /\.jsx?/i,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: 3
}
]
],
// 下面的需要下载@babel/plugin-transform-runtiome -D和@babel/runtime -S,所以我选择上面的
// plugins: [
// [
// '@babel/plugin-transform-runtime',
// {
// corejs: 3
// }
// ]
// ],
cacheDirectory: true
}
}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: resolve(__dirname, 'index.html'),
filename: 'index.html'
}),
new CleanWebpackPlugin()
],
devServer: {
open: true
},
devtool: 'source-map'
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/onemonth/webpack-config.git
[email protected]:onemonth/webpack-config.git
onemonth
webpack-config
webpack-config
master

搜索帮助