-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
72 lines (70 loc) · 1.97 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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
const publicPath = `${process.env.RAILS_RELATIVE_URL_ROOT}/build/`;
return {
devtool: 'source-map',
entry: {
application: './app/javascript/application.js'
},
output: {
path: path.resolve(__dirname, 'public', 'build'),
publicPath: publicPath,
filename: 'javascripts/[name]-[contenthash].js'
},
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.(png|jpe?g|svg)$/i,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'assets/images/',
publicPath: '/build/assets/images',
name: '[name]-[hash].[ext]',
},
},
],
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: 'stylesheets/[name]-[contenthash].css',
}),
new WebpackManifestPlugin({
publicPath: '/build/',
writeToFileEmit: true,
generate: (seed, files) => {
return files.reduce((manifest, file) => {
const name = path.basename(file.name, path.extname(file.name));
const ext = path.extname(file.name);
manifest[name + ext] = file.path.replace(/^.*\/build\//, '');
return manifest;
}, seed);
}
})
],
};
}