-
Notifications
You must be signed in to change notification settings - Fork 603
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
Upgrade app-npm example to latest Webpack version #794
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"cldr-data": ">=25", | ||
"cldr-data": "^32.0.0", | ||
"globalize": "^1.3.0", | ||
"globalize-webpack-plugin": "0.4.x", | ||
"html-webpack-plugin": "^1.1.0", | ||
"globalize-webpack-plugin": "^2.0.1", | ||
"html-webpack-plugin": "^2.30.1", | ||
"iana-tz-data": "^2017.1.0", | ||
"nopt": "^3.0.3", | ||
"webpack": "^1.9.0", | ||
"webpack-dev-server": "^1.9.0" | ||
"webpack": "^3.6.0", | ||
"webpack-dev-server": "^2.9.1" | ||
}, | ||
"scripts": { | ||
"start": "webpack-dev-server --config webpack-config.js --hot --progress --colors --inline", | ||
"build": "webpack --production --config webpack-config.js" | ||
"build": "NODE_ENV=production webpack --config webpack-config.js" | ||
}, | ||
"cldr-data-urls-filter": "(core|dates|numbers|units)" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
var path = require('path'); | ||
var webpack = require( "webpack" ); | ||
var CommonsChunkPlugin = require( "webpack/lib/optimize/CommonsChunkPlugin" ); | ||
var HtmlWebpackPlugin = require( "html-webpack-plugin" ); | ||
var GlobalizePlugin = require( "globalize-webpack-plugin" ); | ||
var nopt = require( "nopt" ); | ||
|
||
var options = nopt({ | ||
production: Boolean | ||
}); | ||
var options = { | ||
production: (process.env.NODE_ENV === "production"), | ||
chunks: [ | ||
"vendor", | ||
"globalize-compiled-data-en", | ||
"main" | ||
] | ||
}; | ||
|
||
module.exports = { | ||
entry: options.production ? { | ||
|
@@ -22,19 +27,33 @@ module.exports = { | |
"globalize/dist/globalize-runtime/unit" | ||
] | ||
} : "./app/index.js", | ||
debug: !options.production, | ||
output: { | ||
path: options.production ? "./dist" : "./tmp", | ||
path: path.resolve(__dirname, options.production ? "./dist" : "./tmp"), | ||
publicPath: options.production ? "" : "http://localhost:8080/", | ||
filename: options.production ? "app.[hash].js" : "app.js" | ||
filename: options.production ? "[name].[chunkhash].js" : "app.js" | ||
}, | ||
resolve: { | ||
extensions: [ "", ".js" ] | ||
extensions: [ "*", ".js" ] | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
production: options.production, | ||
template: "./index-template.html" | ||
template: "./index-template.html", | ||
|
||
// FIXME: These 2 options are a workaround to insert i18n/[locale].[hash].js files at right spot just before main.[hash].js | ||
chunks: options.chunks, | ||
chunksSortMode: function (chunk1, chunk2) { | ||
const order1 = options.chunks.indexOf(chunk1.names[0]); | ||
const order2 = options.chunks.indexOf(chunk2.names[0]); | ||
|
||
if (order1 > order2) { | ||
return 1; | ||
} | ||
if (order1 < order2) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need to be fixed in the webpack plugin instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is here as a better solution than doing something similar in the template, right? Although, it would add all the locales There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your description has a good summary about this, thanks.
Yeap, this shouldn't happen (i.e., it shouldn't be necessary to keep en too). The test I'd make was to keep template as basic and simple as it was, i.e., to make minimal updates in this example necessary to support webpack 2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope the ordering issue can be solved within the plugin without the need to specify the chunks and ordering here. |
||
}), | ||
new GlobalizePlugin({ | ||
production: options.production, | ||
|
@@ -44,8 +63,7 @@ module.exports = { | |
output: "i18n/[locale].[hash].js" | ||
}) | ||
].concat( options.production ? [ | ||
new webpack.optimize.DedupePlugin(), | ||
new CommonsChunkPlugin( "vendor", "vendor.[hash].js" ), | ||
new CommonsChunkPlugin("vendor"), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { | ||
warnings: false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to define these? This should be created automatically by the plugin, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think the plugin should take care of including the chunks in the right order - I just don't know how to do it