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 ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin
const AssetsPlugin = require('assets-webpack-plugin') const AssetsPlugin = require('assets-webpack-plugin')
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin') 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') const WebpackNotifierPlugin = require('webpack-notifier')
/* /*
@ -30,12 +32,6 @@ module.exports = function (options) {
var isProd = options.env === 'production' var isProd = options.env === 'production'
return { return {
/*
* Static metadata for index.html
*
* See: (custom attribute)
*/
metadata: METADATA,
/* /*
* Cache generated modules and chunks to improve performance for multiple incremental builds. * 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 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
*/ */
extensions: [ '', '.ts', '.js', '.scss' ], extensions: [ '.ts', '.js', '.json', '.scss' ],
// Make sure root is src modules: [helpers.root('src'), 'node_modules']
root: helpers.root('src'),
// remove other default values
modulesDirectories: [ 'node_modules' ]
},
output: {
publicPath: '/client/'
}, },
/* /*
@ -88,33 +76,8 @@ module.exports = function (options) {
* See: http://webpack.github.io/docs/configuration.html#module * See: http://webpack.github.io/docs/configuration.html#module
*/ */
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')]
}
],
/* rules: [
* 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: [
/* /*
* Typescript loader support for .ts and Angular 2 async routes via .async.ts * 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. * Add additional plugins to the compiler.
* *
@ -205,7 +164,7 @@ module.exports = function (options) {
* *
* See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
* See: https://github.com/angular/angular/issues/11580 * See: https://github.com/angular/angular/issues/11580
*/ */
new ContextReplacementPlugin( new ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows // The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
@ -241,10 +200,36 @@ module.exports = function (options) {
*/ */
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: 'src/index.html', 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 * See: https://webpack.github.io/docs/configuration.html#node
*/ */
node: { node: {
global: 'window', global: 'true',
crypto: 'empty', crypto: 'empty',
fs: 'empty', process: true,
events: true,
module: false, module: false,
clearImmediate: false, clearImmediate: false,
setImmediate: 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 DefinePlugin = require('webpack/lib/DefinePlugin')
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin') const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin')
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
/** /**
* Webpack Constants * Webpack Constants
@ -30,66 +31,53 @@ const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
module.exports = function (env) { module.exports = function (env) {
return webpackMerge(commonConfig({env: ENV}), { return webpackMerge(commonConfig({env: ENV}), {
/** /**
* Merged metadata from webpack.common.js for index.html * Developer tool to enhance debugging
* *
* See: (custom attribute) * See: http://webpack.github.io/docs/configuration.html#devtool
*/ * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
metadata: METADATA, */
/**
* Switch loaders to debug mode.
*
* See: http://webpack.github.io/docs/configuration.html#debug
*/
debug: true,
/**
* Developer tool to enhance debugging
*
* See: http://webpack.github.io/docs/configuration.html#devtool
* See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
*/
devtool: 'cheap-module-source-map', devtool: 'cheap-module-source-map',
/** /**
* Options affecting the output of the compilation. * Options affecting the output of the compilation.
* *
* See: http://webpack.github.io/docs/configuration.html#output * See: http://webpack.github.io/docs/configuration.html#output
*/ */
output: { output: {
/** /**
* The output directory as absolute path (required). * The output directory as absolute path (required).
* *
* See: http://webpack.github.io/docs/configuration.html#output-path * See: http://webpack.github.io/docs/configuration.html#output-path
*/ */
path: helpers.root('dist'), path: helpers.root('dist'),
/** /**
* Specifies the name of each output file on disk. * Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here! * IMPORTANT: You must not specify an absolute path here!
* *
* See: http://webpack.github.io/docs/configuration.html#output-filename * See: http://webpack.github.io/docs/configuration.html#output-filename
*/ */
filename: '[name].bundle.js', filename: '[name].bundle.js',
/** /**
* The filename of the SourceMaps for the JavaScript files. * The filename of the SourceMaps for the JavaScript files.
* They are inside the output.path directory. * They are inside the output.path directory.
* *
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
*/ */
sourceMapFilename: '[name].map', sourceMapFilename: '[name].map',
/** The filename of non-entry chunks as relative path /** The filename of non-entry chunks as relative path
* inside the output.path directory. * inside the output.path directory.
* *
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
*/ */
chunkFilename: '[id].chunk.js', chunkFilename: '[id].chunk.js',
library: 'ac_[name]', library: 'ac_[name]',
libraryTarget: 'var' libraryTarget: 'var',
publicPath: '/client/'
}, },
externals: { externals: {
@ -99,14 +87,14 @@ module.exports = function (env) {
plugins: [ plugins: [
/** /**
* Plugin: DefinePlugin * Plugin: DefinePlugin
* Description: Define free variables. * Description: Define free variables.
* Useful for having development builds with debug logging or adding global constants. * Useful for having development builds with debug logging or adding global constants.
* *
* Environment helpers * Environment helpers
* *
* See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
*/ */
// NOTE: when adding more properties, make sure you include them in custom-typings.d.ts // NOTE: when adding more properties, make sure you include them in custom-typings.d.ts
new DefinePlugin({ new DefinePlugin({
'ENV': JSON.stringify(METADATA.ENV), 'ENV': JSON.stringify(METADATA.ENV),
@ -118,21 +106,56 @@ 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
* Description: An extensible linter for the TypeScript language.
*
* See: https://github.com/wbuchwalter/tslint-loader
*/
tslint: {
emitErrors: false,
failOnHint: false,
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')
}
}
})
], ],
/** /**
* Static analysis linter for TypeScript advanced options configuration * Webpack Development Server configuration
* Description: An extensible linter for the TypeScript language. * Description: The webpack-dev-server is a little node.js Express server.
* * The server emits information about the compilation state to the client,
* See: https://github.com/wbuchwalter/tslint-loader * which reacts to those events.
*/ *
tslint: { * See: https://webpack.github.io/docs/webpack-dev-server.html
emitErrors: false, */
failOnHint: false,
resourcePath: 'src'
},
devServer: { devServer: {
port: METADATA.port, port: METADATA.port,
host: METADATA.host, host: METADATA.host,
@ -145,13 +168,13 @@ module.exports = function (env) {
}, },
/* /*
* Include polyfills or mocks for various node stuff * Include polyfills or mocks for various node stuff
* Description: Node configuration * Description: Node configuration
* *
* See: https://webpack.github.io/docs/configuration.html#node * See: https://webpack.github.io/docs/configuration.html#node
*/ */
node: { node: {
global: 'window', global: true,
crypto: 'empty', crypto: 'empty',
process: true, process: true,
module: false, 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 ProvidePlugin = require('webpack/lib/ProvidePlugin')
const DefinePlugin = require('webpack/lib/DefinePlugin') const DefinePlugin = require('webpack/lib/DefinePlugin')
const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
// const IgnorePlugin = require('webpack/lib/IgnorePlugin') // const IgnorePlugin = require('webpack/lib/IgnorePlugin')
// const DedupePlugin = require('webpack/lib/optimize/DedupePlugin') // const DedupePlugin = require('webpack/lib/optimize/DedupePlugin')
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin') const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
@ -33,57 +34,52 @@ const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
module.exports = function (env) { module.exports = function (env) {
return webpackMerge(commonConfig({env: ENV}), { return webpackMerge(commonConfig({env: ENV}), {
/** /**
* Switch loaders to debug mode. * Developer tool to enhance debugging
* *
* See: http://webpack.github.io/docs/configuration.html#debug * See: http://webpack.github.io/docs/configuration.html#devtool
*/ * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
debug: false, */
/**
* Developer tool to enhance debugging
*
* See: http://webpack.github.io/docs/configuration.html#devtool
* See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
*/
devtool: 'source-map', devtool: 'source-map',
/** /**
* Options affecting the output of the compilation. * Options affecting the output of the compilation.
* *
* See: http://webpack.github.io/docs/configuration.html#output * See: http://webpack.github.io/docs/configuration.html#output
*/ */
output: { output: {
/** /**
* The output directory as absolute path (required). * The output directory as absolute path (required).
* *
* See: http://webpack.github.io/docs/configuration.html#output-path * See: http://webpack.github.io/docs/configuration.html#output-path
*/ */
path: helpers.root('dist'), path: helpers.root('dist'),
/** /**
* Specifies the name of each output file on disk. * Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here! * IMPORTANT: You must not specify an absolute path here!
* *
* See: http://webpack.github.io/docs/configuration.html#output-filename * See: http://webpack.github.io/docs/configuration.html#output-filename
*/ */
filename: '[name].[chunkhash].bundle.js', filename: '[name].[chunkhash].bundle.js',
/** /**
* The filename of the SourceMaps for the JavaScript files. * The filename of the SourceMaps for the JavaScript files.
* They are inside the output.path directory. * They are inside the output.path directory.
* *
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
*/ */
sourceMapFilename: '[name].[chunkhash].bundle.map', sourceMapFilename: '[name].[chunkhash].bundle.map',
/** /**
* The filename of non-entry chunks as relative path * The filename of non-entry chunks as relative path
* inside the output.path directory. * inside the output.path directory.
* *
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
*/ */
chunkFilename: '[id].[chunkhash].chunk.js' chunkFilename: '[id].[chunkhash].chunk.js',
publicPath: '/client/'
}, },
externals: { externals: {
@ -134,14 +130,13 @@ module.exports = function (env) {
'HMR': METADATA.HMR 'HMR': METADATA.HMR
} }
}), }),
/**
/** * Plugin: UglifyJsPlugin
* Plugin: UglifyJsPlugin * Description: Minimize all JavaScript output of chunks.
* Description: Minimize all JavaScript output of chunks. * Loaders are switched into minimizing mode.
* Loaders are switched into minimizing mode. *
* * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
* See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin */
*/
// NOTE: To debug prod builds uncomment //debug lines and comment //prod lines // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
new UglifyJsPlugin({ new UglifyJsPlugin({
// beautify: true, //debug // beautify: true, //debug
@ -159,68 +154,101 @@ module.exports = function (env) {
// comments: true, //debug // comments: true, //debug
beautify: false, // prod beautify: false, // prod
mangle: { screw_ie8: true, keep_fnames: true }, // prod mangle: {
compress: { screw_ie8: true }, // prod screw_ie8: true,
keep_fnames: true
}, // prod
compress: {
screw_ie8: true
}, // prod
comments: false // prod comments: false // prod
}), }),
new NormalModuleReplacementPlugin( new NormalModuleReplacementPlugin(
/angular2-hmr/, /angular2-hmr/,
helpers.root('config/modules/angular2-hmr-prod.js') helpers.root('config/modules/angular2-hmr-prod.js')
) ),
/** /**
* Plugin: CompressionPlugin * Plugin: IgnorePlugin
* Description: Prepares compressed versions of assets to serve * Description: Dont generate modules for requests matching the provided RegExp.
* them with Content-Encoding *
* * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
* See: https://github.com/webpack/compression-webpack-plugin */
*/
// new IgnorePlugin(/angular2-hmr/),
/**
* Plugin: CompressionPlugin
* Description: Prepares compressed versions of assets to serve
* them with Content-Encoding
*
* See: https://github.com/webpack/compression-webpack-plugin
*/
// install compression-webpack-plugin
// new CompressionPlugin({ // new CompressionPlugin({
// regExp: /\.css$|\.html$|\.js$|\.map$/, // regExp: /\.css$|\.html$|\.js$|\.map$/,
// threshold: 2 * 1024 // 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
* Description: An extensible linter for the TypeScript language.
*
* See: https://github.com/wbuchwalter/tslint-loader
*/
tslint: {
emitErrors: true,
failOnHint: true,
resourcePath: 'src'
},
/**
* Html loader advanced options
*
* See: https://github.com/webpack/html-loader#advanced-options
*/
// TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
htmlLoader: {
minimize: true,
removeAttributeQuotes: false,
caseSensitive: true,
customAttrSurround: [
[/#/, /(?:)/],
[/\*/, /(?:)/],
[/\[?\(?/, /(?:)/]
],
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')
}
}
})
], ],
/**
* Static analysis linter for TypeScript advanced options configuration
* Description: An extensible linter for the TypeScript language.
*
* See: https://github.com/wbuchwalter/tslint-loader
*/
tslint: {
emitErrors: true,
failOnHint: true,
resourcePath: 'src'
},
/**
* Html loader advanced options
*
* See: https://github.com/webpack/html-loader#advanced-options
*/
// TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
htmlLoader: {
minimize: true,
removeAttributeQuotes: false,
caseSensitive: true,
customAttrSurround: [
[/#/, /(?:)/],
[/\*/, /(?:)/],
[/\[?\(?/, /(?:)/]
],
customAttrAssign: [/\)?\]?=/]
},
/* /*
* Include polyfills or mocks for various node stuff * Include polyfills or mocks for various node stuff
* Description: Node configuration * Description: Node configuration
* *
* See: https://webpack.github.io/docs/configuration.html#node * See: https://webpack.github.io/docs/configuration.html#node
*/ */
node: { node: {
global: 'window', global: true,
crypto: 'empty', crypto: 'empty',
process: false, process: false,
module: false, module: false,

View File

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

View File

@ -1,9 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<base href="/"> <title><%= htmlWebpackPlugin.options.title %></title>
<title>PeerTube</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <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 --> <!-- 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> <script src="/client/assets/webtorrent/webtorrent.min.js"></script>
<!-- base url -->
<base href="<%= htmlWebpackPlugin.options.metadata.baseUrl %>">
</head> </head>
<!-- 3. Display the application --> <!-- 3. Display the application -->
<body> <body>
<my-app> <my-app>
</my-app> </my-app>
</body> </body>
</html> </html>