Skip to content

Commit 59101ef

Browse files
authored
Merge pull request #242 from halfzebra/webpack-4
Webpack 4
2 parents 959a533 + 106592a commit 59101ef

15 files changed

+278
-8124
lines changed

.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module.exports = {
55
es6: true,
66
node: true
77
},
8+
parserOptions: {
9+
ecmaVersion: 6
10+
},
811
extends: ['eslint:recommended'],
912
plugins: ['prettier'],
1013
rules: {

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
singleQuote: true
3+
}

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ sudo: required
33
node_js:
44
- '9'
55
- '8'
6-
- '7'
7-
- '6'
86
addons:
97
apt:
108
packages:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Create a production build with `elm-app build`
2121

2222
### Installation
2323

24-
**Node >=6** is required for installation.
24+
**Node >=8** is required for installation.
2525

2626
#### Yarn
2727

appveyor.yml

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ image: Visual Studio 2017
33
platform:
44
- x64
55

6+
# Test against these versions of Node.js.
7+
environment:
8+
matrix:
9+
# node.js
10+
- nodejs_version: "8"
11+
- nodejs_version: "9"
12+
613
install:
714
- ps: Install-Product node $env:nodejs_version $env:platform
815

bin/elm-app-cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function help(version) {
9494
* Spawn separate node process with specified script
9595
*
9696
* @param {string} script Path to script
97-
* @param {Arrays} args Script arguments
97+
* @param {Array} args Script arguments
9898
* @return {undefined}
9999
*/
100100
function spawnSyncNode(script, args) {

config/polyfills.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
if (typeof Promise === 'undefined') {
4+
// Rejection tracking prevents a common issue where React gets into an
5+
// inconsistent state due to an error, but it gets swallowed by a Promise,
6+
// and the user has no idea what causes React's erratic future behavior.
7+
require('promise/lib/rejection-tracking').enable();
8+
window.Promise = require('promise/lib/es6-extensions.js');
9+
}
10+
11+
// fetch() polyfill for making API calls.
12+
require('whatwg-fetch');
13+
14+
// Object.assign() is commonly used with React.
15+
// It will use the native implementation if it's present and isn't buggy.
16+
Object.assign = require('object-assign');

config/webpack.config.dev.js

+64-34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
'use strict';
22

3-
const path = require('path');
43
const autoprefixer = require('autoprefixer');
5-
const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin');
6-
const DefinePlugin = require('webpack/lib/DefinePlugin');
7-
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
8-
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
4+
const path = require('path');
5+
const webpack = require('webpack');
96
const HtmlWebpackPlugin = require('html-webpack-plugin');
7+
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
8+
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
109
const getClientEnvironment = require('./env');
1110
const paths = require('../config/paths');
1211

@@ -20,10 +19,20 @@ const publicUrl = '';
2019
// Get environment variables to inject into our app.
2120
const env = getClientEnvironment(publicUrl);
2221

22+
// This is the development configuration.
23+
// It is focused on developer experience and fast rebuilds.
24+
// The production configuration is different and lives in a separate file.
2325
module.exports = {
26+
mode: 'development',
27+
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
28+
// See the discussion in https://github.com/facebook/create-react-app/issues/343.
2429
devtool: 'cheap-module-source-map',
25-
30+
// These are the "entry points" to our application.
31+
// This means they will be the "root" imports that are included in JS bundle.
32+
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
2633
entry: [
34+
// We ship a few polyfills by default:
35+
require.resolve('./polyfills'),
2736
// Include an alternative client for WebpackDevServer. A client's job is to
2837
// connect to WebpackDevServer by a socket and get notified about changes.
2938
// When you save a file, the client will either apply hot updates (in case
@@ -42,34 +51,44 @@ module.exports = {
4251

4352
paths.appIndexJs
4453
],
45-
4654
output: {
55+
// Add /* filename */ comments to generated require()s in the output.
4756
pathinfo: true,
48-
49-
// The build folder.
50-
path: paths.appBuild,
51-
5257
// This does not produce a real file. It's just the virtual path that is
5358
// served by WebpackDevServer in development. This is the JS bundle
5459
// containing code from all our entry points, and the Webpack runtime.
5560
filename: 'static/js/bundle.js',
56-
61+
// There are also additional JS chunk files if you use code splitting.
62+
chunkFilename: 'static/js/[name].chunk.js',
63+
// This is the URL that app is served from. We use "/" in development.
5764
publicPath: publicPath,
58-
5965
// Point sourcemap entries to original disk location (format as URL on Windows)
6066
devtoolModuleFilenameTemplate: info =>
6167
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')
6268
},
63-
69+
optimization: {
70+
// Automatically split vendor and commons
71+
// https://twitter.com/wSokra/status/969633336732905474
72+
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
73+
splitChunks: {
74+
chunks: 'all',
75+
name: 'vendors'
76+
},
77+
// Keep the runtime chunk seperated to enable long term caching
78+
// https://twitter.com/wSokra/status/969679223278505985
79+
runtimeChunk: true
80+
},
6481
resolve: {
6582
modules: ['node_modules'],
6683
extensions: ['.js', '.elm']
6784
},
68-
6985
module: {
7086
noParse: /\.elm$/,
71-
87+
strictExportPresence: true,
7288
rules: [
89+
// Disable require.ensure as it's not a standard language feature.
90+
{ parser: { requireEnsure: false } },
91+
7392
{
7493
test: /\.js$/,
7594
exclude: [/[/\\\\]elm-stuff[/\\\\]/, /[/\\\\]node_modules[/\\\\]/],
@@ -169,8 +188,9 @@ module.exports = {
169188
// "style" loader turns CSS into JS modules that inject <style> tags.
170189
// In production, we use a plugin to extract that CSS to a file, but
171190
// in development "style" loader enables hot editing of CSS.
191+
// By default we support CSS Modules with the extension .module.css
172192
{
173-
test: /\.css$/,
193+
test: /\.css/,
174194
use: [
175195
require.resolve('style-loader'),
176196
{
@@ -180,17 +200,18 @@ module.exports = {
180200
}
181201
},
182202
{
203+
// Options for PostCSS as we reference these options twice
204+
// Adds vendor prefixing based on your specified browser support in
205+
// package.json
183206
loader: require.resolve('postcss-loader'),
184207
options: {
185-
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
208+
// Necessary for external CSS imports to work
209+
// https://github.com/facebook/create-react-app/issues/2677
210+
ident: 'postcss',
186211
plugins: () => [
212+
require('postcss-flexbugs-fixes'),
187213
autoprefixer({
188-
browsers: [
189-
'>1%',
190-
'last 4 versions',
191-
'Firefox ESR',
192-
'not ie < 9'
193-
]
214+
flexbox: 'no-2009'
194215
})
195216
]
196217
}
@@ -217,20 +238,26 @@ module.exports = {
217238
}
218239
]
219240
},
220-
221241
plugins: [
222-
new DefinePlugin(env.stringified),
223-
224-
new InterpolateHtmlPlugin(env.raw),
225-
242+
// Generates an `index.html` file with the <script> injected.
226243
new HtmlWebpackPlugin({
227244
inject: true,
228245
template: paths.appHtml
229246
}),
230-
231-
new HotModuleReplacementPlugin(),
232-
233-
new NamedModulesPlugin()
247+
// Makes some environment variables available in index.html.
248+
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
249+
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
250+
// In development, this will be an empty string.
251+
new InterpolateHtmlPlugin(env.raw),
252+
// Makes some environment variables available to the JS code, for example:
253+
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
254+
new webpack.DefinePlugin(env.stringified),
255+
// This is necessary to emit hot updates (currently CSS only):
256+
new webpack.HotModuleReplacementPlugin(),
257+
// Watcher doesn't work well if you mistype casing in a path so we use
258+
// a plugin that prints an error when you attempt to do this.
259+
// See https://github.com/facebook/create-react-app/issues/240
260+
new CaseSensitivePathsPlugin()
234261
],
235262

236263
// Some libraries import Node modules but don't use them in the browser.
@@ -241,5 +268,8 @@ module.exports = {
241268
net: 'empty',
242269
tls: 'empty',
243270
child_process: 'empty'
244-
}
271+
},
272+
// Turn off performance processing because we utilize
273+
// our own hints via the FileSizeReporter
274+
performance: false
245275
};

0 commit comments

Comments
 (0)