Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Created February 6, 2017 06:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuroyoro/67530afc0345886801d5088233c813a9 to your computer and use it in GitHub Desktop.
Save yuroyoro/67530afc0345886801d5088233c813a9 to your computer and use it in GitHub Desktop.
webpacker.gemでapp/javascript/packs 以下にディレクトリを掘った場合に対応したconfig/webpack/shared.js
var path = require('path')
var glob = require('glob')
var extname = require('path-complete-extname')
module.exports = {
entry: glob.sync(path.join('..', 'app', 'javascript', 'packs', '**', '*.js*')).reduce(
function(map, entry) {
var relpath = path.relative(path.join('..', 'app', 'javascript', 'packs'), entry);
var basename = path.basename(relpath, extname(relpath));
var dirname = path.dirname(relpath);
if(dirname != ".") {
basename = path.join(dirname, basename)
}
map[basename] = entry
return map
}, {}
),
output: { filename: '[name].js', path: path.resolve('..', 'public', 'packs') },
module: {
rules: [
{ test: /\.coffee(.erb)?$/, loader: "coffee-loader" },
{
test: /\.js(.erb)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
[ 'latest', { 'es2015': { 'modules': false } } ]
]
}
},
{
test: /.erb$/,
enforce: 'pre',
exclude: /node_modules/,
loader: 'rails-erb-loader',
options: {
runner: 'DISABLE_SPRING=1 ../bin/rails runner'
}
},
]
},
plugins: [],
resolve: {
extensions: [ '.js', '.coffee' ],
modules: [
path.resolve('../app/javascript'),
path.resolve('../vendor/node_modules')
]
},
resolveLoader: {
modules: [ path.resolve('../vendor/node_modules') ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment