]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/config/webpack.common.js
Client: Fix Javascript OOM error during webpack compilation (#89)
[github/Chocobozzz/PeerTube.git] / client / config / webpack.common.js
index 4599858803d9e69930eb8148ad874d8396d52f21..7392c58d395ae026cef5ab756707621688c46517 100644 (file)
@@ -8,7 +8,6 @@ const AssetsPlugin = require('assets-webpack-plugin')
 const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
 const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
 const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
-const CopyWebpackPlugin = require('copy-webpack-plugin')
 const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
 const HtmlWebpackPlugin = require('html-webpack-plugin')
 const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
@@ -17,13 +16,14 @@ const ngcWebpack = require('ngc-webpack')
 
 const WebpackNotifierPlugin = require('webpack-notifier')
 
-/*
- * Webpack Constants
- */
+const HMR = helpers.hasProcessFlag('hot')
+const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot')
 const METADATA = {
   title: 'PeerTube',
   baseUrl: '/',
-  isDevServer: helpers.isWebpackDevServer()
+  isDevServer: helpers.isWebpackDevServer(),
+  HMR: HMR,
+  AOT: AOT
 }
 
 /*
@@ -92,13 +92,6 @@ module.exports = function (options) {
         {
           test: /\.ts$/,
           use: [
-            {
-              loader: '@angularclass/hmr-loader',
-              options: {
-                pretty: !isProd,
-                prod: isProd
-              }
-            },
             {
               loader: 'ng-router-loader',
               options: {
@@ -135,7 +128,13 @@ module.exports = function (options) {
           test: /\.(sass|scss)$/,
           use: [
             'css-to-string-loader',
-            'css-loader?sourceMap',
+            {
+              loader: 'css-loader',
+              options: {
+                sourceMap: true,
+                importLoaders: 1
+              }
+            },
             'resolve-url-loader',
             {
               loader: 'sass-loader',
@@ -174,7 +173,7 @@ module.exports = function (options) {
          */
         {
           test: /\.(jpg|png|gif)$/,
-          use: 'file-loader'
+          use: 'url-loader'
         }
 
       ]
@@ -237,7 +236,7 @@ module.exports = function (options) {
         /**
          * The (\\|\/) piece accounts for path separators in *nix and Windows
          */
-        /angular(\\|\/)core(\\|\/)@angular/,
+        /(.+)?angular(\\|\/)core(.+)?/,
         helpers.root('src'), // location of your src
         {
           /**
@@ -246,30 +245,6 @@ module.exports = function (options) {
         }
       ),
 
-      /*
-       * Plugin: CopyWebpackPlugin
-       * Description: Copy files and directories in webpack.
-       *
-       * Copies project static assets.
-       *
-       * See: https://www.npmjs.com/package/copy-webpack-plugin
-       */
-      // Used by embed.html
-      new CopyWebpackPlugin([
-        {
-          from: 'src/assets',
-          to: 'assets'
-        },
-        {
-          from: 'node_modules/webtorrent/webtorrent.min.js',
-          to: 'assets/webtorrent'
-        },
-        {
-          from: 'src/standalone',
-          to: 'standalone'
-        }
-      ]),
-
       /*
        * Plugin: ScriptExtHtmlWebpackPlugin
        * Description: Enhances html-webpack-plugin functionality
@@ -295,7 +270,10 @@ module.exports = function (options) {
       new HtmlWebpackPlugin({
         template: 'src/index.html',
         title: METADATA.title,
-        chunksSortMode: 'dependency',
+        chunksSortMode: function (a, b) {
+          const entryPoints = [ 'inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main' ]
+          return entryPoints.indexOf(a.names[0]) - entryPoints.indexOf(b.names[0])
+        },
         metadata: METADATA,
         inject: 'body'
       }),
@@ -318,8 +296,7 @@ module.exports = function (options) {
 
       new ngcWebpack.NgcWebpackPlugin({
         disabled: !AOT,
-        tsConfig: helpers.root('tsconfig.webpack.json'),
-        resourceOverride: helpers.root('config/resource-override.js')
+        tsConfig: helpers.root('tsconfig.webpack.json')
       }),
 
       new BundleAnalyzerPlugin({