123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- var path = require('path'),
- fs = require('fs'),
- webpack = require('webpack'),
- ExtractTextPlugin = require('extract-text-webpack-plugin'),
- LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
- var staticPrefix = 'src/sentry/static/sentry',
- distPath = path.join(__dirname, staticPrefix, 'dist');
- if (process.env.SENTRY_STATIC_DIST_PATH) {
- distPath = process.env.SENTRY_STATIC_DIST_PATH;
- }
- var IS_PRODUCTION = process.env.NODE_ENV === 'production';
- var IS_TEST = process.env.NODE_ENV === 'test' || process.env.TEST_SUITE;
- var WEBPACK_DEV_PORT = process.env.WEBPACK_DEV_PORT;
- var SENTRY_DEVSERVER_PORT = process.env.SENTRY_DEVSERVER_PORT;
- var USE_HOT_MODULE_RELOAD = !IS_PRODUCTION && WEBPACK_DEV_PORT && SENTRY_DEVSERVER_PORT;
- var WITH_CSS_SOURCEMAPS = !!process.env.WITH_CSS_SOURCEMAPS || IS_PRODUCTION;
- var babelConfig = JSON.parse(fs.readFileSync(path.join(__dirname, '.babelrc')));
- babelConfig.cacheDirectory = true;
- if (process.env.SENTRY_EXTRACT_TRANSLATIONS === '1') {
- babelConfig.plugins.push([
- 'babel-gettext-extractor',
- {
- fileName: 'build/javascript.po',
- baseDirectory: path.join(__dirname, 'src/sentry'),
- functionNames: {
- gettext: ['msgid'],
- ngettext: ['msgid', 'msgid_plural', 'count'],
- gettextComponentTemplate: ['msgid'],
- t: ['msgid'],
- tn: ['msgid', 'msgid_plural', 'count'],
- tct: ['msgid'],
- },
- },
- ]);
- }
- var appEntry = {
- app: ['app'],
- vendor: [
- 'babel-polyfill',
- 'bootstrap/js/dropdown',
- 'bootstrap/js/tab',
- 'bootstrap/js/tooltip',
- 'bootstrap/js/alert',
- 'create-react-class',
- 'jed',
- 'jquery',
- 'marked',
- 'moment',
- 'moment-timezone',
- '@sentry/browser',
- 'react',
- 'react-dom',
- 'react-dom/server',
- 'react-document-title',
- 'react-router',
- 'react-bootstrap/lib/Modal',
- 'reflux',
- 'vendor/simple-slider/simple-slider',
- 'emotion',
- 'react-emotion',
- 'grid-emotion',
- 'emotion-theming',
- ],
- };
- var localeCatalogPath = path.join(__dirname, 'src', 'sentry', 'locale', 'catalogs.json');
- var localeCatalog = JSON.parse(fs.readFileSync(localeCatalogPath, 'utf8'));
- var localeEntries = [];
- localeCatalog.supported_locales.forEach(function(locale) {
- if (locale === 'en') return;
-
- var normalizedLocale = locale.toLowerCase().replace('_', '-');
- appEntry['locale/' + normalizedLocale] = [
- 'moment/locale/' + normalizedLocale,
- 'sentry-locale/' + locale + '/LC_MESSAGES/django.po',
- ];
- localeEntries.push('locale/' + normalizedLocale);
- });
- var appConfig = {
- entry: appEntry,
- context: path.join(__dirname, staticPrefix),
- module: {
- rules: [
- {
- test: /\.jsx?$/,
- loader: 'babel-loader',
- include: path.join(__dirname, staticPrefix),
- exclude: /(vendor|node_modules|dist)/,
- query: babelConfig,
- },
- {
- test: /\.po$/,
- loader: 'po-catalog-loader',
- query: {
- referenceExtensions: ['.js', '.jsx'],
- domain: 'sentry',
- },
- },
- {
- test: /app\/icons\/.*\.svg$/,
- use: [
- {
- loader: 'svg-sprite-loader',
- },
- {
- loader: 'svgo-loader',
- },
- ],
- },
-
- {
- test: /\.less$/,
- use: [
- {
- loader: 'style-loader',
- },
- {
- loader: 'css-loader',
- options: {
- minimize: IS_PRODUCTION,
- },
- },
- {
- loader: 'less-loader',
- },
- ],
- },
- {
- test: /\.css/,
- use: [
- {
- loader: 'style-loader',
- },
- {
- loader: 'css-loader',
- options: {
- minimize: IS_PRODUCTION,
- },
- },
- ],
- },
- {
- test: /\.(woff|woff2|ttf|eot|svg|png|gif|ico|jpg)($|\?)/,
- exclude: /app\/icons\/.*\.svg$/,
- loader: 'file-loader?name=' + '[name].[ext]',
- },
- ],
- noParse: [
-
- /dist\/jquery\.js/,
- /jed\/jed\.js/,
- /marked\/lib\/marked\.js/,
- ],
- },
- plugins: [
- new LodashModuleReplacementPlugin({
- collections: true,
- currying: true,
- flattening: true,
- shorthands: true,
- }),
- new webpack.optimize.CommonsChunkPlugin({
- names: localeEntries.concat(['vendor']),
- }),
- new webpack.ProvidePlugin({
- $: 'jquery',
- jQuery: 'jquery',
- 'window.jQuery': 'jquery',
- 'root.jQuery': 'jquery',
- }),
- new ExtractTextPlugin('[name].css'),
- new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
- new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify(process.env.NODE_ENV),
- IS_PERCY: JSON.stringify(
- process.env.CI && !!process.env.PERCY_TOKEN && !!process.env.TRAVIS
- ),
- },
- }),
-
-
- new webpack.ContextReplacementPlugin(
- /locale$/,
- path.join(__dirname, 'src', 'sentry', 'locale', path.sep),
- true,
- new RegExp('(' + localeCatalog.supported_locales.join('|') + ')/.*\\.po$')
- ),
- ],
- resolve: {
- alias: {
- app: path.join(__dirname, 'src', 'sentry', 'static', 'sentry', 'app'),
- 'app-test': path.join(__dirname, 'tests', 'js'),
- 'app-test-helpers': path.join(__dirname, 'tests', 'js', 'helpers'),
- 'sentry-locale': path.join(__dirname, 'src', 'sentry', 'locale'),
- 'integration-docs-platforms': IS_TEST
- ? path.join(__dirname, 'tests/fixtures/integration-docs/_platforms.json')
- : path.join(__dirname, 'src/sentry/integration-docs/_platforms.json'),
- },
- modules: [path.join(__dirname, staticPrefix), 'node_modules'],
- extensions: ['.less', '.jsx', '.js', '.json'],
- },
- output: {
- path: distPath,
- filename: '[name].js',
- libraryTarget: 'var',
- library: 'exports',
- sourceMapFilename: '[name].js.map',
- },
- devtool: IS_PRODUCTION ? '#source-map' : '#cheap-module-eval-source-map',
- };
- var pwConfig = {
- entry: {
- pwstrength: './index',
- },
- context: path.resolve(path.join(__dirname, staticPrefix), 'js', 'pwstrength'),
- module: {},
- plugins: [],
- resolve: {
- modules: [path.join(__dirname, staticPrefix), 'node_modules'],
- extensions: ['.js'],
- },
- output: {
- path: distPath,
- filename: '[name].js',
- libraryTarget: 'window',
- library: 'sentrypw',
- sourceMapFilename: '[name].js.map',
- },
- devtool: IS_PRODUCTION ? '#source-map' : '#cheap-source-map',
- };
- var legacyCssConfig = {
- entry: {
- sentry: 'less/sentry.less',
-
-
- select2: 'less/select2.less',
- },
- context: path.join(__dirname, staticPrefix),
- output: {
- path: distPath,
- filename: '[name].css',
- },
- plugins: [new ExtractTextPlugin('[name].css')],
- resolve: {
- extensions: ['.less', '.js'],
- modules: [path.join(__dirname, staticPrefix), 'node_modules'],
- },
- module: {
- rules: [
- {
- test: /\.less$/,
- include: path.join(__dirname, staticPrefix),
- use: ExtractTextPlugin.extract({
- fallback: 'style-loader?sourceMap=false',
- use: [
- {
- loader: 'css-loader',
- options: {
- sourceMap: WITH_CSS_SOURCEMAPS,
- minimize: IS_PRODUCTION,
- },
- },
- {
- loader: 'less-loader',
- options: {
- sourceMap: WITH_CSS_SOURCEMAPS,
- },
- },
- ],
- }),
- },
- {
- test: /\.(woff|woff2|ttf|eot|svg|png|gif|ico|jpg)($|\?)/,
- loader: 'file-loader?name=' + '[name].[ext]',
- },
- ],
- },
- devtool: WITH_CSS_SOURCEMAPS ? '#source-map' : undefined,
- };
- if (USE_HOT_MODULE_RELOAD) {
-
- appConfig.plugins.push(new webpack.NamedModulesPlugin());
-
- appConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
- appConfig.devServer = {
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Credentials': 'true',
- },
-
- disableHostCheck: true,
- contentBase: './src/sentry/static/sentry',
- hot: true,
-
- hotOnly: true,
- port: WEBPACK_DEV_PORT,
- };
-
-
- appConfig.output.publicPath = 'http://localhost:' + WEBPACK_DEV_PORT + '/';
- }
- var minificationPlugins = [
-
-
-
- new (require('compression-webpack-plugin'))({
- algorithm: function(buffer, options, callback) {
- require('zlib').gzip(buffer, callback);
- },
- regExp: /\.(js|map|css|svg|html|txt|ico|eot|ttf)$/,
- }),
-
-
- new webpack.optimize.UglifyJsPlugin({
- compress: {
- warnings: false,
- },
-
- sourceMap:
- appConfig.devtool &&
- (appConfig.devtool.indexOf('sourcemap') >= 0 ||
- appConfig.devtool.indexOf('source-map') >= 0),
- }),
- ];
- if (IS_PRODUCTION) {
-
- minificationPlugins.forEach(function(plugin) {
- appConfig.plugins.push(plugin);
- pwConfig.plugins.push(plugin);
- legacyCssConfig.plugins.push(plugin);
- });
- }
- module.exports = [appConfig, legacyCssConfig, pwConfig];
|