bugfix for manifest path, extend to merge plugins

main v0.6.0
HerrHase 1 week ago
parent 0e3461afa1
commit c0fa667d94

@ -16,118 +16,119 @@ const glob = require('glob')
* @link https://git.node001.net/tiny-components/webpack.git * @link https://git.node001.net/tiny-components/webpack.git
* *
*/ */
module.exports = function tinyComponentsWebpack(files, options = {}) {
// merge options with defaults module.exports = function tinyComponentsWebpack(files, options = {}) {
const defaults = Object.assign({
context: path.resolve(process.cwd(), ''),
destination: path.resolve(process.cwd(), 'public'),
publicPath: '/',
purge: {
src: path.join(__dirname, 'js'),
safelist: []
}
}, options)
const config = { // merge options with defaults
context: defaults.context, const defaults = Object.assign({
entry: files, context: path.resolve(process.cwd(), ''),
output: { destination: path.resolve(process.cwd(), 'public'),
path: defaults.destination, publicPath: '/',
filename: 'js/[name].js', purge: {
publicPath: defaults.publicPath src: path.join(__dirname, 'js')
}, },
plugins: []
}, options)
resolve: { const config = {
modules: ['node_modules'], context: defaults.context,
}, entry: files,
output: {
path: defaults.destination,
filename: 'js/[name].js',
publicPath: defaults.publicPath
},
optimization: { resolve: {
removeEmptyChunks: true, modules: ['node_modules'],
minimize: true, },
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false
})
]
},
module: { optimization: {
rules: [{ removeEmptyChunks: true,
test: /\.(css|scss)$/, minimize: true,
use: [ minimizer: [
MiniCssExtractPlugin.loader, new TerserPlugin({
{ terserOptions: {
loader: 'css-loader', output: {
options: { url: false } comments: false,
}, },
'sass-loader' },
] extractComments: false
},{ })
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/, ]
type: 'asset/resource', },
generator: {
filename: "fonts/[name].[ext]",
}
}]
},
plugins: [ module: {
new RemoveEmptyScriptsPlugin(), rules: [{
new MiniCssExtractPlugin({ test: /\.(css|scss)$/,
filename: 'css/[name].css', use: [
}), MiniCssExtractPlugin.loader,
new PurgeCSSPlugin({ {
paths: glob.sync(`${defaults.purge.src}/**/*`, { nodir: true }), loader: 'css-loader',
safelist: defaults.purge.safelist options: { url: false }
}), },
new ManifestPlugin({ 'sass-loader'
filename: 'assets-manifest.json', ]
context: defaults.context },{
}) test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
], type: 'asset/resource',
} generator: {
filename: "fonts/[name].[ext]",
}
}]
}
}
// if rules exists add config.plugins = defaults.plugins.concat([
if (defaults.rules) { new RemoveEmptyScriptsPlugin(),
defaults.rules.forEach((rule) => { new MiniCssExtractPlugin({
config.module.rules.push(rule) filename: 'css/[name].css',
}) }),
} new PurgeCSSPlugin({
paths: glob.sync(`${defaults.purge.src}/**/*`, { nodir: true }),
safelist: defaults.purge.safelist
}),
new ManifestPlugin({
filename: 'assets-manifest.json',
context: defaults.destination
})
])
// adding svg src // if rules exists add
if (defaults.svg && defaults.svg.src) { if (defaults.rules) {
config.plugins.push(new SvgSpritemapPlugin(defaults.svg.src, { defaults.rules.forEach((rule) => {
output: { config.module.rules.push(rule)
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 // adding svg src
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
} }

@ -1,6 +1,6 @@
{ {
"name": "@tiny-components/webpack", "name": "@tiny-components/webpack",
"version": "0.5.2", "version": "0.6.0",
"description": "Webpack Wrapper", "description": "Webpack Wrapper",
"repository": { "repository": {
"type": "git", "type": "git",

Loading…
Cancel
Save