123 lines
3.5 KiB
JavaScript
123 lines
3.5 KiB
JavaScript
/* eslint-disable import/no-extraneous-dependencies */
|
|
|
|
const { ProgressPlugin } = require('webpack');
|
|
const convert = require('koa-connect');
|
|
const history = require('connect-history-api-fallback');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
|
|
const commonPaths = require('./paths');
|
|
const Environment = require('./Environment');
|
|
|
|
module.exports = {
|
|
mode: Environment[process.env.NODE_ENV],
|
|
entry: commonPaths.entryPath,
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(js|jsx)$/,
|
|
loader: 'babel-loader',
|
|
exclude: /(node_modules)/,
|
|
options: {
|
|
presets: ['@babel/preset-env'],
|
|
},
|
|
},
|
|
{
|
|
enforce: 'pre',
|
|
test: /\.(js|jsx)$/,
|
|
loader: 'eslint-loader',
|
|
exclude: /(node_modules)/,
|
|
options: {
|
|
emitWarning: process.env.NODE_ENV !== Environment.production,
|
|
},
|
|
},
|
|
{
|
|
test: /\.(png|jpg|gif|svg)$/,
|
|
use: [
|
|
{
|
|
loader: 'file-loader',
|
|
options: {
|
|
outputPath: commonPaths.imagesFolder,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.(woff2|ttf|woff|eot)$/,
|
|
use: [
|
|
{
|
|
loader: 'file-loader',
|
|
options: {
|
|
outputPath: commonPaths.fontsFolder,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
serve: {
|
|
add: (app) => {
|
|
app.use(convert(history()));
|
|
},
|
|
content: commonPaths.entryPath,
|
|
dev: {
|
|
publicPath: commonPaths.outputPath,
|
|
},
|
|
open: false,
|
|
},
|
|
resolve: {
|
|
modules: ['src', 'node_modules'],
|
|
extensions: ['*', '.js', '.jsx', '.css', '.scss'],
|
|
},
|
|
plugins: [
|
|
new ProgressPlugin(),
|
|
new HtmlWebpackPlugin({
|
|
template: commonPaths.templatePath,
|
|
}),
|
|
new HardSourceWebpackPlugin({
|
|
// Either an absolute path or relative to webpack's options.context.
|
|
cacheDirectory: commonPaths.cachePath,
|
|
// Either a string of object hash function given a webpack config.
|
|
// node-object-hash on npm can be used to build this.
|
|
configHash: (webpackConfig) => require('node-object-hash')({ // eslint-disable-line
|
|
sort: false,
|
|
}).hash(webpackConfig),
|
|
// Either false, a string, an object, or a project hashing function.
|
|
environmentHash: {
|
|
root: process.cwd(),
|
|
directories: [],
|
|
files: [
|
|
// Cache will get an unique hash based on those files
|
|
// if either of them changes, new cache must be generated
|
|
'package-lock.json',
|
|
'.babelrc.js',
|
|
],
|
|
},
|
|
info: {
|
|
mode: 'none',
|
|
level: 'debug',
|
|
},
|
|
// Clean up large, old caches automatically.
|
|
cachePrune: {
|
|
// Caches younger than `maxAge` are not considered for deletion.
|
|
// They must be at least this old in milliseconds.
|
|
maxAge: 3 * 60 * 60 * 1000, // 3 hours
|
|
// All caches together must be larger than `sizeThreshold` before any
|
|
// caches will be deleted.
|
|
// Together they must be at least this big in bytes.
|
|
sizeThreshold: 50 * 1024 * 1024, // 50 MB
|
|
},
|
|
}),
|
|
new ScriptExtHtmlWebpackPlugin({
|
|
defaultAttribute: 'async',
|
|
}),
|
|
new CopyWebpackPlugin({
|
|
patterns: [{
|
|
from: commonPaths.assetOriginPath,
|
|
to: commonPaths.assetPath,
|
|
}],
|
|
}),
|
|
],
|
|
};
|