Last active
August 24, 2020 08:59
-
-
Save Pepeye/8228bd468d5bc065fb33 to your computer and use it in GitHub Desktop.
Multi Environment Webpack Config
This file contains 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
import webpack from 'webpack' | |
import path from 'path' | |
import _debug from 'debug' | |
import ExtractTextPlugin from 'extract-text-webpack-plugin' | |
const ENVIRONMENT = process.env.NODE_ENV | |
const debug = _debug('app:webpack:base') | |
debug('Create configuration.') | |
const webpackConfig = { | |
entry: { | |
app: ['./client'] | |
}, | |
output: { | |
publicPath: '/dist/', | |
filename: '[name].bundle.js', | |
path: path.join(__dirname, 'static', 'dist') | |
}, | |
resolve: { | |
modulesDirectories: ['src', 'assets', 'node_modules'], | |
extensions: ['', '.js', '.jsx', 'scss'] | |
}, | |
module: { | |
preLoaders: [ | |
{ | |
test: /\.(js|jsx)$/, | |
loader: 'eslint', | |
exclude: /node_modules/ | |
} | |
], | |
loaders: [ | |
{ test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader', 'autoprefixer-loader') }, | |
{ test: /\.scss$/, loader: ExtractTextPlugin.extract('sass-loader', 'css-loader', 'autoprefixer-loader') }, | |
{ test: /\.json$/, loader: 'json-loader' }, | |
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader?name=img/img-[hash:6].[ext]&limit=5000' }, | |
/* eslint-disable */ | |
{ test: /\.woff(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff' }, | |
{ test: /\.woff2(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff2' }, | |
{ test: /\.ttf(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/octet-stream' }, | |
{ test: /\.eot(\?.*)?$/, loader: 'file?prefix=fonts/&name=[path][name].[ext]' }, | |
{ test: /\.svg(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=image/svg+xml' } | |
/* eslint-enable */ | |
] | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ | |
NODE_ENV: ENVIRONMENT, | |
__DEV__: ENVIRONMENT !== 'production', | |
__PRODUCTION__: ENVIRONMENT === 'production' | |
}), | |
new webpack.optimize.OccurenceOrderPlugin(), | |
new ExtractTextPlugin('[name].css', { allChunks: true }) | |
] | |
} | |
export default webpackConfig |
This file contains 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
import webpack from 'webpack' | |
import config from './webpack.config.base' | |
import _debug from 'debug' | |
const debug = _debug('app:webpack:development') | |
debug('Create environment configuration.') | |
const webpackConfig = { | |
...config, | |
devtool: 'cheap-module-eval-source-map', | |
entry: { | |
app: [ | |
...config.entry.app, | |
'webpack-hot-middleware/client' | |
] | |
}, | |
output: { | |
...config.output, | |
filename: `index.js`, | |
publicPath: `/` | |
}, | |
module: { | |
...config.module, | |
loaders: [ | |
{ | |
test: /\.(js|jsx)$/, | |
exclude: /node_modules/, | |
loader: 'babel', | |
query: { | |
plugins: ['transform-runtime', 'add-module-exports', 'transform-decorators-legacy'], | |
presets: ['es2015', 'react', 'stage-0'], | |
env: { | |
development: { | |
plugins: [ | |
['react-transform', { | |
// omit HMR plugin by default and _only_ load in hot mode | |
transforms: [{ | |
transform: 'react-transform-hmr', | |
imports: ['react'], | |
locals: ['module'] | |
}, { | |
transform: 'react-transform-catch-errors', | |
imports: ['react', 'redbox-react'] | |
}] | |
}] | |
] | |
} | |
} | |
} | |
}, | |
...config.module.loaders | |
] | |
}, | |
plugins: [ | |
...config.plugins, | |
new webpack.HotModuleReplacementPlugin(), | |
new webpack.NoErrorsPlugin() | |
] | |
} | |
export default webpackConfig |
This file contains 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
import webpack from 'webpack' | |
import config from './webpack.config.base' | |
import _debug from 'debug' | |
const debug = _debug('app:webpack:production') | |
debug('Create environment configuration.') | |
const webpackConfig = { | |
...config, | |
devtool: 'source-map', | |
output: { | |
...config.output, | |
filename: `[name].bundle.js` | |
}, | |
module: { | |
...config.module, | |
loaders: [ | |
{ | |
test: /\.(js|jsx)$/, | |
exclude: /node_modules/, | |
loader: 'babel' | |
}, | |
...config.module.loaders | |
] | |
}, | |
plugins: [ | |
...config.plugins, | |
new webpack.optimize.UglifyJsPlugin({ | |
compressor: { | |
warnings: false | |
} | |
}) | |
] | |
} | |
export default webpackConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment