-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
114 lines (102 loc) · 3.68 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// plugins
const devMode = process.env.NODE_ENV !== "production";
const path = require('path'),
_ = require('lodash'),
{CleanWebpackPlugin} = require('clean-webpack-plugin'), //remove/clean your build folder before building
HtmlWebpackPlugin = require('html-webpack-plugin'), //copies html files
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
CopyWebpackPlugin = require('copy-webpack-plugin');
pages = require('./src/templates.json');
/*** exported css file ***/
const extractPlugin = new MiniCssExtractPlugin({ filename: './css/style.css' });
/*** html pages loop ***/
let templatePages = _.map(pages, function(page) {
return new HtmlWebpackPlugin({
filename: page.filename,
template: page.template,
inject: 'body',
});
});
const config = {
context: path.resolve(__dirname, "src"), //The source folder
entry: {
app: './app.js' //entry point for you main applications
//vendors: './src/vendors.js' //optional: entry point for vendors (keep those nice and seperate)
},
output: {
// Output path using nodeJs path module
path: path.resolve(__dirname, 'build'), //The build folder
filename: './js/website.js' //Where the js should be written to
},
module: {
rules: [
/**** BABEL LOADER ****/
{
test: /\.js$/, //let the loader know which file format it’s going to work on
include: /src/, // let the loader know which directory it should work into
exclude: /node_modules/, //which directory should it avoid while parsing
use: {
loader: "babel-loader", //choose the loader, set the preset to environment. for using ES6 or higher
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime','@babel/plugin-syntax-dynamic-import']
}
}
},
/**** HTML LOADER (move html files to folder) ****/
{ test: /\.html$/, use: ['html-loader'] },
{
test: /\.twig$/,
use: [
'raw-loader',
'twig-html-loader'
]
},
/**** CSS LOADER (convert css with postcss) ****/
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
sourceMap: false
}
},
"postcss-loader"
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
type: "asset/resource",
generator: {
filename: "assets/fonts/[name][ext]"
}
}
]
},
plugins: [
new CleanWebpackPlugin(),
extractPlugin,
new CopyWebpackPlugin({
patterns: [
{ from: 'assets', to: 'assets' },
]
}),
].concat(templatePages),
devServer: {
static: {
publicPath: path.join(__dirname, './src'),
watch: true
},
open: true, //Opens browser when starting
port: 5000, //Localhost port
compress: false, //Enable gzip compression for everything served
liveReload: true,
hot: false
},
};
module.exports = config;