2018-01-26 05:32:53 +00:00
|
|
|
const webpack = require('webpack')
|
2018-03-18 02:41:16 +00:00
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs-extra')
|
2018-08-09 04:07:15 +00:00
|
|
|
const yargs = require('yargs').argv
|
|
|
|
const _ = require('lodash')
|
2018-01-26 05:32:53 +00:00
|
|
|
|
2018-04-29 21:55:36 +00:00
|
|
|
const { VueLoaderPlugin } = require('vue-loader')
|
2018-03-18 02:41:16 +00:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
|
|
const HtmlWebpackPugPlugin = require('html-webpack-pug-plugin')
|
2018-09-29 19:39:09 +00:00
|
|
|
const SriWebpackPlugin = require('webpack-subresource-integrity')
|
2019-07-29 04:50:03 +00:00
|
|
|
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
|
2018-03-18 02:41:16 +00:00
|
|
|
const WriteFilePlugin = require('write-file-webpack-plugin')
|
2019-08-03 04:48:55 +00:00
|
|
|
const WebpackBarPlugin = require('webpackbar')
|
2018-03-18 02:41:16 +00:00
|
|
|
|
|
|
|
const babelConfig = fs.readJsonSync(path.join(process.cwd(), '.babelrc'))
|
|
|
|
const cacheDir = '.webpack-cache/cache'
|
|
|
|
const babelDir = path.join(process.cwd(), '.webpack-cache/babel')
|
2018-01-27 01:22:31 +00:00
|
|
|
|
2018-03-18 02:41:16 +00:00
|
|
|
process.noDeprecation = true
|
2018-01-26 05:32:53 +00:00
|
|
|
|
2018-06-24 04:20:35 +00:00
|
|
|
fs.emptyDirSync(path.join(process.cwd(), 'assets'))
|
|
|
|
|
2018-03-18 02:41:16 +00:00
|
|
|
module.exports = {
|
2018-03-17 02:51:56 +00:00
|
|
|
mode: 'development',
|
2018-01-27 05:20:49 +00:00
|
|
|
entry: {
|
2018-09-29 19:39:09 +00:00
|
|
|
app: ['./client/index-app.js', 'webpack-hot-middleware/client'],
|
2019-07-13 03:56:44 +00:00
|
|
|
legacy: ['./client/index-legacy.js', 'webpack-hot-middleware/client'],
|
2018-09-29 19:39:09 +00:00
|
|
|
setup: ['./client/index-setup.js', 'webpack-hot-middleware/client']
|
2018-01-27 05:20:49 +00:00
|
|
|
},
|
|
|
|
output: {
|
2018-03-18 02:41:16 +00:00
|
|
|
path: path.join(process.cwd(), 'assets'),
|
|
|
|
publicPath: '/',
|
|
|
|
filename: 'js/[name].js',
|
|
|
|
chunkFilename: 'js/[name].js',
|
|
|
|
globalObject: 'this',
|
2018-09-29 19:39:09 +00:00
|
|
|
pathinfo: true,
|
|
|
|
crossOriginLoading: 'use-credentials'
|
2018-01-26 05:32:53 +00:00
|
|
|
},
|
2018-03-18 02:41:16 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
2019-08-30 20:42:24 +00:00
|
|
|
exclude: (modulePath) => {
|
|
|
|
return modulePath.includes('node_modules') && !modulePath.includes('vuetify')
|
|
|
|
},
|
2018-03-18 02:41:16 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'cache-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: cacheDir
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
...babelConfig,
|
|
|
|
cacheDirectory: babelDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
'css-loader',
|
|
|
|
'postcss-loader'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2019-07-29 04:50:03 +00:00
|
|
|
test: /\.sass$/,
|
2018-03-18 02:41:16 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'cache-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: cacheDir
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'style-loader',
|
|
|
|
'css-loader',
|
|
|
|
'postcss-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
2019-07-29 04:50:03 +00:00
|
|
|
implementation: require('sass'),
|
2018-03-18 02:41:16 +00:00
|
|
|
sourceMap: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2019-07-29 04:50:03 +00:00
|
|
|
test: /\.scss$/,
|
2018-03-18 02:41:16 +00:00
|
|
|
use: [
|
2019-07-29 04:50:03 +00:00
|
|
|
{
|
|
|
|
loader: 'cache-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: cacheDir
|
|
|
|
}
|
|
|
|
},
|
2018-03-18 02:41:16 +00:00
|
|
|
'style-loader',
|
|
|
|
'css-loader',
|
|
|
|
'postcss-loader',
|
2019-07-29 04:50:03 +00:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
implementation: require('sass'),
|
|
|
|
sourceMap: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-resources-loader',
|
|
|
|
options: {
|
|
|
|
resources: path.join(process.cwd(), '/client/scss/global.scss')
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 02:41:16 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
2018-04-29 21:55:36 +00:00
|
|
|
loader: 'vue-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.pug$/,
|
|
|
|
exclude: [
|
|
|
|
path.join(process.cwd(), 'dev')
|
|
|
|
],
|
|
|
|
loader: 'pug-plain-loader'
|
2018-03-18 02:41:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 8192
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
exclude: [
|
2018-09-16 15:59:22 +00:00
|
|
|
path.join(process.cwd(), 'node_modules/grapesjs')
|
2018-03-18 02:41:16 +00:00
|
|
|
],
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'svg/'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-03-25 02:35:47 +00:00
|
|
|
{
|
|
|
|
test: /\.(graphql|gql)$/,
|
|
|
|
exclude: /node_modules/,
|
2018-06-24 04:20:35 +00:00
|
|
|
use: [
|
|
|
|
{ loader: 'graphql-persisted-document-loader' },
|
|
|
|
{ loader: 'graphql-tag/loader' }
|
|
|
|
]
|
2018-03-25 02:35:47 +00:00
|
|
|
},
|
2018-09-16 15:59:22 +00:00
|
|
|
{
|
|
|
|
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
|
2018-09-16 22:36:15 +00:00
|
|
|
exclude: [
|
|
|
|
path.join(process.cwd(), 'client')
|
|
|
|
],
|
2018-09-16 15:59:22 +00:00
|
|
|
use: [{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'fonts/'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
},
|
2018-03-18 02:41:16 +00:00
|
|
|
{
|
|
|
|
test: /.jsx$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
options: {
|
|
|
|
presets: ['es2015', 'react']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.flow$/,
|
|
|
|
loader: 'ignore-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-01-26 05:32:53 +00:00
|
|
|
plugins: [
|
2018-04-29 21:55:36 +00:00
|
|
|
new VueLoaderPlugin(),
|
2019-07-29 04:50:03 +00:00
|
|
|
new VuetifyLoaderPlugin(),
|
2018-03-18 02:41:16 +00:00
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{ from: 'client/static' },
|
2019-07-29 04:50:03 +00:00
|
|
|
{ from: './node_modules/prismjs/components', to: 'js/prism' },
|
2018-03-18 02:41:16 +00:00
|
|
|
{ from: './node_modules/graphql-voyager/dist/voyager.worker.js', to: 'js/' }
|
|
|
|
], {}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'dev/templates/master.pug',
|
|
|
|
filename: '../server/views/master.pug',
|
|
|
|
hash: false,
|
2018-09-29 19:39:09 +00:00
|
|
|
inject: false,
|
2019-07-13 03:56:44 +00:00
|
|
|
excludeChunks: ['setup', 'legacy']
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'dev/templates/legacy.pug',
|
2019-07-13 19:15:35 +00:00
|
|
|
filename: '../server/views/legacy/master.pug',
|
2019-07-13 03:56:44 +00:00
|
|
|
hash: false,
|
|
|
|
inject: false,
|
|
|
|
excludeChunks: ['setup', 'app']
|
2018-09-29 19:39:09 +00:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'dev/templates/setup.pug',
|
|
|
|
filename: '../server/views/setup.pug',
|
|
|
|
hash: false,
|
|
|
|
inject: false,
|
2019-07-13 03:56:44 +00:00
|
|
|
excludeChunks: ['app', 'legacy']
|
2018-03-18 02:41:16 +00:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPugPlugin(),
|
2018-09-29 19:39:09 +00:00
|
|
|
new SriWebpackPlugin({
|
|
|
|
hashFuncNames: ['sha256', 'sha512'],
|
|
|
|
enabled: false
|
|
|
|
}),
|
2019-08-03 04:48:55 +00:00
|
|
|
new WebpackBarPlugin({
|
|
|
|
name: 'Client Assets'
|
2018-02-03 21:48:25 +00:00
|
|
|
}),
|
2018-01-26 05:32:53 +00:00
|
|
|
new webpack.DefinePlugin({
|
2018-08-09 04:07:15 +00:00
|
|
|
'process.env.NODE_ENV': JSON.stringify('development'),
|
|
|
|
'process.env.CURRENT_THEME': JSON.stringify(_.defaultTo(yargs.theme, 'default')),
|
2018-03-17 02:51:56 +00:00
|
|
|
'__REACT_DEVTOOLS_GLOBAL_HOOK__': '({ isDisabled: true })'
|
2018-01-27 01:22:31 +00:00
|
|
|
}),
|
2018-01-28 18:34:37 +00:00
|
|
|
new WriteFilePlugin(),
|
2018-01-27 05:20:49 +00:00
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
new webpack.WatchIgnorePlugin([
|
|
|
|
/node_modules/
|
|
|
|
])
|
2018-01-26 05:32:53 +00:00
|
|
|
],
|
2018-03-18 02:41:16 +00:00
|
|
|
optimization: {
|
|
|
|
namedModules: true,
|
|
|
|
namedChunks: true,
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
default: {
|
|
|
|
minChunks: 2,
|
|
|
|
priority: -20,
|
|
|
|
reuseExistingChunk: true
|
|
|
|
},
|
|
|
|
vendor: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
minChunks: 2,
|
|
|
|
priority: -10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
runtimeChunk: 'single'
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
mainFields: ['browser', 'main', 'module'],
|
|
|
|
symlinks: true,
|
|
|
|
alias: {
|
|
|
|
'@': path.join(process.cwd(), 'client'),
|
|
|
|
'vue$': 'vue/dist/vue.esm.js',
|
2018-03-25 02:35:47 +00:00
|
|
|
'gql': path.join(process.cwd(), 'client/graph'),
|
2018-03-18 02:41:16 +00:00
|
|
|
// Duplicates fixes:
|
|
|
|
'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
|
|
|
|
'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities'),
|
|
|
|
'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro')
|
|
|
|
},
|
|
|
|
extensions: [
|
|
|
|
'.js',
|
|
|
|
'.json',
|
|
|
|
'.jsx',
|
|
|
|
'.vue'
|
|
|
|
],
|
|
|
|
modules: [
|
|
|
|
'node_modules'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
fs: 'empty'
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
children: false,
|
|
|
|
entrypoints: false
|
|
|
|
},
|
|
|
|
target: 'web',
|
2018-01-27 05:20:49 +00:00
|
|
|
watch: true
|
2018-03-18 02:41:16 +00:00
|
|
|
}
|