safe-react/config/webpack.config.dev.js

156 lines
4.8 KiB
JavaScript
Raw Normal View History

/*eslint-disable*/
const autoprefixer = require('autoprefixer')
const cssmixins = require('postcss-mixins')
const cssvars = require('postcss-simple-vars')
const webpack = require('webpack')
const HtmlWebPackPlugin = require('html-webpack-plugin')
2018-03-06 08:52:55 +00:00
const paths = require('./paths')
const getClientEnvironment = require('./env')
2018-03-06 08:52:55 +00:00
const publicPath = '/'
2018-03-06 09:52:49 +00:00
2018-03-06 08:52:55 +00:00
// `publicUrl` we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
var publicUrl = ''
2018-03-06 08:52:55 +00:00
// Get environment variables to inject into our app.
var env = getClientEnvironment(publicUrl)
2018-03-06 08:20:10 +00:00
const cssvariables = require(paths.appSrc + '/theme/variables')
2018-03-06 08:20:10 +00:00
const postcssPlugins = [
autoprefixer({
2019-05-21 14:19:59 +00:00
overrideBrowserslist: [
2018-03-06 08:20:10 +00:00
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
2018-03-06 08:20:10 +00:00
}),
cssmixins,
2018-03-06 08:20:10 +00:00
cssvars({
variables: function() {
return Object.assign({}, cssvariables)
2018-03-06 08:20:10 +00:00
},
silent: false,
2018-03-06 08:20:10 +00:00
}),
]
2018-03-06 08:20:10 +00:00
module.exports = {
devtool: 'eval-source-map',
mode: 'development',
entry: [
'babel-polyfill',
// Include an alternative client for WebpackDevServer. A client's job is to
// connect to WebpackDevServer by a socket and get notified about changes.
// When you save a file, the client will either apply hot updates (in case
// of CSS changes), or refresh the page (in case of JS changes). When you
// make a syntax error, this client will display a syntax error overlay.
// Note: instead of the default WebpackDevServer client, we use a custom one
// to bring better experience for Create React App users. You can replace
// the line below with these two lines if you prefer the stock client:
// require.resolve('webpack-dev-server/client') + '?/',
// require.resolve('webpack/hot/dev-server'),
require.resolve('react-dev-utils/webpackHotDevClient'),
// We ship a few polyfills by default:
require.resolve('./polyfills'),
// Finally, this is your app's code:
paths.appIndexJs,
// We include the app code last so that if there is a runtime error during
// initialization, it doesn't blow up the WebpackDevServer client, and
// changing JS code would still trigger a refresh.
],
2018-03-08 08:27:17 +00:00
resolve: {
modules: [paths.appSrc, 'node_modules', paths.appContracts],
// These are the reasonable defaults supported by the Node ecosystem.
// We also include JSX as a common component filename extension to support
// some tools, although we do not recommend using it, see:
// https://github.com/facebookincubator/create-react-app/issues/290
2018-03-06 08:20:10 +00:00
extensions: ['.js', '.json', '.jsx'],
alias: {
'~': paths.appSrc,
'#': paths.appContracts,
},
2018-03-06 09:52:49 +00:00
},
output: {
// Next line is not used in dev but WebpackDevServer crashes without it:
path: paths.appBuild,
// Add /* filename */ comments to generated require()s in the output.
pathinfo: true,
// This does not produce a real file. It's just the virtual path that is
// served by WebpackDevServer in development. This is the JS bundle
// containing code from all our entry points, and the Webpack runtime.
filename: 'static/js/bundle.js',
// This is the URL that app is served from. We use "/" in development.
publicPath: publicPath,
},
2018-03-06 08:20:10 +00:00
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
2018-03-06 08:20:10 +00:00
},
{
test: /\.(scss|css)$/,
use: [
'style-loader',
{
loader: 'css-loader',
2018-03-06 08:20:10 +00:00
options: {
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
2018-03-06 08:20:10 +00:00
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: postcssPlugins,
},
},
],
},
2018-03-06 08:20:10 +00:00
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: false },
},
],
},
{
test: /\.(jpe?g|png|svg)$/i,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
name: 'img/[hash].[ext]',
},
},
],
},
],
2018-03-06 08:20:10 +00:00
},
plugins: [
new HtmlWebPackPlugin({
template: paths.appHtml,
2018-03-06 08:52:55 +00:00
}),
new webpack.DefinePlugin(env),
new webpack.HotModuleReplacementPlugin(),
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
},
}