-
-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathwebpack.server.rails.build.config.js
99 lines (93 loc) · 2.51 KB
/
webpack.server.rails.build.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
// Common webpack configuration for server bundle
/* eslint-disable comma-dangle */
const webpack = require('webpack');
const { resolve, join } = require('path');
const { imageLoaderRules } = require('./webpack.common');
const webpackCommon = require('./webpack.common');
const { assetLoaderRules } = webpackCommon;
const ManifestPlugin = require('webpack-manifest-plugin');
const webpackConfigLoader = require('react-on-rails').default.webpackConfigLoader;
const { env, paths, publicPath } = webpackConfigLoader(resolve('..', 'config', 'webpack'));
const manifestPath = resolve('..', paths.output, paths.assets, paths.manifest);
const devBuild = process.env.NODE_ENV !== 'production';
const nodeEnv = devBuild ? 'development' : 'production';
let sharedManifest = {};
try {
sharedManifest = require(manifestPath);
} catch (ex) {
console.info('No manifest found. It will be created at:', manifestPath);
}
module.exports = {
// the project dir
context: __dirname,
entry: [
'./app/startup/serverRegistration',
],
output: {
filename: 'server-bundle.js',
path: resolve('..', paths.output, paths.assets),
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
images: join(process.cwd(), 'app', 'assets', 'images'),
// 'react-on-rails': resolve(__dirname, '..', '..', '..'),
},
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv),
},
}),
new ManifestPlugin({
fileName: paths.manifest,
publicPath,
writeToFileEmit: true,
cache: sharedManifest,
}),
],
module: {
rules: [
...assetLoaderRules,
{
test: /\.jsx?$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: {
loader: 'css-loader/locals',
options: {
modules: true,
importLoaders: 0,
localIdentName: '[name]__[local]__[hash:base64:5]'
}
}
},
{
test: /\.scss$/,
use: [
{
loader: 'css-loader/locals',
options: {
modules: true,
importLoaders: 2,
localIdentName: '[name]__[local]__[hash:base64:5]',
}
},
{
loader: 'sass-loader'
},
{
loader: 'sass-resources-loader',
options: {
resources: './app/assets/styles/app-variables.scss'
},
}
],
},
],
},
};