2017-01-17 13:40:59 +01:00
|
|
|
// Important modules this config uses
|
|
|
|
const path = require('path');
|
2018-03-08 12:56:44 +01:00
|
|
|
const _ = require('lodash');
|
2018-01-12 16:41:59 +01:00
|
|
|
|
2017-08-18 14:17:15 +02:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2017-01-17 13:40:59 +01:00
|
|
|
const cssnext = require('postcss-cssnext');
|
|
|
|
const postcssFocus = require('postcss-focus');
|
|
|
|
const postcssReporter = require('postcss-reporter');
|
2017-05-11 14:17:21 +02:00
|
|
|
const webpack = require('webpack');
|
2018-03-08 12:56:44 +01:00
|
|
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
2017-09-27 15:09:46 +02:00
|
|
|
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
|
2018-01-12 16:41:59 +01:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2017-05-11 14:17:21 +02:00
|
|
|
|
2018-03-08 12:56:44 +01:00
|
|
|
const base = require('./webpack.base.babel');
|
|
|
|
|
2017-11-10 16:04:57 +01:00
|
|
|
const isAdmin = process.env.IS_ADMIN === 'true';
|
2018-05-03 17:39:24 +02:00
|
|
|
// const isSetup = path.resolve(process.env.PWD, '..', '..') === path.resolve(process.env.INIT_CWD);
|
|
|
|
const isSetup = process.env.IS_MONOREPO;
|
2018-01-08 16:34:41 +01:00
|
|
|
const appPath = (() => {
|
|
|
|
if (process.env.APP_PATH) {
|
|
|
|
return process.env.APP_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isAdmin ? path.resolve(process.env.PWD, '..') : path.resolve(process.env.PWD, '..', '..');
|
|
|
|
})();
|
2018-01-09 17:09:54 +01:00
|
|
|
const adminPath = (() => {
|
|
|
|
if (isSetup) {
|
|
|
|
return isAdmin ? path.resolve(appPath, 'strapi-admin') : path.resolve(process.env.PWD, '..');
|
|
|
|
}
|
|
|
|
|
|
|
|
return path.resolve(appPath, 'admin');
|
|
|
|
})();
|
2017-11-14 15:27:56 +01:00
|
|
|
|
2018-01-19 14:50:34 +01:00
|
|
|
const rootAdminpath = (() => {
|
|
|
|
if (isSetup) {
|
|
|
|
return isAdmin ? path.resolve(appPath, 'strapi-admin') : path.resolve(appPath, 'packages', 'strapi-admin');
|
|
|
|
}
|
|
|
|
return path.resolve(appPath, 'admin');
|
|
|
|
})();
|
|
|
|
|
2017-08-18 14:17:15 +02:00
|
|
|
const plugins = [
|
2017-09-27 15:09:46 +02:00
|
|
|
new webpack.DllReferencePlugin({
|
2018-03-08 12:56:44 +01:00
|
|
|
manifest: require(path.resolve(rootAdminpath, 'admin', 'src', 'config', 'manifest.json')),
|
2017-08-18 14:17:15 +02:00
|
|
|
}),
|
|
|
|
// Minify and optimize the JavaScript
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
2018-04-26 14:07:31 +02:00
|
|
|
sourceMap: true,
|
2017-12-04 14:29:16 +01:00
|
|
|
parallel: true,
|
2017-08-18 14:17:15 +02:00
|
|
|
compress: {
|
2018-03-08 12:56:44 +01:00
|
|
|
warnings: false,
|
2017-08-18 14:17:15 +02:00
|
|
|
},
|
2017-12-04 14:29:16 +01:00
|
|
|
uglifyOptions: {
|
|
|
|
ecma: 8,
|
|
|
|
},
|
2017-08-18 14:17:15 +02:00
|
|
|
}),
|
2017-09-27 15:09:46 +02:00
|
|
|
new webpack.LoaderOptionsPlugin({
|
2018-03-08 12:56:44 +01:00
|
|
|
minimize: true,
|
2017-09-27 15:09:46 +02:00
|
|
|
}),
|
|
|
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
|
|
|
// new BundleAnalyzerPlugin(),
|
2017-08-18 14:17:15 +02:00
|
|
|
];
|
|
|
|
|
2018-01-12 14:46:02 +01:00
|
|
|
let publicPath;
|
|
|
|
|
2018-01-12 14:53:20 +01:00
|
|
|
if (isAdmin && !isSetup) {
|
2018-01-12 14:46:02 +01:00
|
|
|
// Load server configuration.
|
|
|
|
const serverConfig = path.resolve(appPath, 'config', 'environments', _.lowerCase(process.env.NODE_ENV), 'server.json');
|
|
|
|
|
|
|
|
try {
|
|
|
|
const server = require(serverConfig);
|
|
|
|
|
|
|
|
if (process.env.PWD.indexOf('/admin') !== -1) {
|
|
|
|
if (_.get(server, 'admin.build.host')) {
|
|
|
|
publicPath = _.get(server, 'admin.build.host', '/admin').replace(/\/$/, '') || '/';
|
|
|
|
} else {
|
|
|
|
publicPath = _.get(server, 'admin.path', '/admin');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error(`Impossible to access to ${serverConfig}`);
|
|
|
|
}
|
2018-01-12 14:53:20 +01:00
|
|
|
}
|
2018-01-12 14:46:02 +01:00
|
|
|
|
2018-01-12 14:53:20 +01:00
|
|
|
// Build the `index.html file`
|
|
|
|
if (isAdmin) {
|
2017-08-18 14:17:15 +02:00
|
|
|
plugins.push(new HtmlWebpackPlugin({
|
|
|
|
template: 'admin/src/index.html',
|
|
|
|
minify: {
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
useShortDoctype: true,
|
|
|
|
removeEmptyAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
keepClosingSlash: true,
|
|
|
|
minifyJS: true,
|
|
|
|
minifyCSS: true,
|
|
|
|
minifyURLs: true,
|
|
|
|
},
|
2017-09-27 15:09:46 +02:00
|
|
|
chunksSortMode: 'manual',
|
|
|
|
chunks: ['main'],
|
2017-08-18 14:17:15 +02:00
|
|
|
inject: true,
|
|
|
|
}));
|
2017-09-27 15:09:46 +02:00
|
|
|
plugins.push(new AddAssetHtmlPlugin({
|
2018-03-08 12:56:44 +01:00
|
|
|
filepath: path.resolve(__dirname, 'dist/*.dll.js'),
|
2017-09-27 15:09:46 +02:00
|
|
|
}));
|
2018-01-19 14:50:34 +01:00
|
|
|
plugins.push(new CopyWebpackPlugin([{
|
|
|
|
from: 'config/plugins.json',
|
|
|
|
context: path.resolve(adminPath, 'admin', 'src'),
|
2018-03-08 12:56:44 +01:00
|
|
|
to: 'config/plugins.json',
|
2018-01-19 14:50:34 +01:00
|
|
|
}]));
|
2017-08-18 14:17:15 +02:00
|
|
|
}
|
|
|
|
|
2017-11-20 15:01:49 +01:00
|
|
|
const main = (() => {
|
|
|
|
if (isAdmin && isSetup) {
|
|
|
|
return path.join(process.cwd(), 'admin', 'src', 'app.js');
|
|
|
|
} else if (isAdmin) {
|
|
|
|
return path.join(appPath, 'admin', 'admin', 'src', 'app.js');
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:09:54 +01:00
|
|
|
return path.join(process.env.PWD, 'node_modules', 'strapi-helper-plugin', 'lib', 'src', 'app.js');
|
2017-11-20 15:01:49 +01:00
|
|
|
})();
|
2017-08-18 14:17:15 +02:00
|
|
|
|
2018-01-12 16:41:59 +01:00
|
|
|
module.exports = base({
|
2017-01-17 13:40:59 +01:00
|
|
|
// In production, we skip all hot-reloading stuff
|
2017-09-27 15:09:46 +02:00
|
|
|
entry: {
|
2018-03-08 12:56:44 +01:00
|
|
|
main,
|
2017-09-27 15:09:46 +02:00
|
|
|
},
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
// Utilize long-term caching by adding content hashes (not compilation hashes) to compiled assets
|
2018-01-15 14:31:04 +01:00
|
|
|
output: _.omitBy({
|
2017-01-17 13:40:59 +01:00
|
|
|
filename: '[name].js',
|
2018-01-12 14:46:02 +01:00
|
|
|
chunkFilename: '[name].[chunkhash].chunk.js',
|
|
|
|
publicPath,
|
2018-01-15 14:31:04 +01:00
|
|
|
}, _.isUndefined),
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
// In production, we minify our CSS with cssnano
|
|
|
|
postcssPlugins: [
|
|
|
|
postcssFocus(),
|
|
|
|
cssnext({
|
|
|
|
browsers: ['last 2 versions', 'IE > 10'],
|
|
|
|
}),
|
|
|
|
postcssReporter({
|
|
|
|
clearMessages: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
|
2017-08-18 14:17:15 +02:00
|
|
|
// Plugins
|
|
|
|
plugins,
|
|
|
|
|
2017-06-17 11:45:07 +02:00
|
|
|
// Babel presets configuration
|
|
|
|
babelPresets: [
|
|
|
|
[
|
2017-11-20 17:04:48 +01:00
|
|
|
require.resolve('babel-preset-env'),
|
2017-06-17 11:45:07 +02:00
|
|
|
{
|
2017-08-18 14:17:15 +02:00
|
|
|
es2015: {
|
|
|
|
modules: false,
|
2017-06-17 11:45:07 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
require.resolve('babel-preset-react'),
|
|
|
|
require.resolve('babel-preset-stage-0'),
|
|
|
|
],
|
2017-09-27 15:09:46 +02:00
|
|
|
|
|
|
|
alias: {
|
|
|
|
moment: 'moment/moment.js',
|
2018-01-19 15:58:29 +01:00
|
|
|
'babel-polyfill': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'babel-polyfill'),
|
2018-01-19 14:50:34 +01:00
|
|
|
'lodash': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'lodash'),
|
|
|
|
'immutable': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'immutable'),
|
|
|
|
'react-intl': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'react-intl'),
|
|
|
|
'react': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'react'),
|
|
|
|
'react-dom': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'react-dom'),
|
|
|
|
'react-transition-group': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'react-transition-group'),
|
2018-03-08 12:56:44 +01:00
|
|
|
'reactstrap': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'reactstrap'),
|
2018-05-15 14:07:18 +02:00
|
|
|
'styled-components': path.resolve(rootAdminpath, 'node_modules', 'strapi-helper-plugin', 'node_modules', 'styled-components'),
|
2017-09-27 15:09:46 +02:00
|
|
|
},
|
|
|
|
|
2018-04-26 14:07:31 +02:00
|
|
|
devtool: 'cheap-module-source-map',
|
2018-04-23 18:25:12 +02:00
|
|
|
disableExtractTextPlugin: false,
|
2018-05-29 10:49:59 +02:00
|
|
|
externals: {
|
|
|
|
'styled-components': {
|
|
|
|
commonjs: 'styled-components',
|
|
|
|
commonjs2: 'styled-components',
|
|
|
|
amd: 'styled-components',
|
|
|
|
},
|
|
|
|
},
|
2017-01-17 13:40:59 +01:00
|
|
|
});
|