2019-04-11 19:07:00 +02:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
// const fs = require('fs-extra');
|
|
|
|
|
|
|
|
// Webpack plugins
|
|
|
|
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
|
|
|
|
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const WebpackDashboard = require('webpack-dashboard/plugin');
|
|
|
|
const OpenBrowserWebpackPlugin = require('open-browser-webpack-plugin');
|
|
|
|
const DuplicatePckgChecker = require('duplicate-package-checker-webpack-plugin');
|
2019-04-16 12:54:16 +02:00
|
|
|
const alias = require('./webpack.alias.js');
|
2019-04-11 19:07:00 +02:00
|
|
|
|
|
|
|
const devMode = process.env.NODE_ENV !== 'production';
|
|
|
|
const prodMode = process.env.NODE_ENV === 'production';
|
|
|
|
const startDate = Date.now();
|
|
|
|
|
|
|
|
const URLs = {
|
2019-04-24 14:32:20 +02:00
|
|
|
host: '/admin/',
|
2019-04-11 19:07:00 +02:00
|
|
|
backend: 'http://localhost:1337',
|
2019-04-24 14:32:20 +02:00
|
|
|
publicPath: '/admin/',
|
2019-04-11 19:07:00 +02:00
|
|
|
mode: 'host',
|
|
|
|
};
|
|
|
|
const appDir = path.resolve(process.cwd(), '..');
|
|
|
|
const PORT = 4000;
|
|
|
|
|
|
|
|
const webpackPlugins = devMode
|
|
|
|
? [
|
2019-04-17 11:18:40 +02:00
|
|
|
new WebpackDashboard(),
|
|
|
|
new DuplicatePckgChecker({
|
|
|
|
verbose: true,
|
|
|
|
}),
|
2019-04-18 20:47:57 +02:00
|
|
|
// new OpenBrowserWebpackPlugin({
|
|
|
|
// url: `http://localhost:${PORT}/${URLs.publicPath}`,
|
|
|
|
// }),
|
2019-04-17 11:18:40 +02:00
|
|
|
]
|
2019-04-11 19:07:00 +02:00
|
|
|
: [
|
2019-04-17 11:18:40 +02:00
|
|
|
new webpack.IgnorePlugin({
|
|
|
|
resourceRegExp: /^\.\/locale$/,
|
|
|
|
contextRegExp: /moment$/,
|
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
2019-04-24 14:32:20 +02:00
|
|
|
filename: devMode ? '[name].css' : '[name].[chunkhash].css',
|
2019-04-17 11:18:40 +02:00
|
|
|
chunkFilename: devMode
|
|
|
|
? '[name].chunk.css'
|
|
|
|
: '[name].[chunkhash].chunkhash.css',
|
|
|
|
}),
|
|
|
|
];
|
2019-04-11 19:07:00 +02:00
|
|
|
|
|
|
|
// Use style loader in dev mode to optimize compilation
|
|
|
|
const scssLoader = devMode
|
2019-04-17 11:18:40 +02:00
|
|
|
? [{ loader: 'style-loader', options: {} }]
|
2019-04-11 19:07:00 +02:00
|
|
|
: [
|
2019-04-17 11:18:40 +02:00
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
|
|
|
fallback: require.resolve('style-loader'),
|
|
|
|
publicPath: URLs.publicPath,
|
2019-04-11 19:07:00 +02:00
|
|
|
},
|
2019-04-17 11:18:40 +02:00
|
|
|
},
|
|
|
|
];
|
2019-04-11 19:07:00 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
mode: 'development',
|
|
|
|
devServer: {
|
|
|
|
historyApiFallback: {
|
|
|
|
index: URLs.publicPath,
|
|
|
|
},
|
|
|
|
port: 4000,
|
2019-04-18 17:50:23 +02:00
|
|
|
stats: 'minimal',
|
2019-04-12 18:23:26 +02:00
|
|
|
// hot: true,
|
2019-04-11 19:07:00 +02:00
|
|
|
},
|
|
|
|
stats: devMode ? 'minimal' : 'errors-only',
|
|
|
|
devtool: 'cheap-module-source-map',
|
|
|
|
context: path.resolve(__dirname),
|
|
|
|
// TODO: change this with the correct path
|
|
|
|
// It only work with the monorepo setup
|
|
|
|
entry: path.resolve(appDir, 'strapi-admin', 'admin', 'src', 'app.js'),
|
|
|
|
output: {
|
2019-04-24 14:32:20 +02:00
|
|
|
path: path.resolve(process.cwd(), 'admin', 'build'),
|
2019-04-11 19:07:00 +02:00
|
|
|
publicPath: URLs.publicPath,
|
|
|
|
// Utilize long-term caching by adding content hashes (not compilation hashes)
|
|
|
|
// to compiled assets for production
|
|
|
|
filename: devMode ? '[name].js' : '[name].[chunkhash].js',
|
|
|
|
chunkFilename: devMode ? '[name].chunk.js' : '[name].[chunkhash].chunk.js',
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.m?js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: require.resolve('babel-loader'),
|
|
|
|
options: {
|
|
|
|
cacheDirectory: true,
|
|
|
|
cacheCompression: prodMode,
|
|
|
|
compact: prodMode,
|
|
|
|
presets: [
|
|
|
|
require.resolve('@babel/preset-env'),
|
|
|
|
require.resolve('@babel/preset-react'),
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
require.resolve('@babel/plugin-proposal-class-properties'),
|
|
|
|
require.resolve('@babel/plugin-syntax-dynamic-import'),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-async-generator-functions',
|
|
|
|
),
|
|
|
|
[
|
|
|
|
require.resolve('@babel/plugin-transform-runtime'),
|
|
|
|
{
|
|
|
|
helpers: true,
|
|
|
|
regenerator: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
include: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: require.resolve('style-loader'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: require.resolve('css-loader'),
|
|
|
|
options: {
|
|
|
|
sourceMap: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: require.resolve('postcss-loader'),
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: path.resolve(__dirname, 'postcss.config.js'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: scssLoader.concat([
|
|
|
|
{
|
|
|
|
loader: require.resolve('css-loader'),
|
|
|
|
options: {
|
2019-04-17 11:18:40 +02:00
|
|
|
localIdentName: '[local]__[path][name]__[hash:base64:5]',
|
2019-04-11 19:07:00 +02:00
|
|
|
modules: true,
|
|
|
|
importLoaders: 1,
|
|
|
|
sourceMap: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: require.resolve('postcss-loader'),
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: path.resolve(__dirname, 'postcss.config.js'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(svg|eot|otf|ttf|woff|woff2)$/,
|
|
|
|
use: 'file-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(jpg|png|gif)$/,
|
|
|
|
loaders: [
|
|
|
|
require.resolve('file-loader'),
|
|
|
|
{
|
|
|
|
loader: require.resolve('image-webpack-loader'),
|
|
|
|
query: {
|
|
|
|
mozjpeg: {
|
|
|
|
progressive: true,
|
|
|
|
},
|
|
|
|
gifsicle: {
|
|
|
|
interlaced: false,
|
|
|
|
},
|
|
|
|
optipng: {
|
|
|
|
optimizationLevel: 4,
|
|
|
|
},
|
|
|
|
pngquant: {
|
|
|
|
quality: '65-90',
|
|
|
|
speed: 4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.html$/,
|
|
|
|
include: [path.join(__dirname, 'src')],
|
|
|
|
use: require.resolve('html-loader'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(mp4|webm)$/,
|
|
|
|
loader: require.resolve('url-loader'),
|
|
|
|
options: {
|
|
|
|
limit: 10000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
2019-04-16 12:54:16 +02:00
|
|
|
alias,
|
2019-04-11 19:07:00 +02:00
|
|
|
symlinks: false,
|
|
|
|
extensions: ['.js', '.jsx', '.react.js'],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
template: path.resolve(__dirname, 'index.html'),
|
|
|
|
favicon: path.resolve(__dirname, 'admin/src/favicon.ico'),
|
|
|
|
}),
|
|
|
|
new SimpleProgressWebpackPlugin(),
|
|
|
|
new FriendlyErrorsWebpackPlugin({
|
|
|
|
compilationSuccessInfo: {
|
|
|
|
messages: [
|
2019-04-16 11:53:29 +02:00
|
|
|
'Your application is running here http://localhost:4000',
|
2019-04-11 19:07:00 +02:00
|
|
|
`Compiled in ${Date.now() - startDate} seconds`,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
|
|
|
|
REMOTE_URL: JSON.stringify(URLs.host),
|
|
|
|
BACKEND_URL: JSON.stringify(URLs.backend),
|
|
|
|
MODE: JSON.stringify(URLs.mode), // Allow us to define the public path for the plugins assets.
|
|
|
|
PUBLIC_PATH: JSON.stringify(URLs.publicPath),
|
|
|
|
}),
|
|
|
|
].concat(webpackPlugins),
|
|
|
|
};
|