Replace sprockets/browserify with Webpack (#2617)
* Replace browserify with webpack * Add react-intl-translations-manager * Do not minify in development, add offline-plugin for ServiceWorker background cache updates * Adjust tests and dependencies * Fix production deployments * Fix tests * More optimizations * Improve travis cache for npm stuff * Re-run travis * Add back support for custom.scss as before * Remove offline-plugin and babili * Fix issue with Immutable.List().unshift(...values) not working as expected * Make travis load schema instead of running all migrations in sequence * Fix missing React import in WarningContainer. Optimize rendering performance by using ImmutablePureComponent instead of React.PureComponent. ImmutablePureComponent uses Immutable.is() to compare props. Replace dynamic callback bindings in <UI /> * Add react definitions to places that use JSX * Add Procfile.dev for running rails, webpack and streaming API at the same time
This commit is contained in:
parent
26bc591572
commit
f5bf5ebb82
343 changed files with 5299 additions and 2081 deletions
26
config/webpack/configuration.js
Normal file
26
config/webpack/configuration.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Common configuration for webpacker loaded from config/webpack/paths.yml
|
||||
|
||||
const { join, resolve } = require('path')
|
||||
const { env } = require('process')
|
||||
const { safeLoad } = require('js-yaml')
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
const configPath = resolve('config', 'webpack')
|
||||
const loadersDir = join(__dirname, 'loaders')
|
||||
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV]
|
||||
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV]
|
||||
|
||||
// Compute public path based on environment and CDN_HOST in production
|
||||
const ifHasCDN = env.CDN_HOST !== undefined && env.NODE_ENV === 'production'
|
||||
const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`
|
||||
const publicUrl = ifHasCDN ? `${env.CDN_HOST}/${paths.entry}/` : `/${paths.entry}/`
|
||||
const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl
|
||||
|
||||
module.exports = {
|
||||
devServer,
|
||||
env,
|
||||
paths,
|
||||
loadersDir,
|
||||
publicUrl,
|
||||
publicPath
|
||||
}
|
16
config/webpack/development.js
Normal file
16
config/webpack/development.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||
|
||||
const merge = require('webpack-merge')
|
||||
const sharedConfig = require('./shared.js')
|
||||
|
||||
module.exports = merge(sharedConfig, {
|
||||
devtool: 'sourcemap',
|
||||
|
||||
stats: {
|
||||
errorDetails: true
|
||||
},
|
||||
|
||||
output: {
|
||||
pathinfo: true
|
||||
}
|
||||
})
|
18
config/webpack/development.server.js
Normal file
18
config/webpack/development.server.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||
|
||||
const { resolve } = require('path')
|
||||
const merge = require('webpack-merge')
|
||||
const devConfig = require('./development.js')
|
||||
const { devServer, publicPath, paths } = require('./configuration.js')
|
||||
|
||||
module.exports = merge(devConfig, {
|
||||
devServer: {
|
||||
host: devServer.host,
|
||||
port: devServer.port,
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
compress: true,
|
||||
historyApiFallback: true,
|
||||
contentBase: resolve(paths.output, paths.entry),
|
||||
publicPath
|
||||
}
|
||||
})
|
17
config/webpack/development.server.yml
Normal file
17
config/webpack/development.server.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||
|
||||
default: &default
|
||||
enabled: true
|
||||
host: localhost
|
||||
port: 8080
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
|
||||
test:
|
||||
<<: *default
|
||||
enabled: false
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
enabled: false
|
12
config/webpack/loaders/assets.js
Normal file
12
config/webpack/loaders/assets.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
const { env, publicPath } = require('../configuration.js')
|
||||
|
||||
module.exports = {
|
||||
test: /\.(jpg|jpeg|png|gif|svg|eot|ttf|woff|woff2)$/i,
|
||||
use: [{
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
publicPath,
|
||||
name: env.NODE_ENV === 'production' ? '[name]-[hash].[ext]' : '[name].[ext]'
|
||||
}
|
||||
}]
|
||||
}
|
5
config/webpack/loaders/babel.js
Normal file
5
config/webpack/loaders/babel.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
test: /\.js(\.erb)?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader'
|
||||
}
|
4
config/webpack/loaders/coffee.js
Normal file
4
config/webpack/loaders/coffee.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
test: /\.coffee(\.erb)?$/,
|
||||
loader: 'coffee-loader'
|
||||
}
|
9
config/webpack/loaders/erb.js
Normal file
9
config/webpack/loaders/erb.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
test: /\.erb$/,
|
||||
enforce: 'pre',
|
||||
exclude: /node_modules/,
|
||||
loader: 'rails-erb-loader',
|
||||
options: {
|
||||
runner: 'bin/rails runner'
|
||||
}
|
||||
}
|
14
config/webpack/loaders/sass.js
Normal file
14
config/webpack/loaders/sass.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||
const { env } = require('../configuration.js')
|
||||
|
||||
module.exports = {
|
||||
test: /\.(scss|sass|css)$/i,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: [
|
||||
{ loader: 'css-loader', options: { minimize: env.NODE_ENV === 'production' } },
|
||||
'postcss-loader',
|
||||
'sass-loader'
|
||||
]
|
||||
})
|
||||
}
|
33
config/webpack/paths.yml
Normal file
33
config/webpack/paths.yml
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||
|
||||
default: &default
|
||||
config: config/webpack
|
||||
entry: packs
|
||||
output: public
|
||||
manifest: manifest.json
|
||||
node_modules: node_modules
|
||||
source: app/javascript
|
||||
extensions:
|
||||
- .coffee
|
||||
- .js
|
||||
- .jsx
|
||||
- .ts
|
||||
- .vue
|
||||
- .sass
|
||||
- .scss
|
||||
- .css
|
||||
- .png
|
||||
- .svg
|
||||
- .gif
|
||||
- .jpeg
|
||||
- .jpg
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
|
||||
test:
|
||||
<<: *default
|
||||
manifest: manifest-test.json
|
||||
|
||||
production:
|
||||
<<: *default
|
44
config/webpack/production.js
Normal file
44
config/webpack/production.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||
|
||||
/* eslint global-require: 0 */
|
||||
|
||||
const webpack = require('webpack')
|
||||
const merge = require('webpack-merge')
|
||||
const CompressionPlugin = require('compression-webpack-plugin')
|
||||
const sharedConfig = require('./shared.js')
|
||||
|
||||
module.exports = merge(sharedConfig, {
|
||||
output: { filename: '[name]-[chunkhash].js' },
|
||||
|
||||
plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
unused: true,
|
||||
evaluate: true,
|
||||
booleans: true,
|
||||
drop_debugger: true,
|
||||
dead_code: true,
|
||||
pure_getters: true,
|
||||
negate_iife: true,
|
||||
conditionals: true,
|
||||
loops: true,
|
||||
cascade: true,
|
||||
keep_fargs: false,
|
||||
warnings: true
|
||||
},
|
||||
|
||||
mangle: false,
|
||||
|
||||
output: {
|
||||
comments: false
|
||||
},
|
||||
|
||||
sourceMap: false
|
||||
}),
|
||||
new CompressionPlugin({
|
||||
asset: '[path].gz[query]',
|
||||
algorithm: 'gzip',
|
||||
test: /\.(js|css|svg|eot|ttf|woff|woff2)$/
|
||||
})
|
||||
]
|
||||
})
|
59
config/webpack/shared.js
Normal file
59
config/webpack/shared.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||
|
||||
/* eslint global-require: 0 */
|
||||
/* eslint import/no-dynamic-require: 0 */
|
||||
|
||||
const webpack = require('webpack')
|
||||
const { basename, dirname, join, relative, resolve } = require('path')
|
||||
const { sync } = require('glob')
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||
const ManifestPlugin = require('webpack-manifest-plugin')
|
||||
const extname = require('path-complete-extname')
|
||||
const { env, paths, publicPath, loadersDir } = require('./configuration.js')
|
||||
|
||||
const extensionGlob = `**/*{${paths.extensions.join(',')}}*`
|
||||
const packPaths = sync(join(paths.source, paths.entry, extensionGlob))
|
||||
|
||||
module.exports = {
|
||||
entry: packPaths.reduce(
|
||||
(map, entry) => {
|
||||
const localMap = map
|
||||
const namespace = relative(join(paths.source, paths.entry), dirname(entry))
|
||||
localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry)
|
||||
return localMap
|
||||
}, {}
|
||||
),
|
||||
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
chunkFilename: '[name]-[chunkhash].js',
|
||||
path: resolve(paths.output, paths.entry),
|
||||
publicPath
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: sync(join(loadersDir, '*.js')).map(loader => require(loader))
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
|
||||
new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
|
||||
new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }),
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: 'vendor',
|
||||
minChunks: ({ resource }) => /node_modules/.test(resource)
|
||||
})
|
||||
],
|
||||
|
||||
resolve: {
|
||||
extensions: paths.extensions,
|
||||
modules: [
|
||||
resolve(paths.source),
|
||||
resolve(paths.node_modules)
|
||||
]
|
||||
},
|
||||
|
||||
resolveLoader: {
|
||||
modules: [paths.node_modules]
|
||||
}
|
||||
}
|
6
config/webpack/test.js
Normal file
6
config/webpack/test.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||
|
||||
const merge = require('webpack-merge')
|
||||
const sharedConfig = require('./shared.js')
|
||||
|
||||
module.exports = merge(sharedConfig, {})
|
34
config/webpack/translationRunner.js
Normal file
34
config/webpack/translationRunner.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const manageTranslations = require('react-intl-translations-manager').default;
|
||||
|
||||
manageTranslations({
|
||||
messagesDirectory: 'build/messages',
|
||||
translationsDirectory: 'app/javascript/mastodon/locales/',
|
||||
detectDuplicateIds: false,
|
||||
singleMessagesFile: true,
|
||||
languages: [
|
||||
'ar',
|
||||
'en',
|
||||
'de',
|
||||
'es',
|
||||
'fa',
|
||||
'hr',
|
||||
'hu',
|
||||
'io',
|
||||
'it',
|
||||
'fr',
|
||||
'nl',
|
||||
'no',
|
||||
'oc',
|
||||
'pt',
|
||||
'pt-BR',
|
||||
'uk',
|
||||
'fi',
|
||||
'eo',
|
||||
'ru',
|
||||
'ja',
|
||||
'zh-HK',
|
||||
'zh-CN',
|
||||
'bg',
|
||||
'id',
|
||||
],
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue