2017-07-23 07:49:52 -05:00
|
|
|
const helpers = require('./helpers')
|
2018-06-07 09:50:33 -05:00
|
|
|
const path = require('path')
|
2017-07-23 07:49:52 -05:00
|
|
|
|
|
|
|
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
2017-12-12 04:38:02 -06:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
2017-07-23 07:49:52 -05:00
|
|
|
const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
|
2017-12-12 04:38:02 -06:00
|
|
|
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
|
2017-07-23 07:49:52 -05:00
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
|
|
|
const PurifyCSSPlugin = require('purifycss-webpack')
|
|
|
|
|
2017-12-12 04:38:02 -06:00
|
|
|
module.exports = function () {
|
|
|
|
const isProd = process.env.NODE_ENV === 'production'
|
2017-07-23 07:49:52 -05:00
|
|
|
|
|
|
|
const configuration = {
|
|
|
|
entry: {
|
2018-07-10 10:47:56 -05:00
|
|
|
'video-embed': './src/standalone/videos/embed.ts',
|
|
|
|
'player': './src/standalone/player/player.ts',
|
|
|
|
'test-embed': './src/standalone/videos/test-embed.ts'
|
2017-07-23 07:49:52 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
/*
|
|
|
|
* An array of extensions that should be used to resolve modules.
|
|
|
|
*
|
|
|
|
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
|
|
|
|
*/
|
|
|
|
extensions: [ '.ts', '.js', '.json', '.scss' ],
|
|
|
|
|
2018-06-07 09:50:33 -05:00
|
|
|
modules: [ helpers.root('src'), helpers.root('node_modules') ],
|
|
|
|
|
|
|
|
alias: {
|
|
|
|
'video.js$': path.resolve('node_modules/video.js/dist/alt/video.core.js')
|
|
|
|
}
|
2017-07-23 07:49:52 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
|
|
|
path: helpers.root('dist/standalone/videos'),
|
|
|
|
filename: '[name].[hash].bundle.js',
|
|
|
|
sourceMapFilename: '[file].map',
|
|
|
|
chunkFilename: '[id].chunk.js',
|
|
|
|
publicPath: '/client/standalone/videos/'
|
|
|
|
},
|
|
|
|
|
2018-05-29 08:05:03 -05:00
|
|
|
// devtool: 'source-map',
|
|
|
|
|
2017-07-23 07:49:52 -05:00
|
|
|
module: {
|
|
|
|
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'awesome-typescript-loader',
|
|
|
|
options: {
|
2017-12-12 04:38:02 -06:00
|
|
|
configFileName: 'tsconfig.json'
|
2017-07-23 07:49:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
exclude: [/\.(spec|e2e)\.ts$/]
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.(sass|scss)$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
importLoaders: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'resolve-url-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
2017-12-12 04:38:02 -06:00
|
|
|
sourceMap: true,
|
|
|
|
includePaths: [
|
|
|
|
helpers.root('src/sass/include')
|
2017-07-23 07:49:52 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.html$/,
|
|
|
|
use: 'raw-loader',
|
|
|
|
exclude: [
|
|
|
|
helpers.root('src/index.html'),
|
2018-07-10 10:47:56 -05:00
|
|
|
helpers.root('src/standalone/videos/embed.html'),
|
|
|
|
helpers.root('src/standalone/videos/test-embed.html')
|
2017-07-23 07:49:52 -05:00
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.(jpg|png|gif)$/,
|
|
|
|
use: 'url-loader'
|
|
|
|
},
|
|
|
|
|
|
|
|
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
|
|
|
|
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new ExtractTextPlugin({
|
2018-04-06 09:06:43 -05:00
|
|
|
filename: '[name].[hash].css'
|
2017-07-23 07:49:52 -05:00
|
|
|
}),
|
|
|
|
|
|
|
|
new PurifyCSSPlugin({
|
2018-07-10 10:47:56 -05:00
|
|
|
paths: [
|
|
|
|
helpers.root('src/standalone/videos/embed.ts'),
|
|
|
|
helpers.root('src/standalone/videos/test-embed.html')
|
|
|
|
],
|
2017-07-23 07:49:52 -05:00
|
|
|
purifyOptions: {
|
|
|
|
minify: true,
|
|
|
|
whitelist: [ '*vjs*', '*video-js*' ]
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
new CheckerPlugin(),
|
|
|
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'src/standalone/videos/embed.html',
|
|
|
|
filename: 'embed.html',
|
|
|
|
title: 'PeerTube',
|
|
|
|
chunksSortMode: 'dependency',
|
2018-07-10 10:47:56 -05:00
|
|
|
inject: 'body',
|
|
|
|
chunks: ['video-embed']
|
|
|
|
}),
|
|
|
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: '!!html-loader!src/standalone/videos/test-embed.html',
|
|
|
|
filename: 'test-embed.html',
|
|
|
|
title: 'PeerTube',
|
|
|
|
chunksSortMode: 'dependency',
|
|
|
|
inject: 'body',
|
|
|
|
chunks: ['test-embed']
|
2017-12-12 04:38:02 -06:00
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin LoaderOptionsPlugin (experimental)
|
|
|
|
*
|
|
|
|
* See: https://gist.github.com/sokra/27b24881210b56bbaff7
|
|
|
|
*/
|
|
|
|
new LoaderOptionsPlugin({
|
|
|
|
options: {
|
|
|
|
context: __dirname,
|
|
|
|
output: {
|
|
|
|
path: helpers.root('dist')
|
|
|
|
}
|
|
|
|
}
|
2017-07-23 07:49:52 -05:00
|
|
|
})
|
|
|
|
],
|
|
|
|
|
2018-04-06 09:06:43 -05:00
|
|
|
performance: {
|
2018-05-14 03:57:07 -05:00
|
|
|
maxEntrypointSize: 700000, // 600kB
|
|
|
|
maxAssetSize: 700000
|
2018-04-06 09:06:43 -05:00
|
|
|
},
|
|
|
|
|
2017-07-23 07:49:52 -05:00
|
|
|
node: {
|
|
|
|
global: true,
|
|
|
|
crypto: 'empty',
|
|
|
|
fs: 'empty',
|
|
|
|
process: true,
|
|
|
|
module: false,
|
|
|
|
clearImmediate: false,
|
|
|
|
setImmediate: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isProd) {
|
|
|
|
configuration.plugins.push(
|
|
|
|
new UglifyJsPlugin({
|
2017-12-12 04:38:02 -06:00
|
|
|
uglifyOptions: {
|
|
|
|
ecma: 6,
|
2017-07-23 07:49:52 -05:00
|
|
|
warnings: false,
|
2017-12-12 04:38:02 -06:00
|
|
|
ie8: false,
|
|
|
|
mangle: true,
|
|
|
|
compress: {
|
|
|
|
passes: 3,
|
|
|
|
pure_getters: true
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
ascii_only: true,
|
|
|
|
comments: false
|
|
|
|
}
|
2017-07-23 07:49:52 -05:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
new HashedModuleIdsPlugin()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return configuration
|
|
|
|
}
|