1
0
Fork 0

Update to webpack beta 25

This commit is contained in:
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.
* *
@ -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
@ -29,20 +30,6 @@ 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
*
* 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 * Developer tool to enhance debugging
* *
@ -88,8 +75,9 @@ module.exports = function (env) {
chunkFilename: '[id].chunk.js', chunkFilename: '[id].chunk.js',
library: 'ac_[name]', library: 'ac_[name]',
libraryTarget: 'var' libraryTarget: 'var',
publicPath: '/client/'
}, },
externals: { 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 * Static analysis linter for TypeScript advanced options configuration
@ -133,6 +135,27 @@ module.exports = function (env) {
resourcePath: 'src' 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: { devServer: {
port: METADATA.port, port: METADATA.port,
host: METADATA.host, host: METADATA.host,
@ -151,7 +174,7 @@ module.exports = function (env) {
* 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')
@ -32,13 +33,6 @@ 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.
*
* See: http://webpack.github.io/docs/configuration.html#debug
*/
debug: false,
/** /**
* Developer tool to enhance debugging * Developer tool to enhance debugging
* *
@ -53,6 +47,7 @@ module.exports = function (env) {
* 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).
* *
@ -82,8 +77,9 @@ module.exports = function (env) {
* *
* 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,8 +130,7 @@ 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.
@ -159,15 +154,29 @@ 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: 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 * Plugin: CompressionPlugin
@ -176,12 +185,20 @@ module.exports = function (env) {
* *
* See: https://github.com/webpack/compression-webpack-plugin * 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 * Static analysis linter for TypeScript advanced options configuration
@ -213,6 +230,17 @@ module.exports = function (env) {
customAttrAssign: [/\)?\]?=/] 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 * Include polyfills or mocks for various node stuff
* Description: Node configuration * Description: Node configuration
@ -220,7 +248,7 @@ module.exports = function (env) {
* 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>