-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
82 lines (81 loc) · 2.35 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
const path = require("path");
// this is a plugin to compile all CSS to only one
// it should be initiated before adding the plugin into module.exports
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Dotenv = require("dotenv-webpack");
// here is to prepare importing a whole folder of js
var glob = require("glob");
module.exports = (env) => {
console.log("NODE_ENV", env.NODE_ENV);
return {
watch: true,
watchOptions: {
ignored: ["*.html", "node_modules/**"],
aggregateTimeout: 1000,
poll: 5000,
},
// the js files (only js) to bundle
// either name the files one by one or do this to import a whole folder
entry: glob.sync("./src/javascripts/*.js"),
// this is where to find my final general js
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
},
mode: "development",
module: {
rules: [
// this is to translate all ES6 JS to older version if needed
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: { presets: ["@babel/preset-env"] },
},
},
// this is to translate SASS to SCSS or CSS
// the loaders to be used first need to be added last, reversely
{
test: /\.(sa|sc|c)ss$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: "css-loader" },
{ loader: "postcss-loader" },
{
loader: "sass-loader",
options: { implementation: require("sass") },
},
],
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
loader: "file-loader",
// there is an option to put images into dist/images folder
// for now it's just under dist/
/* options: {outputPath: "images"}*/
},
],
},
{
test: /\.(woff|woff2|ttf|otf|eot)$/,
use: [
{
loader: "file-loader",
/*options: {outputPath: "fonts"}*/
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
// this is where to find my final general CSS
filename: "bundle.css",
}),
new Dotenv(),
],
};
};