Created
May 4, 2019 17:03
-
-
Save channainfo/32377697b37a233f92e02ad23e8ab02c to your computer and use it in GitHub Desktop.
Multiple entries from a directory dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const glob = require('glob'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const templateEntries = glob.sync('./js/templates/**.js').reduce(function(obj, el){ | |
var name = "./templates/" + path.parse(el).name | |
obj[name] = el; | |
return obj | |
},{}) | |
const mainEntries = { | |
'./app': ['./js/app.js'].concat(glob.sync('./vendor/**/*.js')), | |
'./manage': ['./js/manage.js'].concat(glob.sync('./vendor/**/*.js')), | |
'./admin': ['./js/admin.js'].concat(glob.sync('./vendor/**/*.js')) | |
} | |
const entries = Object.assign(templateEntries, mainEntries) | |
module.exports = (env, options) => ({ | |
optimization: { | |
minimizer: [ | |
new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }), | |
new OptimizeCSSAssetsPlugin({}) | |
] | |
}, | |
entry: entries, | |
output: { | |
filename: '[name].js', | |
path: path.resolve(__dirname, '../priv/static/js') | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader' | |
} | |
}, | |
{ | |
// test: /\.css$/, | |
// use: [MiniCssExtractPlugin.loader, 'css-loader'] | |
test: /\.scss$/, | |
use: [ | |
MiniCssExtractPlugin.loader, | |
{ | |
loader: 'css-loader', | |
options: {} | |
}, | |
{ | |
loader: 'sass-loader', | |
options: {} | |
} | |
] | |
} | |
] | |
}, | |
plugins: [ | |
// new MiniCssExtractPlugin({ filename: '../css/app.css' }), | |
new MiniCssExtractPlugin({ filename: '../css/[name].css' }), | |
new CopyWebpackPlugin([{ from: 'static/', to: '../' }]) | |
], | |
resolve: { | |
alias: { | |
react: path.resolve(__dirname, './node_modules/react'), | |
'react-dom': path.resolve(__dirname, './node_modules/react-dom') | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment