Skip to content

Instantly share code, notes, and snippets.

@gauravtiwari
Last active February 22, 2017 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauravtiwari/4e5673c08e60fcb2a86a81906e9c4dc2 to your computer and use it in GitHub Desktop.
Save gauravtiwari/4e5673c08e60fcb2a86a81906e9c4dc2 to your computer and use it in GitHub Desktop.
Shared webpack config
// Note: You must restart bin/webpack-watcher for changes to take effect
var path = require('path');
var glob = require('glob');
var extname = require('path-complete-extname');
var distPath = process.env.WEBPACK_DIST_PATH;
if (distPath === undefined) {
distPath = 'packs'
}
var config = {
entry: glob.sync(path.resolve('app', 'javascript', 'packs', '*.js*')).reduce(
function(map, entry) {
basename = path.basename(entry, extname(entry))
map[basename] = path.resolve(entry);
return map;
}, {}
),
output: { filename: '[name].js', path: path.resolve('public', distPath) },
module: {
rules: [
{ test: /\.coffee(.erb)?$/, loader: 'coffee-loader' },
{
test: /\.jsx?(.erb)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
'react', ['latest', { 'es2015': { 'modules': false } }],
['env', { "modules": false }],
],
}
},
{
test: /\.erb$/,
enforce: 'pre',
loader: 'rails-erb-loader',
options: {
runner: 'bin/rails runner'
}
},
{
test: /\.sass$/,
loader: ['style-loader', 'css-loader', 'sass-loader'],
},
]
},
plugins: [],
resolve: {
alias: {
'ie': 'component-ie',
},
extensions: [ '.js', '.coffee' ],
modules: [
path.resolve('app/javascript'),
path.resolve('node_modules')
]
},
resolveLoader: {
modules: [ path.resolve('node_modules') ]
}
}
module.exports = {
distPath: distPath,
config: config
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment