2017-04-28 12:24:56 +08:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-11-22 04:24:40 +08:00
|
|
|
const glob = require('glob')
|
2018-03-07 10:12:53 +08:00
|
|
|
const fs = require('fs')
|
|
|
|
const momentLocaleBundles = require('./momentBundles')
|
2015-10-01 11:16:11 +08:00
|
|
|
|
2016-11-22 04:24:40 +08:00
|
|
|
const entries = {}
|
2015-10-01 11:16:11 +08:00
|
|
|
|
2018-11-08 05:33:43 +08:00
|
|
|
const bundlesPattern = `${__dirname}/../app/{jsx,coffeescripts}/bundles/**/*.{coffee,js}`
|
|
|
|
const pluginBundlesPattern = `${__dirname}/../gems/plugins/*/app/{jsx,coffeescripts}/bundles/**/*.{coffee,js}`
|
2017-03-15 06:48:32 +08:00
|
|
|
const bundleNameRegexp = /\/(coffeescripts|jsx)\/bundles\/(.*).(coffee|js)/
|
|
|
|
const fileNameRegexp = /\/([^/]+)\.(coffee|js)/
|
2017-01-11 07:29:45 +08:00
|
|
|
const pluginNameRegexp = /plugins\/([^/]+)\/app/
|
|
|
|
|
|
|
|
const appBundles = glob.sync(bundlesPattern, [])
|
|
|
|
const pluginBundles = glob.sync(pluginBundlesPattern, [])
|
2015-12-22 06:05:27 +08:00
|
|
|
|
2018-11-08 05:33:43 +08:00
|
|
|
appBundles.forEach(entryFilepath => {
|
|
|
|
const entryBundlePath = entryFilepath.replace(
|
|
|
|
/^.*app\/(coffeescripts|jsx)\/bundles/,
|
2018-03-07 10:12:53 +08:00
|
|
|
(_, dir) => `../app/${dir}/bundles`
|
2018-11-08 05:33:43 +08:00
|
|
|
)
|
2017-03-15 06:48:32 +08:00
|
|
|
const entryName = bundleNameRegexp.exec(entryBundlePath)[2]
|
2019-05-16 11:53:48 +08:00
|
|
|
entries[entryName] = entryBundlePath
|
2016-11-22 04:24:40 +08:00
|
|
|
})
|
2015-12-22 06:05:27 +08:00
|
|
|
|
2018-11-08 05:33:43 +08:00
|
|
|
pluginBundles.forEach(entryFilepath => {
|
2018-03-07 10:12:53 +08:00
|
|
|
const relativePath = entryFilepath.replace(/.*\/gems\/plugins/, '../gems/plugins')
|
Webpack: better handling of chunks and cdn stuff
fixes: CNVS-31779 [webpack] bundle file size
test plan:
* using webpack, look at the network panel in
the chrome developer console.
* the total ammount of javascript loaded for any
given page should be much less than before this commit
and about on par with what requireJS loads for the same page.
* use chrome network panel to throttle to "Regular 3G"
* from both a clean cache and a primed cache:
* make sure that the total time to render the page
is about on par with requireJS
first change: load webpack chunks from CDN
fixes: CNVS-32261
test plan:
* run `npm run webpack-production`
* check your page, it should load js files and chunks
from the same hostname the page is served from.
* now set a host: in config/canvas_cdn.yml
(for testing locally, I just set it to http://127.0.0.1:3000,
* restart rails and reload the page, now the scripts and
chucks should come from that new hostname
second change:include fingerprints in webpack bundle and chunk filenames
closes: CNVS-28628
with this change we don't need to run `gulp rev`
after running webpack and we can load both the bundle
and chunk files safely from the cdn, since they will
have content-based fingerprints so we can tell
browsers to cache them forever. (we set those
http caching headers in lib/canvas/cdn/s3_uploader.rb:53)
test plan:
* for both dev and production
* run `npm run webpack` (or `npm run wepack-production`)
* with a cdn configured in canvas_cdn.yml, run:
RAILS_ENV=<dev or prod> bundle exec rake canvas:cdn:upload_to_s3
* check to make sure that the page loads the webpack js,
that there are no errors, and it all came from the cdn
third change: properly handle moment locale & timezone in webpack
test plan:
(see application_helper_spec.rb)
* set a non-default user timezone, context timezone
and locale
* dates should show up in your timezone and and
the date helper strings should be in your language
better handling of moment custom locales
closes: CNVS-33811
since we now have hatian and maori, we need to do this in
a way that is not just a one-off for maori
test plan:
* set your locale to maori
* in webpack & requireJS make sure dates show up right
Change-Id: I34dbff7d46a1047f9b459d5e1c0d141f435d42fb
Reviewed-on: https://gerrit.instructure.com/95737
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
2016-12-13 01:32:11 +08:00
|
|
|
const pluginName = pluginNameRegexp.exec(entryFilepath)[1]
|
|
|
|
const fileName = fileNameRegexp.exec(entryFilepath)[1]
|
2018-11-08 05:33:43 +08:00
|
|
|
const bundleName = `${pluginName}-${fileName}`
|
2018-03-07 10:12:53 +08:00
|
|
|
entries[bundleName] = relativePath
|
Webpack: better handling of chunks and cdn stuff
fixes: CNVS-31779 [webpack] bundle file size
test plan:
* using webpack, look at the network panel in
the chrome developer console.
* the total ammount of javascript loaded for any
given page should be much less than before this commit
and about on par with what requireJS loads for the same page.
* use chrome network panel to throttle to "Regular 3G"
* from both a clean cache and a primed cache:
* make sure that the total time to render the page
is about on par with requireJS
first change: load webpack chunks from CDN
fixes: CNVS-32261
test plan:
* run `npm run webpack-production`
* check your page, it should load js files and chunks
from the same hostname the page is served from.
* now set a host: in config/canvas_cdn.yml
(for testing locally, I just set it to http://127.0.0.1:3000,
* restart rails and reload the page, now the scripts and
chucks should come from that new hostname
second change:include fingerprints in webpack bundle and chunk filenames
closes: CNVS-28628
with this change we don't need to run `gulp rev`
after running webpack and we can load both the bundle
and chunk files safely from the cdn, since they will
have content-based fingerprints so we can tell
browsers to cache them forever. (we set those
http caching headers in lib/canvas/cdn/s3_uploader.rb:53)
test plan:
* for both dev and production
* run `npm run webpack` (or `npm run wepack-production`)
* with a cdn configured in canvas_cdn.yml, run:
RAILS_ENV=<dev or prod> bundle exec rake canvas:cdn:upload_to_s3
* check to make sure that the page loads the webpack js,
that there are no errors, and it all came from the cdn
third change: properly handle moment locale & timezone in webpack
test plan:
(see application_helper_spec.rb)
* set a non-default user timezone, context timezone
and locale
* dates should show up in your timezone and and
the date helper strings should be in your language
better handling of moment custom locales
closes: CNVS-33811
since we now have hatian and maori, we need to do this in
a way that is not just a one-off for maori
test plan:
* set your locale to maori
* in webpack & requireJS make sure dates show up right
Change-Id: I34dbff7d46a1047f9b459d5e1c0d141f435d42fb
Reviewed-on: https://gerrit.instructure.com/95737
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
2016-12-13 01:32:11 +08:00
|
|
|
})
|
2015-10-01 11:16:11 +08:00
|
|
|
|
2018-03-07 10:12:53 +08:00
|
|
|
fs.writeFileSync(
|
|
|
|
'./node_modules/bundles-generated.js',
|
|
|
|
`
|
|
|
|
|
|
|
|
if (typeof ENV !== 'undefined' && ENV.MOMENT_LOCALE && ENV.MOMENT_LOCALE !== 'en') {
|
|
|
|
function loadLocale(locale) {
|
|
|
|
switch (locale) {
|
|
|
|
${Object.entries(momentLocaleBundles)
|
|
|
|
.map(
|
|
|
|
([assetName, jsFile]) => `
|
|
|
|
case "${assetName}": return import(/* webpackChunkName: "${assetName}" */ "${jsFile}");
|
|
|
|
`
|
|
|
|
)
|
|
|
|
.join('')}
|
|
|
|
|
|
|
|
default:
|
|
|
|
console.warn("couldn't load moment/locale/", locale)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadLocale('moment/locale/' + ENV.MOMENT_LOCALE)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function loadBundle(bundleName) {
|
|
|
|
switch (bundleName) {
|
|
|
|
${Object.entries(entries)
|
|
|
|
.map(
|
|
|
|
([entryName, entryBundlePath]) => `
|
|
|
|
case "${entryName}": return import(/* webpackChunkName: "${entryName}" */ "${entryBundlePath}");
|
|
|
|
`
|
|
|
|
)
|
|
|
|
.join('')}
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Error("couldn't find bundle " + bundleName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
|
Webpack: better handling of chunks and cdn stuff
fixes: CNVS-31779 [webpack] bundle file size
test plan:
* using webpack, look at the network panel in
the chrome developer console.
* the total ammount of javascript loaded for any
given page should be much less than before this commit
and about on par with what requireJS loads for the same page.
* use chrome network panel to throttle to "Regular 3G"
* from both a clean cache and a primed cache:
* make sure that the total time to render the page
is about on par with requireJS
first change: load webpack chunks from CDN
fixes: CNVS-32261
test plan:
* run `npm run webpack-production`
* check your page, it should load js files and chunks
from the same hostname the page is served from.
* now set a host: in config/canvas_cdn.yml
(for testing locally, I just set it to http://127.0.0.1:3000,
* restart rails and reload the page, now the scripts and
chucks should come from that new hostname
second change:include fingerprints in webpack bundle and chunk filenames
closes: CNVS-28628
with this change we don't need to run `gulp rev`
after running webpack and we can load both the bundle
and chunk files safely from the cdn, since they will
have content-based fingerprints so we can tell
browsers to cache them forever. (we set those
http caching headers in lib/canvas/cdn/s3_uploader.rb:53)
test plan:
* for both dev and production
* run `npm run webpack` (or `npm run wepack-production`)
* with a cdn configured in canvas_cdn.yml, run:
RAILS_ENV=<dev or prod> bundle exec rake canvas:cdn:upload_to_s3
* check to make sure that the page loads the webpack js,
that there are no errors, and it all came from the cdn
third change: properly handle moment locale & timezone in webpack
test plan:
(see application_helper_spec.rb)
* set a non-default user timezone, context timezone
and locale
* dates should show up in your timezone and and
the date helper strings should be in your language
better handling of moment custom locales
closes: CNVS-33811
since we now have hatian and maori, we need to do this in
a way that is not just a one-off for maori
test plan:
* set your locale to maori
* in webpack & requireJS make sure dates show up right
Change-Id: I34dbff7d46a1047f9b459d5e1c0d141f435d42fb
Reviewed-on: https://gerrit.instructure.com/95737
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
2016-12-13 01:32:11 +08:00
|
|
|
module.exports = entries
|