Skip to content

Instantly share code, notes, and snippets.

@YasushiKobayashi
Created May 6, 2017 05:56
Show Gist options
  • Save YasushiKobayashi/618e94e224d9aa57e14bed959b73369f to your computer and use it in GitHub Desktop.
Save YasushiKobayashi/618e94e224d9aa57e14bed959b73369f to your computer and use it in GitHub Desktop.
ディレクトリ構成を維持しつつwebpackで複数ファイルをビルドする(nodejs用)
import webpack from 'webpack';
import path from 'path';
import glob from 'glob';
import nodeExternals from 'webpack-node-externals';
import loaders from './webpack.loaders';
const jsBasePath = path.resolve(__dirname, './');
const targetDirectories = ['es'];
const targets = glob.sync(`${jsBasePath}/+(${targetDirectories.join('|')})/*.js`);
const entries = {};
targets.forEach((value) => {
const re = new RegExp(`${jsBasePath}/`);
const key = value.replace(re, '');
entries[key] = value;
});
module.exports = {
entry: entries,
output: {
path: path.join(__dirname, 'js'),
filename: '[name]',
},
module: {
loaders,
},
target: 'node',
node: {
__filename: true,
__dirname: true,
},
externals: nodeExternals(),
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
drop_debugger: true,
},
}),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment