1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- const CopyWebpackPlugin = require('copy-webpack-plugin')
- const HtmlWebpackPlugin = require('html-webpack-plugin')
- const path = require('path')
- let fs = require('fs')
- const adminPath = 'admins'
- function resolve (dir) {
- return path.resolve(__dirname, '../', dir)
- }
- // 获取 admins 目录下的后台管理系统文件名并指定公共文件目录命名
- const files = fs.readdirSync(resolve(adminPath))
- function copyToApps(dir) {
- let r = []
-
- files.map(app => {
- r.push({
- from: resolve(dir),
- to: resolve(`${adminPath}/${app}/${dir}`)
- })
- })
- return r
- }
- let htmlPluginsArr = []
- files.map(app => {
- const config = require(`./../admins/${app}/config/config.js`)
- htmlPluginsArr.push(new HtmlWebpackPlugin({
- filename: `./../admins/${app}/index.html`,
- template: 'index.html',
- title: config.title,
- navTitle: config.navTitle
- }))
- })
- module.exports = {
- mode: 'development',
- watch: true,
- entry: resolve('index.js'),
- output: {
- path: resolve('.tmp'),
- filename: 'bundle.js'
- },
- devServer: {
- hot: true,
- port: 9000,
- contentBase: false
- },
- plugins: [
- new CopyWebpackPlugin([
- ...copyToApps('statics'),
- ...copyToApps('js'),
- ]),
- ...htmlPluginsArr
- ]
- }
|