You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.0 KiB
106 lines
3.0 KiB
8 months ago
|
const webpack = require('webpack')
|
||
|
const TerserPlugin = require('terser-webpack-plugin')
|
||
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
||
|
const { PurgeCSSPlugin } = require('purgecss-webpack-plugin')
|
||
|
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts')
|
||
|
const SvgSpritemapPlugin = require('svg-spritemap-webpack-plugin')
|
||
|
const path = require('path')
|
||
|
const glob = require('glob')
|
||
|
|
||
|
const PATHS = {
|
||
|
src: path.join(__dirname, 'resources/js')
|
||
|
}
|
||
|
|
||
|
module.exports = function tinyComponentsWebpack(files, options = {}) {
|
||
|
|
||
|
// merge options with defaults
|
||
|
const defaults = Object.assign({
|
||
|
destination: path.resolve(__dirname, 'public')
|
||
|
}, options)
|
||
|
|
||
|
const config = {
|
||
|
entry: files,
|
||
|
output: {
|
||
|
path: defaults.destination,
|
||
|
filename: 'js/[name].js',
|
||
|
},
|
||
|
|
||
|
optimization: {
|
||
|
removeEmptyChunks: true,
|
||
|
minimize: true,
|
||
|
minimizer: [
|
||
|
new TerserPlugin({
|
||
|
terserOptions: {
|
||
|
output: {
|
||
|
comments: false,
|
||
|
},
|
||
|
},
|
||
|
extractComments: false
|
||
|
})
|
||
|
]
|
||
|
},
|
||
|
|
||
|
module: {
|
||
|
rules: [{
|
||
|
test: /\.riot$/,
|
||
|
exclude: /node_modules/,
|
||
|
use: [{
|
||
|
loader: '@riotjs/webpack-loader',
|
||
|
options: {
|
||
|
hot: false,
|
||
|
}
|
||
|
}]
|
||
|
},
|
||
|
{
|
||
|
test: /\.scss$/,
|
||
|
use: [
|
||
|
MiniCssExtractPlugin.loader,
|
||
|
'css-loader',
|
||
|
'sass-loader'
|
||
|
],
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
|
||
|
plugins: [
|
||
|
new RemoveEmptyScriptsPlugin(),
|
||
|
new MiniCssExtractPlugin({
|
||
|
filename: 'css/[name].css',
|
||
|
}),
|
||
|
new PurgeCSSPlugin({
|
||
|
paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true })
|
||
|
}),
|
||
|
],
|
||
|
}
|
||
|
|
||
|
if (defaults.svg.src) {
|
||
|
config.plugins.push(new SvgSpritemapPlugin(defaults.svg.src, {
|
||
|
output: {
|
||
|
filename: 'symbol-defs.svg',
|
||
|
chunk: {
|
||
|
keep: true
|
||
|
},
|
||
|
svgo: {
|
||
|
plugins: [{
|
||
|
name: 'convertStyleToAttrs',
|
||
|
active: true
|
||
|
},{
|
||
|
name: 'removeStyleElement',
|
||
|
active: true
|
||
|
}, {
|
||
|
name: 'removeAttrs',
|
||
|
params: {
|
||
|
attrs: 'fill'
|
||
|
}
|
||
|
}]
|
||
|
}
|
||
|
},
|
||
|
sprite: {
|
||
|
prefix: 'icon-'
|
||
|
}
|
||
|
}))
|
||
|
}
|
||
|
|
||
|
return config
|
||
|
}
|