1 Star 0 Fork 1

文昶/butterfly

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
webpack.config.js 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
jianyi.yl 提交于 2021-05-18 15:17 . feat(webpack): add unpkg type
const _ = require('lodash');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const common = {
mode: 'production',
devtool: 'cheap-module-source-map',
performance: {
hints: false
},
entry: './index.js',
output: {
path: __dirname,
filename: 'dist/index.js',
libraryTarget: 'umd',
},
resolve: {
alias: {},
},
plugins: [
new MiniCssExtractPlugin({
filename: 'dist/index.css',
chunkFilename: '[id].css'
})
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'], //'env'--babel7中的es7语法编译插件
// plugins: ['transform-decorators-legacy', 'transform-class-properties', 'add-module-exports', 'transform-object-rest-spread'],
plugins: ['transform-es2015-modules-commonjs', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-proposal-class-properties']
}
}
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "less-loader" // compiles Less to CSS
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 1024 * 200,
name: '[name].[ext]',
outputPath: '/dist/fonts/'
}
}
}
]
},
optimization: {
minimize: false
}
};
const main = _.cloneDeep(common);
const unpkg = _.cloneDeep(common);
/**
* unpkg包需要满足条件:
* 1. no sourcemap
* 2. no mini-css-extract-plugin
* 3. minimize: true
*/
unpkg.optimization.minimize = true;
delete unpkg.devtool;
unpkg.output.filename = 'unpkg/index.unpkg.js';
unpkg.plugins.pop();
unpkg.module.rules[1].use.shift();
module.exports = [
main,
unpkg
];
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wenchang666/butterfly.git
[email protected]:wenchang666/butterfly.git
wenchang666
butterfly
butterfly
master

搜索帮助