main
HerrHase 3 weeks ago
parent c0fa667d94
commit 747c2cfedd

@ -19,80 +19,85 @@ const glob = require('glob')
module.exports = function tinyComponentsWebpack(files, options = {}) { module.exports = function tinyComponentsWebpack(files, options = {}) {
// merge options with defaults // merge options with defaults
const defaults = Object.assign({ const defaults = Object.assign({
context: path.resolve(process.cwd(), ''), context: path.resolve(process.cwd(), ''),
destination: path.resolve(process.cwd(), 'public'), destination: path.resolve(process.cwd(), 'public'),
publicPath: '/', publicPath: '/',
purge: { purge: {
src: path.join(__dirname, 'js') src: path.join(__dirname, 'js')
}, },
plugins: [] plugins: []
}, options) }, options)
const config = { const config = {
context: defaults.context, context: defaults.context,
entry: files, entry: files,
output: { output: {
path: defaults.destination, path: defaults.destination,
filename: 'js/[name].js', filename: 'js/[name].js',
publicPath: defaults.publicPath publicPath: defaults.publicPath
}, },
resolve: { resolve: {
modules: ['node_modules'], modules: ['node_modules'],
}, },
optimization: { optimization: {
removeEmptyChunks: true, removeEmptyChunks: true,
minimize: true, minimize: true,
minimizer: [ minimizer: [
new TerserPlugin({ new TerserPlugin({
terserOptions: { terserOptions: {
output: { output: {
comments: false, comments: false,
}, },
}, },
extractComments: false extractComments: false
}) })
] ]
}, },
module: { module: {
rules: [{ rules: [{
test: /\.(css|scss)$/, test: /\.(css|scss)$/,
use: [ use: [
MiniCssExtractPlugin.loader, MiniCssExtractPlugin.loader,
{ {
loader: 'css-loader', loader: 'css-loader',
options: { url: false } options: { url: false }
}, },
'sass-loader' 'sass-loader'
] ]
},{ },{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/, test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource', type: 'asset/resource',
generator: { generator: {
filename: "fonts/[name].[ext]", filename: "fonts/[name].[ext]",
} }
}] }]
} }
} }
config.plugins = defaults.plugins.concat([ const plugins = [
new RemoveEmptyScriptsPlugin(), new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'css/[name].css', filename: 'css/[name].css',
}), }),
new PurgeCSSPlugin({ new ManifestPlugin({
paths: glob.sync(`${defaults.purge.src}/**/*`, { nodir: true }), filename: 'assets-manifest.json',
safelist: defaults.purge.safelist context: defaults.destination
}), })
new ManifestPlugin({ ]
filename: 'assets-manifest.json',
context: defaults.destination if (defaults.purge) {
}) plugins.push(new PurgeCSSPlugin({
]) paths: glob.sync(`${defaults.purge.src}/**/*`, { nodir: true }),
safelist: defaults.purge.safelist
}))
}
config.plugins = defaults.plugins.concat(plugins)
// if rules exists add // if rules exists add
if (defaults.rules) { if (defaults.rules) {
@ -102,33 +107,33 @@ const glob = require('glob')
} }
// adding svg src // adding svg src
if (defaults.svg.src) { if (defaults.svg.src) {
config.plugins.push(new SvgSpritemapPlugin(defaults.svg.src, { config.plugins.push(new SvgSpritemapPlugin(defaults.svg.src, {
output: { output: {
filename: 'symbol-defs.svg', filename: 'symbol-defs.svg',
chunk: { chunk: {
keep: true keep: true
}, },
svgo: { svgo: {
plugins: [{ plugins: [{
name: 'convertStyleToAttrs', name: 'convertStyleToAttrs',
active: true active: true
},{ },{
name: 'removeStyleElement', name: 'removeStyleElement',
active: true active: true
}, { }, {
name: 'removeAttrs', name: 'removeAttrs',
params: { params: {
attrs: 'fill' attrs: 'fill'
} }
}] }]
} }
}, },
sprite: { sprite: {
prefix: 'icon-' prefix: 'icon-'
} }
})) }))
} }
return config return config
} }

2536
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,10 +1,10 @@
{ {
"name": "@tiny-components/webpack", "name": "@tiny-components/webpack",
"version": "0.6.0", "version": "0.7.0",
"description": "Webpack Wrapper", "description": "Webpack Wrapper",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git@git.node001.net:tiny-components/webpack.git" "url": "git@git.node001.net:tiny-components/webpack.git"
}, },
"author": "Björn Hase <me@herr-hase.wtf>", "author": "Björn Hase <me@herr-hase.wtf>",
"license": "MIT", "license": "MIT",
@ -15,6 +15,7 @@
"sass": "^1.71.1", "sass": "^1.71.1",
"sass-loader": "^14.1.1", "sass-loader": "^14.1.1",
"svg-spritemap-webpack-plugin": "^4.5.0", "svg-spritemap-webpack-plugin": "^4.5.0",
"terser-webpack-plugin": "^5.6.1",
"webpack": "^5.90.3", "webpack": "^5.90.3",
"webpack-cli": "^5.1.4", "webpack-cli": "^5.1.4",
"webpack-remove-empty-scripts": "^1.0.4" "webpack-remove-empty-scripts": "^1.0.4"

Loading…
Cancel
Save