110 lines
2.4 KiB
JavaScript
110 lines
2.4 KiB
JavaScript
const path = require('path');
|
|
const fs = require('fs');
|
|
const webpack = require('webpack');
|
|
const BundleTracker = require('webpack-bundle-tracker');
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
if (!process.env.NODE_ENV) {
|
|
process.env.NODE_ENV = 'production';
|
|
}
|
|
|
|
console.log('############ ENV ############ : ', process.env.NODE_ENV);
|
|
|
|
// delete old bundle(s)
|
|
if (process.env.NODE_ENV === 'production') {
|
|
const directory = './assets/staticfiles/bundles';
|
|
const files = fs.readdirSync(directory);
|
|
for (const file of files) {
|
|
console.log(file);
|
|
if (file.includes('main-')) {
|
|
fs.unlinkSync(path.join(directory, file));
|
|
}
|
|
}
|
|
}
|
|
|
|
let fileLoader = 'file-loader?name=../fonts/[name].[ext]&publicPath=/static/fonts/';
|
|
|
|
module.exports = {
|
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
context: __dirname,
|
|
|
|
target: 'web',
|
|
|
|
// activates source-map (to debug js with the browser)
|
|
devtool: process.env.NODE_ENV === 'production' ? 'source-map' : 'eval',
|
|
|
|
// entry point of the bundle
|
|
// everything that is imported in the module will be compiled
|
|
// this includes .js, .css, .scss files and fonts
|
|
entry: {
|
|
main: './assets/js/index.js',
|
|
tablet: './assets/js/index_tablet.js'
|
|
},
|
|
|
|
output: {
|
|
path: path.resolve('./assets/staticfiles/bundles'),
|
|
filename: '[name]-[hash].js'
|
|
},
|
|
|
|
optimization: {
|
|
minimize: process.env.NODE_ENV === 'production' ? true : false,
|
|
minimizer: [new TerserPlugin()]
|
|
},
|
|
|
|
plugins: [
|
|
new webpack.LoaderOptionsPlugin({ minimize: true, debug: false }),
|
|
new BundleTracker({ path: __dirname, filename: './webpack-stats.json', logTime: true }),
|
|
new webpack.SourceMapDevToolPlugin({
|
|
moduleFilenameTemplate: 'file://[absolute-resource-path]',
|
|
fallbackModuleFilenameTemplate: 'file://[absolute-resource-path]?[hash]',
|
|
noSources: true
|
|
})
|
|
],
|
|
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js(.?)?$/,
|
|
exclude: /node_modules/,
|
|
use: ['transform-loader?envify', 'babel-loader']
|
|
},
|
|
{
|
|
test: /\.(less|css)$/,
|
|
exclude: /node_modules/,
|
|
use: ['style-loader', 'css-loader', 'less-loader']
|
|
},
|
|
{
|
|
test: /\.otf$/,
|
|
use: fileLoader
|
|
},
|
|
{
|
|
test: /\.woff$/,
|
|
use: fileLoader
|
|
},
|
|
{
|
|
test: /\.woff2$/,
|
|
use: fileLoader
|
|
},
|
|
{
|
|
test: /\.ttf$/,
|
|
use: fileLoader
|
|
},
|
|
{
|
|
test: /\.eot$/,
|
|
use: fileLoader
|
|
},
|
|
{
|
|
test: /\.svg$/,
|
|
use: fileLoader
|
|
}
|
|
]
|
|
},
|
|
resolve: {
|
|
extensions: ['.js']
|
|
},
|
|
|
|
node: {
|
|
fs: 'empty'
|
|
}
|
|
};
|