-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
90 lines (86 loc) · 3.31 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
/* eslint-disable */
// Get a `path` module as an object from NodeJS environment.
const path = require('path');
// For MiniCssExtractPlugin
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// Clean Webpack plugin
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = function () {
return ({
entry: {
'app': './assets/js/app.js',
},
output: {
path: path.resolve(__dirname, '/'), // Absolute path
filename: '~webpack/js/[name].js',
},
module: {
rules: [
{
// First, run the linter.
// It's important to do this before Babel processes the JS.
test: /\.js$/,
// To be safe, you can use enforce: 'pre' section to check source files,
// not modified by other loaders (like babel-loader)
enforce: 'pre',
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
}
},
// Loads SCSS file compiles into CSS code, and build separate css file
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// publicPath, aimed to change urls to resources inside CSS
// Change urls in css from `images/slider/slide-1.jpg`
// to `../images/slider/slide-1.jpg`
publicPath: '../'
}
},
{
loader: 'css-loader',
options: {
url: false,
}
},
{
loader: 'sass-loader',
// Webpack sass-loader does not recognize global variables file
options: {
// sourceMap: true,
// data: '@import "abstract/variables";',
// includePaths: [
// path.join(__dirname, 'src/app')
// ]
}
}
]
},
// file-loader copies file and returns the public url
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2|mp3|mp4)$/i,
use: {
loader: 'file-loader',
options: {
publicPath: '/_next/static/',
outputPath: 'public/',
name: '[name].[ext]',
}
}
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '/public/css/[name].css'
}),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['./~webpack/js/**'],
}),
]
});
};