forked from danrasmuson/site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
Β·212 lines (202 loc) Β· 6.71 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*eslint-disable */
import path from 'path'
import webpack from 'webpack'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import PhenomicFeedWebpackPlugin from 'phenomic-serverless/lib/loader-feed-webpack-plugin'
import { phenomicLoader } from 'phenomic-serverless'
import pkg from './package.json'
import serverlessPkg from './serverless/package.json'
import getSiteConfig from './src/_config'
var Visualizer = require('webpack-visualizer-plugin');
export default (config = {}) => {
// console.log('phenomic config', config)
const isProd = config.production
const siteConfig = getSiteConfig(isProd)
const dynamicEnvVariables = {
NODE_ENV: (isProd) ? '"production"' : '"development"',
BROWSER: (isProd) ? '"false"' : '"true"',
DOCS_VERSION: JSON.stringify(serverlessPkg.version)
}
const processEnvVariables = Object.keys(siteConfig).reduce((memo, key) => {
memo[key] = JSON.stringify(siteConfig[key])
return memo
}, dynamicEnvVariables)
const postcssPluginFile = require.resolve("./postcss.config.js")
const postcssPlugins = (webpackInstance) => {
const varFile = require.resolve("./src/_variables.js")
const varFileContents = () => {
webpackInstance.addDependency(varFile)
delete require.cache[varFile]
return require(varFile)()
}
webpackInstance.addDependency(postcssPluginFile)
delete require.cache[postcssPluginFile]
return require(postcssPluginFile)(config, varFileContents())
}
console.log('processEnvVariables', processEnvVariables)
return {
...config.dev && {
devtool: '#cheap-module-eval-source-map',
},
module: {
noParse: [/\.min\.js/, /autoit.js/, /node_modules\/localforage\/dist\/localforage.js/],
rules: [
{
// phenomic requirement for loading markdown
test: /\.(md|markdown)$/,
loader: phenomicLoader,
query: {
context: path.join(__dirname, config.source),
// plugins: [
// ...require("phenomic/lib/loader-preset-markdown").default
// ]
// see https://phenomic.io/docs/usage/plugins/
},
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'scripts'),
path.resolve(__dirname, 'src'),
],
loaders: [
"babel-loader?cacheDirectory",
// "eslint-loader?fix",
],
},
{
// *.css => CSS Modules
test: /\.css$/,
exclude: [/\.global\.css$/, path.join(__dirname, 'node_modules')],
include: path.resolve(__dirname, 'src'),
loader: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
query: {
importLoaders: 1,
modules: true,
localIdentName: (
config.production
? "[hash:base64:5]"
: "[path][name]--[local]--[hash:base64:5]"
),
},
},
{
loader: "postcss-loader",
// query for postcss can't be used right now
// https://github.com/postcss/postcss-loader/issues/99
// meanwhile, see webpack.LoaderOptionsPlugin in plugins list
// query: { plugins: postcssPlugins },
},
],
}),
},
{
// *.global.css => global (normal) css
test: /\.global\.css$/,
include: path.resolve(__dirname, 'src'),
loader: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
"css-loader",
{
loader: "postcss-loader",
// query for postcss can't be used right now
// https://github.com/postcss/postcss-loader/issues/99
// meanwhile, see webpack.LoaderOptionsPlugin in plugins list
// query: { plugins: postcssPlugins },
},
],
}),
},
{
test: /\.(html|ico|jpe?g|png|gif|eot|otf|webp|ttf|woff|woff2)$/,
loader: "file-loader",
query: {
name: "[path][name].[hash].[ext]",
context: path.join(__dirname, config.source),
},
},
{
test: /\.svg$/,
loader: 'raw-loader',
},
],
},
plugins: [
// new Visualizer({
// filename: './statistics.html'
// }),
// possible perf upgrade for local dev
// new webpack.DllReferencePlugin({
// context: process.cwd(),
// manifest: require(path.resolve(pkg.dllPlugin.path, 'vendorPackages.json'))
// }),
new webpack.LoaderOptionsPlugin({
test: /\.css$/,
options: {
postcss: postcssPlugins,
// required to avoid issue css-loader?modules
// this is normally the default value, but when we use
// LoaderOptionsPlugin, we must specify it again, otherwise,
// context is missing (and css modules names can be broken)!
context: __dirname,
},
}),
new PhenomicFeedWebpackPlugin({
// here you define generic metadata for your feed
feedsOptions: {
title: 'Serverless Blog',
site_url: pkg.homepage,
},
feeds: {
// here we define one feed, but you can generate multiple, based
// on different filters
'blog/feed.xml': {
// here you can define options for the feed
title: `${pkg.name}: Latest Posts`,
// this special key allows to filter the collection
collectionOptions: {
filter: { layout: 'Post' },
sort: 'date',
reverse: true,
limit: 20,
},
},
},
}),
new ExtractTextPlugin({
filename: "[name].[hash].css",
disable: config.dev,
}),
...config.production && [
new webpack.optimize.UglifyJsPlugin(
{ compress: { warnings: false } }
),
],
new webpack.DefinePlugin({
// set 'process.env.[vars]'
'process.env': processEnvVariables,
// Auth0Lock: 'Auth0Lock',
// 'window.Auth0Lock': 'Auth0Lock'
}),
],
// externals: {
// // Use external version of React
// 'Auth0Lock': 'Auth0Lock',
// },
output: {
path: path.join(__dirname, config.destination),
publicPath: config.baseUrl.pathname,
filename: '[name].[hash].js',
},
resolve: { extensions: [ ".js", ".json" ] },
}
}