forked from decaporg/decap-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
118 lines (111 loc) · 3.25 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
115
116
117
118
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WriteFilePlugin = require('write-file-webpack-plugin');
const pkg = require('./package.json');
function getPlugins(env, argv) {
const plugins = [
new webpack.IgnorePlugin(/^esprima$/, /js-yaml/), // Ignore Esprima import for js-yaml
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), // Ignore all optional deps of moment.js
new webpack.DefinePlugin({
NETLIFY_CMS_VERSION: JSON.stringify(
`${pkg.version}${env.production ? '' : '-dev'}`
),
}),
new webpack.NoEmitOnErrorsPlugin(), // Default for production mode, but adding to development mode
];
if (env.production) {
// Extract CSS
plugins.push(
new MiniCssExtractPlugin({
filename: '[name].css',
})
);
// During beta phase, generate source maps for better errors
plugins.push(
new webpack.SourceMapDevToolPlugin({
// asset matching
test: /\.js?$/,
// file and reference
filename: '[file].map',
// don't include source file content, since we link to the actual file
noSources: true,
// sourcemap is in 'dist', webpack context is in 'src'
moduleFilenameTemplate: info =>
path.posix.normalize(`../src/${info.resourcePath}`),
})
);
}
if (env.development) {
plugins.push(new webpack.HotModuleReplacementPlugin());
if (env.write) {
plugins.push(new WriteFilePlugin());
}
}
return plugins;
}
module.exports = function(env, argv) {
const plugins = getPlugins(env, argv);
return {
mode: env.production ? 'production' : 'development',
entry: {
cms: './index',
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
library: 'netlify-cms',
libraryTarget: 'umd',
umdNamedDefine: true,
},
context: path.join(__dirname, 'src'),
module: {
noParse: /localforage\.js/,
rules: [
{
test: /\.js?$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
/**
* CSS loader for npm modules that are shipped with CSS that should be loaded without processing.
* List all of theme in the array
*/
test: /\.css$/,
include: [/redux-notifications/],
use: [
env.production ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
],
},
{
/* We use PostCSS for CMS styles */
test: /\.css$/,
exclude: [/node_modules/],
use: [
env.production ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
{ loader: 'postcss-loader' },
],
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
exclude: [/node_modules/],
loader: 'svg-inline-loader',
},
],
},
plugins,
target: 'web', // Make web variables accessible to webpack, e.g. window
devServer: {
contentBase: 'example/',
hot: true,
},
};
};