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')
/*
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.
*
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
*/
- extensions: [ '', '.ts', '.js', '.scss' ],
-
- // Make sure root is src
- root: helpers.root('src'),
+ extensions: [ '.ts', '.js', '.json', '.scss' ],
- // remove other default values
- modulesDirectories: [ 'node_modules' ]
- },
-
- output: {
- publicPath: '/client/'
+ modules: [helpers.root('src'), 'node_modules']
},
/*
* 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
},
- sassLoader: {
- precision: 10
- },
-
/*
* Add additional plugins to the compiler.
*
*
* See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
* See: https://github.com/angular/angular/issues/11580
- */
+ */
new ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
*/
new HtmlWebpackPlugin({
template: 'src/index.html',
- chunksSortMode: 'dependency'
+ title: METADATA.title,
+ chunksSortMode: 'dependency',
+ metadata: METADATA
+ }),
+
+ /*
+ * 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 })
+ new WebpackNotifierPlugin({ alwaysNotify: true }),
+
+ /**
+ * Plugin LoaderOptionsPlugin (experimental)
+ *
+ * See: https://gist.github.com/sokra/27b24881210b56bbaff7
+ */
+ new LoaderOptionsPlugin({
+ options: {
+ sassLoader: {
+ precision: 10
+ }
+ }
+ })
],
/*
* 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
*/
const DefinePlugin = require('webpack/lib/DefinePlugin')
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin')
+const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
/**
* Webpack Constants
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
- *
- * See: http://webpack.github.io/docs/configuration.html#devtool
- * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
- */
+ * 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',
/**
- * Options affecting the output of the compilation.
- *
- * See: http://webpack.github.io/docs/configuration.html#output
- */
+ * Options affecting the output of the compilation.
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output
+ */
output: {
/**
- * The output directory as absolute path (required).
- *
- * See: http://webpack.github.io/docs/configuration.html#output-path
- */
+ * The output directory as absolute path (required).
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-path
+ */
path: helpers.root('dist'),
/**
- * Specifies the name of each output file on disk.
- * IMPORTANT: You must not specify an absolute path here!
- *
- * See: http://webpack.github.io/docs/configuration.html#output-filename
- */
+ * Specifies the name of each output file on disk.
+ * IMPORTANT: You must not specify an absolute path here!
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-filename
+ */
filename: '[name].bundle.js',
/**
- * The filename of the SourceMaps for the JavaScript files.
- * They are inside the output.path directory.
- *
- * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
- */
+ * The filename of the SourceMaps for the JavaScript files.
+ * They are inside the output.path directory.
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
+ */
sourceMapFilename: '[name].map',
/** The filename of non-entry chunks as relative path
- * inside the output.path directory.
- *
- * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
- */
+ * inside the output.path directory.
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
+ */
chunkFilename: '[id].chunk.js',
library: 'ac_[name]',
- libraryTarget: 'var'
+ libraryTarget: 'var',
+ publicPath: '/client/'
},
externals: {
plugins: [
/**
- * Plugin: DefinePlugin
- * Description: Define free variables.
- * Useful for having development builds with debug logging or adding global constants.
- *
- * Environment helpers
- *
- * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
- */
+ * Plugin: DefinePlugin
+ * Description: Define free variables.
+ * Useful for having development builds with debug logging or adding global constants.
+ *
+ * Environment helpers
+ *
+ * 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
new DefinePlugin({
'ENV': JSON.stringify(METADATA.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
- * Description: An extensible linter for the TypeScript language.
- *
- * See: https://github.com/wbuchwalter/tslint-loader
- */
- tslint: {
- emitErrors: false,
- failOnHint: false,
- resourcePath: 'src'
- },
-
+ * 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,
},
/*
- * Include polyfills or mocks for various node stuff
- * Description: Node configuration
- *
- * See: https://webpack.github.io/docs/configuration.html#node
- */
+ * Include polyfills or mocks for various node stuff
+ * Description: Node configuration
+ *
+ * See: https://webpack.github.io/docs/configuration.html#node
+ */
node: {
- global: 'window',
+ global: true,
crypto: 'empty',
process: true,
module: false,
// 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')
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
- *
- * See: http://webpack.github.io/docs/configuration.html#devtool
- * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
- */
+ * 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',
/**
- * Options affecting the output of the compilation.
- *
- * See: http://webpack.github.io/docs/configuration.html#output
- */
+ * Options affecting the output of the compilation.
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output
+ */
output: {
+
/**
- * The output directory as absolute path (required).
- *
- * See: http://webpack.github.io/docs/configuration.html#output-path
- */
+ * The output directory as absolute path (required).
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-path
+ */
path: helpers.root('dist'),
/**
- * Specifies the name of each output file on disk.
- * IMPORTANT: You must not specify an absolute path here!
- *
- * See: http://webpack.github.io/docs/configuration.html#output-filename
- */
+ * Specifies the name of each output file on disk.
+ * IMPORTANT: You must not specify an absolute path here!
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-filename
+ */
filename: '[name].[chunkhash].bundle.js',
/**
- * The filename of the SourceMaps for the JavaScript files.
- * They are inside the output.path directory.
- *
- * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
- */
+ * The filename of the SourceMaps for the JavaScript files.
+ * They are inside the output.path directory.
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
+ */
sourceMapFilename: '[name].[chunkhash].bundle.map',
/**
- * The filename of non-entry chunks as relative path
- * inside the output.path directory.
- *
- * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
- */
- chunkFilename: '[id].[chunkhash].chunk.js'
+ * The filename of non-entry chunks as relative path
+ * inside the output.path directory.
+ *
+ * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
+ */
+ chunkFilename: '[id].[chunkhash].chunk.js',
+ publicPath: '/client/'
},
externals: {
'HMR': METADATA.HMR
}
}),
-
- /**
- * Plugin: UglifyJsPlugin
- * Description: Minimize all JavaScript output of chunks.
- * Loaders are switched into minimizing mode.
- *
- * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
- */
+/**
+ * Plugin: UglifyJsPlugin
+ * Description: Minimize all JavaScript output of chunks.
+ * Loaders are switched into minimizing mode.
+ *
+ * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
+ */
// NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
new UglifyJsPlugin({
// beautify: true, //debug
// 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: CompressionPlugin
- * Description: Prepares compressed versions of assets to serve
- * them with Content-Encoding
- *
- * See: https://github.com/webpack/compression-webpack-plugin
- */
+ * Plugin: IgnorePlugin
+ * Description: Don’t 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
+ * 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({
// 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
- * Description: An extensible linter for the TypeScript language.
- *
- * See: https://github.com/wbuchwalter/tslint-loader
- */
- tslint: {
- emitErrors: true,
- failOnHint: true,
- resourcePath: 'src'
- },
+ /**
+ * 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: [/\)?\]?=/]
- },
+ /**
+ * 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')
+ }
+ }
+ })
+ ],
/*
- * Include polyfills or mocks for various node stuff
- * Description: Node configuration
- *
- * See: https://webpack.github.io/docs/configuration.html#node
- */
+ * Include polyfills or mocks for various node stuff
+ * Description: Node configuration
+ *
+ * See: https://webpack.github.io/docs/configuration.html#node
+ */
node: {
- global: 'window',
+ global: true,
crypto: 'empty',
process: false,
module: false,
"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",
"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",
<!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">
<!-- 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>