Skip to content

Instantly share code, notes, and snippets.

@kolpav
Created January 10, 2017 12:17
Show Gist options
  • Save kolpav/aa0737071fa47b6c326de921a30f775f to your computer and use it in GitHub Desktop.
Save kolpav/aa0737071fa47b6c326de921a30f775f to your computer and use it in GitHub Desktop.
var path = require('path')
var webpack = require('webpack')
var project = require('../project.json')
var InlineEnviromentVariablesPlugin = require('inline-environment-variables-webpack-plugin')
var ROOT_PATH = path.resolve(__dirname) // c:\Projects\palvelutietovaranto\src\PTV.Application.Web\webpack_external
var appJsPath = path.join(project.webroot, 'js', 'app') // wwwroot\js\app
module.exports = getOptions()
function getOptions () {
var options = {}
console.log('webpack options init - enviroment: ', process.env.NODE_ENV)
options.entry = ['babel-polyfill', path.resolve(appJsPath, 'main.jsx')]
options.output = {
path: path.resolve(project.webroot + '/js/build'),
filename: 'bundle.js'
}
if (process.env.NODE_ENV !== 'production') {
options.output.publicPath = 'http://localhost:4000/'
}
options.resolve = {
extensions: ['', '.js', '.jsx'],
modules: [appJsPath, 'node_modules']
}
options.module = {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react', 'stage-0', 'stage-2']
}
},
{
test: /\.scss$/,
loaders: [
'style',
'css',
'sass'
]
},
{
test: /\.less$/,
loaders: [
'style',
'css',
'less'
]
},
{
test: /\.jsonx$/,
loaders: [
'json'
]
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=100000'
}
]
}
options.devtool = 'source-map'
if (process.env.NODE_ENV !== 'production') {
options.devServer = {
host: '0.0.0.0',
port: '4000',
colors: true,
historyApiFallback: true,
hot: true,
inline: true,
stats: 'errors-only',
headers: { 'Access-Control-Allow-Origin': '*' }
}
options.plugins = [
new webpack.HotModuleReplacementPlugin()
]
} else {
options.plugins = [
new InlineEnviromentVariablesPlugin({ NODE_ENV: 'production' })
]
}
return options
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment