1.0.1 • Published 3 years ago

owl-assets-plugin v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

owl-assets-plugin

给 html-webpack-plugin 中添加,js 和 css 文件

注意事项

需要与 html-webpack-plugin 一起使用

Example

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const AssetsPlugin = require('./index')

const pagesConfig = {
  main: {
    css: ['main.css'],
    js: ['main.js']
  },
  about: {
    css: ['about.css'],
    js: ['about.js']
  }
}
const htmlPlugins = []
const entry = {}

Object.keys(pagesConfig).forEach((key) => {
  const filename = key
  const page = pagesConfig[key]
  entry[key] = [path.resolve(__dirname, 'pages', filename, './main.js')]
  htmlPlugins.push(
    new HtmlWebpackPlugin({
      inject: 'body',
      filename: `pages/${filename}.html`,
      chunks: [filename]
    }),
    new AssetsPlugin({
      files: [`**/${filename}.html`],
      ...page
    })
  )
})

module.exports = {
  mode: 'development',
  entry,
  output: {
    path: path.resolve('dist'),
    filename: 'js/[name].js',
    publicPath: '/'
  },
  plugins: [...htmlPlugins]
}