<commit_before>/*
 * Copyright (C) 2015 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

if (!process.env.NODE_ENV) process.env.NODE_ENV = 'development'

// keep this in sync with webpack's dep version
const TerserPlugin = require('terser-webpack-plugin')
const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin')
const path = require('path')
const glob = require('glob')
const webpack = require('webpack')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin
const I18nPlugin = require('./i18nPlugin')
const WebpackHooks = require('./webpackHooks')
const SourceFileExtensionsPlugin = require('./SourceFileExtensionsPlugin')
const EncapsulationPlugin = require('webpack-encapsulation-plugin')
const IgnoreErrorsPlugin = require('./IgnoreErrorsPlugin')
const webpackPublicPath = require('./webpackPublicPath')
const {canvasDir} = require('#params')

require('./bundles')

// We have a bunch of things (like our selenium jenkins builds) that have
// historically used the environment variable JS_BUILD_NO_UGLIFY to make their
// prod webpack builds go faster. But the slowest thing was not actually uglify
// (aka terser), it is generating the sourcemaps. Now that we added the
// performance hints and want to fail the build if you accidentally make our
// bundles larger than a certain size, we need to always uglify to check the
// after-uglify size of things, but can skip making sourcemaps if you want it to
// go faster. So this is to allow people to use either environment variable:
// the technically more correct SKIP_SOURCEMAPS one or the historically used JS_BUILD_NO_UGLIFY one.
const skipSourcemaps = Boolean(
  process.env.SKIP_SOURCEMAPS || process.env.JS_BUILD_NO_UGLIFY === '1'
)

const createBundleAnalyzerPlugin = (...args) => {
  const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
  return new BundleAnalyzerPlugin(...args)
}

module.exports = {
  mode: process.env.NODE_ENV,
  performance: skipSourcemaps
    ? false
    : {
        // This just reflects how big the 'main' entry is at the time of writing. Every
        // time we get it smaller we should change this to the new smaller number so it
        // only goes down over time instead of growing bigger over time
        maxEntrypointSize: 1265000,
        // This is how big our biggest js bundles are at the time of writing. We should
        // first work to attack the things in `thingsWeKnowAreWayTooBig` so we can start
        // tracking them too. Then, as we work to get all chunks smaller, we should change
        // this number to the size of our biggest known asset and hopefully someday get
        // to where they are all under the default value of 250000 and then remove this
        // TODO: decrease back to 1200000 LS-1222
        maxAssetSize: 1400000,
        assetFilter: assetFilename => {
          const thingsWeKnowAreWayTooBig = [
            'assignment_edit',
            'canvas-rce-async-chunk',
            'canvas-rce-old-async-chunk',
            'discussion_topic_edit',
            'discussion_topics_post'
          ]
          return (
            assetFilename.endsWith('.js') &&
            !thingsWeKnowAreWayTooBig.some(t => assetFilename.includes(t))
          )<commit_msg>bump maxEntryPointSize to allow builds to pass<commit_after>/*
 * Copyright (C) 2015 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

if (!process.env.NODE_ENV) process.env.NODE_ENV = 'development'

// keep this in sync with webpack's dep version
const TerserPlugin = require('terser-webpack-plugin')
const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin')
const path = require('path')
const glob = require('glob')
const webpack = require('webpack')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin
const I18nPlugin = require('./i18nPlugin')
const WebpackHooks = require('./webpackHooks')
const SourceFileExtensionsPlugin = require('./SourceFileExtensionsPlugin')
const EncapsulationPlugin = require('webpack-encapsulation-plugin')
const IgnoreErrorsPlugin = require('./IgnoreErrorsPlugin')
const webpackPublicPath = require('./webpackPublicPath')
const {canvasDir} = require('#params')

require('./bundles')

// We have a bunch of things (like our selenium jenkins builds) that have
// historically used the environment variable JS_BUILD_NO_UGLIFY to make their
// prod webpack builds go faster. But the slowest thing was not actually uglify
// (aka terser), it is generating the sourcemaps. Now that we added the
// performance hints and want to fail the build if you accidentally make our
// bundles larger than a certain size, we need to always uglify to check the
// after-uglify size of things, but can skip making sourcemaps if you want it to
// go faster. So this is to allow people to use either environment variable:
// the technically more correct SKIP_SOURCEMAPS one or the historically used JS_BUILD_NO_UGLIFY one.
const skipSourcemaps = Boolean(
  process.env.SKIP_SOURCEMAPS || process.env.JS_BUILD_NO_UGLIFY === '1'
)

const createBundleAnalyzerPlugin = (...args) => {
  const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
  return new BundleAnalyzerPlugin(...args)
}

module.exports = {
  mode: process.env.NODE_ENV,
  performance: skipSourcemaps
    ? false
    : {
        // This just reflects how big the 'main' entry is at the time of writing. Every
        // time we get it smaller we should change this to the new smaller number so it
        // only goes down over time instead of growing bigger over time
        maxEntrypointSize: 1270000,
        // This is how big our biggest js bundles are at the time of writing. We should
        // first work to attack the things in `thingsWeKnowAreWayTooBig` so we can start
        // tracking them too. Then, as we work to get all chunks smaller, we should change
        // this number to the size of our biggest known asset and hopefully someday get
        // to where they are all under the default value of 250000 and then remove this
        // TODO: decrease back to 1200000 LS-1222
        maxAssetSize: 1400000,
        assetFilter: assetFilename => {
          const thingsWeKnowAreWayTooBig = [
            'assignment_edit',
            'canvas-rce-async-chunk',
            'canvas-rce-old-async-chunk',
            'discussion_topic_edit',
            'discussion_topics_post'
          ]
          return (
            assetFilename.endsWith('.js') &&
            !thingsWeKnowAreWayTooBig.some(t => assetFilename.includes(t))
          )
{'fraction_non_alphanumeric': 0.08206034591591971, 'fraction_numerical': 0.010352228254008332, 'mean_word_length': 3.4681331077270166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4408671', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2056, 'n_words': 868}