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
*
*/
module.exports = function tinyComponentsWebpack(files, options = {}) {
// merge options with defaults
const defaults = Object.assign({
context: path.resolve(process.cwd(), ''),
destination: path.resolve(process.cwd(), 'public'),
publicPath: '/',
purge: {
src: path.join(__dirname, 'js'),
safelist: []
}
}, options)
module.exports = function tinyComponentsWebpack(files, options = {}) {
const config = {
context: defaults.context,
entry: files,
output: {
path: defaults.destination,
filename: 'js/[name].js',
publicPath: defaults.publicPath
},
// merge options with defaults
const defaults = Object.assign({
context: path.resolve(process.cwd(), ''),
destination: path.resolve(process.cwd(), 'public'),
publicPath: '/',
purge: {
src: path.join(__dirname, 'js')
},
plugins: []
}, options)
resolve: {
modules: ['node_modules'],
},
const config = {
context: defaults.context,
entry: files,
output: {
path: defaults.destination,
filename: 'js/[name].js',
publicPath: defaults.publicPath
},
optimization: {
removeEmptyChunks: true,
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false
})
]
},
resolve: {
modules: ['node_modules'],
},
module: {
rules: [{
test: /\.(css|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { url: false }
},
'sass-loader'
]
},{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
generator: {
filename: "fonts/[name].[ext]",
}
}]
},
optimization: {
removeEmptyChunks: true,
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false
})
]
},
plugins: [
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
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.context
})
],
}
module: {
rules: [{
test: /\.(css|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { url: false }
},
'sass-loader'
]
},{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
generator: {
filename: "fonts/[name].[ext]",
}
}]
}
}
// if rules exists add
if (defaults.rules) {
defaults.rules.forEach((rule) => {
config.module.rules.push(rule)
})
}
config.plugins = defaults.plugins.concat([
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
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 (defaults.svg && 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-'
}
}))
}
// if rules exists add
if (defaults.rules) {
defaults.rules.forEach((rule) => {
config.module.rules.push(rule)
})
}
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",
"version": "0.5.2",
"version": "0.6.0",
"description": "Webpack Wrapper",
"repository": {
"type": "git",

Loading…
Cancel
Save