Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 4 #242

Merged
merged 23 commits into from Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2d335a1
chore(package.json): Extract the configuration for prettier to the ex…
halfzebra Mar 20, 2018
9a78f84
chore(Added lint-staged to the devDependencies and the setup for runn…
halfzebra Mar 20, 2018
e0289d9
build(dev config): Added `case-sensitive-paths-webpack-plugin` for ex…
halfzebra Mar 20, 2018
f0ffc88
docs(webpackDevServer.config.js): Update the comments pointing to the…
halfzebra Mar 20, 2018
c274ca1
feat(scripts/start.js): Upgrade the script to use webpack@4.# APIs
halfzebra Mar 20, 2018
6e8cf30
feat(config/webpack.config.prod.js): Upgrade production configuration…
halfzebra Mar 20, 2018
aeaf21e
chore(.eslintrc): Allow ES6 for ESlint
halfzebra Mar 20, 2018
6dbfb46
fix(yarn.lock): Remove yarn.lock from the CVS
halfzebra Mar 20, 2018
d19bd53
feat(package.json): Upgrade dependencies to support webpack@4.#
halfzebra Mar 20, 2018
39d1003
fix(package.json): Fixed malformed package.json
halfzebra Mar 22, 2018
e016897
feat(package.json): Bump webpack to 4.2.0
halfzebra Mar 22, 2018
ddbc5ae
feat: Add a polyfill for Promise and fetch
halfzebra Jun 19, 2018
462027e
fix(package.json): Upgrade the dependencies to the latest
halfzebra Jun 20, 2018
ac51579
ci(.travis.yml): Remove Node 4 and 6 support.
halfzebra Jun 24, 2018
a72e81e
ci(appveyor.yml): Run tests on appveyor using Node 8 and 9
halfzebra Jun 24, 2018
649e574
fix(package.json): Upgraded outdated dependencies
halfzebra Jun 25, 2018
abea84d
test(package.json): Bump the Node engine in package.json to 8
halfzebra Jun 27, 2018
25fbe14
test(tests): Increase the timeouts to deal with appveyor false-negatives
halfzebra Jun 27, 2018
20ac506
docs(README.md): Updated the docs and the JSDOC in the elm-app-cli.js
halfzebra Aug 1, 2018
65e7876
fix(package.json): Add missing polyfill dependency.
halfzebra Aug 5, 2018
134fd3e
fix(webpack.config.dev): ship polyfills in dev mode as well.
halfzebra Aug 5, 2018
7c6a0b5
fix(webpack.config.dev): remove dead configuration, enable chunk spli…
halfzebra Aug 5, 2018
106592a
fix(webpack.config): added missing loader for images and removed dead…
halfzebra Aug 6, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.js
Expand Up @@ -5,6 +5,9 @@ module.exports = {
es6: true,
node: true
},
parserOptions: {
ecmaVersion: 6
},
extends: ['eslint:recommended'],
plugins: ['prettier'],
rules: {
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc
@@ -0,0 +1,3 @@
{
singleQuote: true
}
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -3,8 +3,6 @@ sudo: required
node_js:
- '9'
- '8'
- '7'
- '6'
addons:
apt:
packages:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -21,7 +21,7 @@ Create a production build with `elm-app build`

### Installation

**Node >=6** is required for installation.
**Node >=8** is required for installation.

#### Yarn

Expand Down
7 changes: 7 additions & 0 deletions appveyor.yml
Expand Up @@ -3,6 +3,13 @@ image: Visual Studio 2017
platform:
- x64

# Test against these versions of Node.js.
environment:
matrix:
# node.js
- nodejs_version: "8"
- nodejs_version: "9"

install:
- ps: Install-Product node $env:nodejs_version $env:platform

Expand Down
2 changes: 1 addition & 1 deletion bin/elm-app-cli.js
Expand Up @@ -94,7 +94,7 @@ function help(version) {
* Spawn separate node process with specified script
*
* @param {string} script Path to script
* @param {Arrays} args Script arguments
* @param {Array} args Script arguments
* @return {undefined}
*/
function spawnSyncNode(script, args) {
Expand Down
16 changes: 16 additions & 0 deletions config/polyfills.js
@@ -0,0 +1,16 @@
'use strict';

if (typeof Promise === 'undefined') {
// Rejection tracking prevents a common issue where React gets into an
// inconsistent state due to an error, but it gets swallowed by a Promise,
// and the user has no idea what causes React's erratic future behavior.
require('promise/lib/rejection-tracking').enable();
window.Promise = require('promise/lib/es6-extensions.js');
}

// fetch() polyfill for making API calls.
require('whatwg-fetch');

// Object.assign() is commonly used with React.
// It will use the native implementation if it's present and isn't buggy.
Object.assign = require('object-assign');
98 changes: 64 additions & 34 deletions config/webpack.config.dev.js
@@ -1,12 +1,11 @@
'use strict';

const path = require('path');
const autoprefixer = require('autoprefixer');
const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const getClientEnvironment = require('./env');
const paths = require('../config/paths');

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

// This is the development configuration.
// It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file.
module.exports = {
mode: 'development',
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
// See the discussion in https://github.com/facebook/create-react-app/issues/343.
devtool: 'cheap-module-source-map',

// These are the "entry points" to our application.
// This means they will be the "root" imports that are included in JS bundle.
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
entry: [
// We ship a few polyfills by default:
require.resolve('./polyfills'),
// 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
Expand All @@ -42,34 +51,44 @@ module.exports = {

paths.appIndexJs
],

output: {
// Add /* filename */ comments to generated require()s in the output.
pathinfo: true,

// The build folder.
path: paths.appBuild,

// 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',

// There are also additional JS chunk files if you use code splitting.
chunkFilename: 'static/js/[name].chunk.js',
// This is the URL that app is served from. We use "/" in development.
publicPath: publicPath,

// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: info =>
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')
},

optimization: {
// Automatically split vendor and commons
// https://twitter.com/wSokra/status/969633336732905474
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
splitChunks: {
chunks: 'all',
name: 'vendors'
},
// Keep the runtime chunk seperated to enable long term caching
// https://twitter.com/wSokra/status/969679223278505985
runtimeChunk: true
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.elm']
},

module: {
noParse: /\.elm$/,

strictExportPresence: true,
rules: [
// Disable require.ensure as it's not a standard language feature.
{ parser: { requireEnsure: false } },

{
test: /\.js$/,
exclude: [/[/\\\\]elm-stuff[/\\\\]/, /[/\\\\]node_modules[/\\\\]/],
Expand Down Expand Up @@ -169,8 +188,9 @@ module.exports = {
// "style" loader turns CSS into JS modules that inject <style> tags.
// In production, we use a plugin to extract that CSS to a file, but
// in development "style" loader enables hot editing of CSS.
// By default we support CSS Modules with the extension .module.css
{
test: /\.css$/,
test: /\.css/,
use: [
require.resolve('style-loader'),
{
Expand All @@ -180,17 +200,18 @@ module.exports = {
}
},
{
// Options for PostCSS as we reference these options twice
// Adds vendor prefixing based on your specified browser support in
// package.json
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9'
]
flexbox: 'no-2009'
})
]
}
Expand All @@ -217,20 +238,26 @@ module.exports = {
}
]
},

plugins: [
new DefinePlugin(env.stringified),

new InterpolateHtmlPlugin(env.raw),

// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml
}),

new HotModuleReplacementPlugin(),

new NamedModulesPlugin()
// Makes some environment variables available in index.html.
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
// In development, this will be an empty string.
new InterpolateHtmlPlugin(env.raw),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
new webpack.DefinePlugin(env.stringified),
// This is necessary to emit hot updates (currently CSS only):
new webpack.HotModuleReplacementPlugin(),
// Watcher doesn't work well if you mistype casing in a path so we use
// a plugin that prints an error when you attempt to do this.
// See https://github.com/facebook/create-react-app/issues/240
new CaseSensitivePathsPlugin()
],

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