Update to webpack beta 25

pull/24/head
Chocobozzz 2016-11-04 12:50:01 +01:00
parent d05eb4ed10
commit 4d19d2f10b
5 changed files with 252 additions and 213 deletions

View File

@ -10,6 +10,8 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin
const AssetsPlugin = require('assets-webpack-plugin')
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
const WebpackNotifierPlugin = require('webpack-notifier')
/*
@ -30,12 +32,6 @@ module.exports = function (options) {
var isProd = options.env === 'production'
return {
/*
* Static metadata for index.html
*
* See: (custom attribute)
*/
metadata: METADATA,
/*
* Cache generated modules and chunks to improve performance for multiple incremental builds.
@ -69,17 +65,9 @@ module.exports = function (options) {
*
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
*/
extensions: [ '', '.ts', '.js', '.scss' ],
extensions: [ '.ts', '.js', '.json', '.scss' ],
// Make sure root is src
root: helpers.root('src'),
// remove other default values
modulesDirectories: [ 'node_modules' ]
},
output: {
publicPath: '/client/'
modules: [helpers.root('src'), 'node_modules']
},
/*
@ -88,33 +76,8 @@ module.exports = function (options) {
* See: http://webpack.github.io/docs/configuration.html#module
*/
module: {
/*
* An array of applied pre and post loaders.
*
* See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
*/
preLoaders: [
{
test: /\.ts$/,
loader: 'string-replace-loader',
query: {
search: '(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import\\((.+)\\)',
replace: '$1.import($3).then(mod => (mod.__esModule && mod.default) ? mod.default : mod)',
flags: 'g'
},
include: [helpers.root('src')]
}
],
/*
* An array of automatically applied loaders.
*
* IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
* This means they are not resolved relative to the configuration file.
*
* See: http://webpack.github.io/docs/configuration.html#module-loaders
*/
loaders: [
rules: [
/*
* Typescript loader support for .ts and Angular 2 async routes via .async.ts
@ -163,10 +126,6 @@ module.exports = function (options) {
},
sassLoader: {
precision: 10
},
/*
* Add additional plugins to the compiler.
*
@ -241,10 +200,36 @@ module.exports = function (options) {
*/
new HtmlWebpackPlugin({
template: 'src/index.html',
chunksSortMode: 'dependency'
title: METADATA.title,
chunksSortMode: 'dependency',
metadata: METADATA
}),
new WebpackNotifierPlugin({ alwaysNotify: true })
/*
* Plugin: ScriptExtHtmlWebpackPlugin
* Description: Enhances html-webpack-plugin functionality
* with different deployment options for your scripts including:
*
* See: https://github.com/numical/script-ext-html-webpack-plugin
*/
new ScriptExtHtmlWebpackPlugin({
defaultAttribute: 'defer'
}),
new WebpackNotifierPlugin({ alwaysNotify: true }),
/**
* Plugin LoaderOptionsPlugin (experimental)
*
* See: https://gist.github.com/sokra/27b24881210b56bbaff7
*/
new LoaderOptionsPlugin({
options: {
sassLoader: {
precision: 10
}
}
})
],
/*
@ -254,10 +239,9 @@ module.exports = function (options) {
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: 'window',
global: 'true',
crypto: 'empty',
fs: 'empty',
events: true,
process: true,
module: false,
clearImmediate: false,
setImmediate: false

View File

@ -7,6 +7,7 @@ const commonConfig = require('./webpack.common.js') // the settings that are com
*/
const DefinePlugin = require('webpack/lib/DefinePlugin')
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin')
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
/**
* Webpack Constants
@ -29,20 +30,6 @@ const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
*/
module.exports = function (env) {
return webpackMerge(commonConfig({env: ENV}), {
/**
* Merged metadata from webpack.common.js for index.html
*
* See: (custom attribute)
*/
metadata: METADATA,
/**
* Switch loaders to debug mode.
*
* See: http://webpack.github.io/docs/configuration.html#debug
*/
debug: true,
/**
* Developer tool to enhance debugging
*
@ -88,8 +75,9 @@ module.exports = function (env) {
chunkFilename: '[id].chunk.js',
library: 'ac_[name]',
libraryTarget: 'var'
libraryTarget: 'var',
publicPath: '/client/'
},
externals: {
@ -118,8 +106,22 @@ module.exports = function (env) {
}
}),
new NamedModulesPlugin()
],
/**
* Plugin: NamedModulesPlugin (experimental)
* Description: Uses file names as module name.
*
* See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb
*/
new NamedModulesPlugin(),
/**
* Plugin LoaderOptionsPlugin (experimental)
*
* See: https://gist.github.com/sokra/27b24881210b56bbaff7
*/
new LoaderOptionsPlugin({
debug: true,
options: {
/**
* Static analysis linter for TypeScript advanced options configuration
@ -133,6 +135,27 @@ module.exports = function (env) {
resourcePath: 'src'
},
// FIXME: Remove
// https://github.com/bholloway/resolve-url-loader/issues/36
// https://github.com/jtangelder/sass-loader/issues/289
context: __dirname,
output: {
path: helpers.root('dist')
}
}
})
],
/**
* Webpack Development Server configuration
* Description: The webpack-dev-server is a little node.js Express server.
* The server emits information about the compilation state to the client,
* which reacts to those events.
*
* See: https://webpack.github.io/docs/webpack-dev-server.html
*/
devServer: {
port: METADATA.port,
host: METADATA.host,
@ -151,7 +174,7 @@ module.exports = function (env) {
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: 'window',
global: true,
crypto: 'empty',
process: true,
module: false,

View File

@ -12,6 +12,7 @@ const commonConfig = require('./webpack.common.js') // the settings that are com
// const ProvidePlugin = require('webpack/lib/ProvidePlugin')
const DefinePlugin = require('webpack/lib/DefinePlugin')
const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
// const IgnorePlugin = require('webpack/lib/IgnorePlugin')
// const DedupePlugin = require('webpack/lib/optimize/DedupePlugin')
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
@ -32,13 +33,6 @@ const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
module.exports = function (env) {
return webpackMerge(commonConfig({env: ENV}), {
/**
* Switch loaders to debug mode.
*
* See: http://webpack.github.io/docs/configuration.html#debug
*/
debug: false,
/**
* Developer tool to enhance debugging
*
@ -53,6 +47,7 @@ module.exports = function (env) {
* See: http://webpack.github.io/docs/configuration.html#output
*/
output: {
/**
* The output directory as absolute path (required).
*
@ -82,8 +77,9 @@ module.exports = function (env) {
*
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
*/
chunkFilename: '[id].[chunkhash].chunk.js'
chunkFilename: '[id].[chunkhash].chunk.js',
publicPath: '/client/'
},
externals: {
@ -134,8 +130,7 @@ module.exports = function (env) {
'HMR': METADATA.HMR
}
}),
/**
/**
* Plugin: UglifyJsPlugin
* Description: Minimize all JavaScript output of chunks.
* Loaders are switched into minimizing mode.
@ -159,15 +154,29 @@ module.exports = function (env) {
// comments: true, //debug
beautify: false, // prod
mangle: { screw_ie8: true, keep_fnames: true }, // prod
compress: { screw_ie8: true }, // prod
mangle: {
screw_ie8: true,
keep_fnames: true
}, // prod
compress: {
screw_ie8: true
}, // prod
comments: false // prod
}),
new NormalModuleReplacementPlugin(
/angular2-hmr/,
helpers.root('config/modules/angular2-hmr-prod.js')
)
),
/**
* Plugin: IgnorePlugin
* Description: Dont generate modules for requests matching the provided RegExp.
*
* See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
*/
// new IgnorePlugin(/angular2-hmr/),
/**
* Plugin: CompressionPlugin
@ -176,12 +185,20 @@ module.exports = function (env) {
*
* See: https://github.com/webpack/compression-webpack-plugin
*/
// install compression-webpack-plugin
// new CompressionPlugin({
// regExp: /\.css$|\.html$|\.js$|\.map$/,
// threshold: 2 * 1024
// })
],
/**
* Plugin LoaderOptionsPlugin (experimental)
*
* See: https://gist.github.com/sokra/27b24881210b56bbaff7
*/
new LoaderOptionsPlugin({
debug: false,
options: {
/**
* Static analysis linter for TypeScript advanced options configuration
@ -213,6 +230,17 @@ module.exports = function (env) {
customAttrAssign: [/\)?\]?=/]
},
// FIXME: Remove
// https://github.com/bholloway/resolve-url-loader/issues/36
// https://github.com/jtangelder/sass-loader/issues/289
context: __dirname,
output: {
path: helpers.root('dist')
}
}
})
],
/*
* Include polyfills or mocks for various node stuff
* Description: Node configuration
@ -220,7 +248,7 @@ module.exports = function (env) {
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: 'window',
global: true,
crypto: 'empty',
process: false,
module: false,

View File

@ -60,6 +60,7 @@
"resolve-url-loader": "^1.6.0",
"rxjs": "^5.0.0-rc.1",
"sass-loader": "^4.0.2",
"script-ext-html-webpack-plugin": "^1.3.2",
"source-map-loader": "^0.1.5",
"string-replace-loader": "^1.0.3",
"style-loader": "^0.13.1",
@ -68,7 +69,7 @@
"tslint-loader": "^2.1.4",
"typescript": "^2.0.0",
"url-loader": "^0.5.7",
"webpack": "2.1.0-beta.22",
"webpack": "2.1.0-beta.25",
"webpack-md5-hash": "0.0.5",
"webpack-merge": "^0.15.0",
"webpack-notifier": "^1.3.0",

View File

@ -1,9 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<base href="/">
<title>PeerTube</title>
<title><%= htmlWebpackPlugin.options.title %></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@ -12,11 +10,16 @@
<!-- TODO: bundle it with webpack when https://github.com/webpack/webpack/pull/1931 will be merged -->
<script src="/client/assets/webtorrent/webtorrent.min.js"></script>
<!-- base url -->
<base href="<%= htmlWebpackPlugin.options.metadata.baseUrl %>">
</head>
<!-- 3. Display the application -->
<body>
<my-app>
</my-app>
</body>
</html>