owl-assets-plugin

1.0.1 • Public • Published

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]
}

Package Sidebar

Install

npm i owl-assets-plugin

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

6.99 kB

Total Files

4

Last publish

Collaborators

  • owl.js