Skip to content

Instantly share code, notes, and snippets.

@HiDeoo
Created November 22, 2017 17:11
Show Gist options
  • Save HiDeoo/6b4b9009bec8e47b5261bba63c7196d3 to your computer and use it in GitHub Desktop.
Save HiDeoo/6b4b9009bec8e47b5261bba63c7196d3 to your computer and use it in GitHub Desktop.
Webpack
// We're not using ES6 import/export in this file to avoid linting failures in some environments like Atom.
// We're using the webpack resolver in our ESLint configuration for the import plugin and we're using this file as
// configuration. Atom package linter-eslint will automatically invokes ESLint for us and we can't choose to run
// it using babel-node.
// @see:https://github.com/benmosher/eslint-plugin-import/issues/536
const _ = require('lodash')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const LodashPlugin = require('lodash-webpack-plugin')
const path = require('path')
const webpack = require('webpack')
const pkg = require('./package.json')
/**
* Base plugins list.
* @type {Plugins[]}
*/
const plugins = []
if (!_.isNil(process.env.ANALYZE_BUNDLE)) {
plugins.push(new BundleAnalyzerPlugin())
}
/**
* Webpack Base configuration.
* @type {Object}
*/
module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules(?!\/(devtron|joi|hoek|isemail|topo))/,
options: {
cacheDirectory: true,
},
},
{
test: /\.woff2$/,
loader: 'file-loader',
options: {
name: 'assets/fonts/[name].[ext]',
},
},
{
test: /\.(png|ico)$/,
loader: 'url-loader',
options: {
limit: 100000,
},
},
{
test: /\.md$/,
use: [
{
loader: 'html-loader',
},
{
loader: 'markdown-loader',
},
],
},
],
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
},
plugins: [
...plugins,
new LodashPlugin({
collections: true,
paths: true,
shorthands: true,
coercions: true,
}),
new webpack.DefinePlugin({
'global.GENTLY': false,
_URL_: JSON.stringify(pkg.repository.url),
_VERSION_: JSON.stringify(pkg.version),
}),
new webpack.optimize.ModuleConcatenationPlugin(),
],
resolve: {
alias: {
/**
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
ALIASES Kreygasm
Components: path.resolve(__dirname, 'src/components/'),
Store: path.resolve(__dirname, 'src/store/'),
**/
},
},
}
import merge from 'webpack-merge'
import webpack from 'webpack'
import baseConfig from './webpack.config.base'
/**
* Developer server port.
* @type {number}
*/
const port = process.env.PORT || 8000
/**
* Webpack Development configuration.
* @type {Object}
*/
export default merge(baseConfig, {
devtool: 'cheap-module-source-map',
entry: [
'react-hot-loader/patch',
`webpack-dev-server/client?http://localhost:${port}`,
'webpack/hot/only-dev-server',
'./src/index',
],
output: {
publicPath: `http://localhost:${port}/dist/`,
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
],
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
target: 'electron-renderer',
})
import CopyWebpackPlugin from 'copy-webpack-plugin'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import merge from 'webpack-merge'
import MinifyPlugin from 'babel-minify-webpack-plugin'
import path from 'path'
import webpack from 'webpack'
import baseConfig from './webpack.config.base'
/**
* Webpack Production (Electron Renderer) configuration.
* @type {Object}
*/
export default merge(baseConfig, {
devtool: 'cheap-module-source-map',
entry: ['./src/index'],
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader',
}),
},
],
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '../dist/',
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
'global.GENTLY': false,
}),
new ExtractTextPlugin({
filename: 'styles.css',
allChunks: true,
}),
new CopyWebpackPlugin(/** removed in the example **/),
new MinifyPlugin(
{},
{
sourceMap: true,
}
),
],
target: 'electron-renderer',
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment