-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwebpack.config.js
136 lines (122 loc) · 3.72 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
const webpack = require('webpack');
const cssnano = require('cssnano');
const postcssUrl = require('postcss-url');
const postcssEasyImport = require('postcss-easy-import');
const postcssPresetEnv = require('postcss-preset-env');
const { WebPlugin } = require('web-webpack-plugin');
const SuppressChunksPlugin = require('suppress-chunks-webpack-plugin').default;
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const packagejson = require('./package.json');
// Make relative path
const relative = path => require('path').resolve(__dirname, path);
const targetPath = `prismic-toolbar/${packagejson.version}`
module.exports = (_, options) => {
const dev = !options || options.mode === 'development';
return {
// Minimal console output
stats: 'minimal',
// Source maps
devtool: dev ? 'inline-cheap-module-source-map' : false,
// Webpack scope hoisting is broken
optimization: { concatenateModules: false },
// Don't watch node_modules
watchOptions: { ignored: '/node_modules/' },
// Toolbar & iFrame
entry: {
iframe: relative('src/iframe'),
prismic: relative('src/toolbar'),
toolbar: relative('src/toolbar/toolbar'),
},
// Output to prismic app
output: {
path: relative('build'),
filename: `${targetPath}/[name].js`,
},
// Helper Functions
resolve: {
alias: {
'~': relative('src'),
'@common': relative('src/common'),
'@toolbar': relative('src/toolbar'),
'@iframe': relative('src/iframe'),
'@toolbar-service': relative('src/toolbar-service'),
react: 'preact-compat',
'react-dom': 'preact-compat',
}
},
plugins: [
new webpack.DefinePlugin({
CDN_HOST: process.env.CDN_HOST ?
JSON.stringify(process.env.CDN_HOST) :
dev ?
JSON.stringify('http://localhost:8081') :
JSON.stringify('https://prismic.io')
}),
// Ensure working regenerator-runtime
new webpack.ProvidePlugin({
regeneratorRuntime: 'regenerator-runtime',
h: ['preact', 'h'],
}),
// Expose environment variables
new webpack.EnvironmentPlugin(['npm_package_version']),
// Output HTML for iFrame
new WebPlugin({
filename: `${targetPath}/iframe.html`,
template: relative('src/iframe/index.html'),
}),
new SuppressChunksPlugin(['iframe']),
new CleanWebpackPlugin(),
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static',
}),
],
module: {
rules: [
{
test: /\.css$/,
use: [
// `import foo.css` gets the raw text to inject anywhere
'raw-loader',
{
// PostCSS
loader: 'postcss-loader',
options: {
sourceMap: 'inline',
plugins: () => [
postcssEasyImport(),
postcssUrl({ url: 'inline' }),
postcssPresetEnv({
features: {
'nesting-rules': true,
'color-mod-function': true,
},
}),
cssnano(),
],
},
},
],
},
// Babel
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
// ESLint
{
test: /\.js$/,
exclude: /node_modules/,
use: ['eslint-loader']
},
// DataURI Image Loader
{
test: /\.(svg|jpg)$/,
use: 'url-loader',
},
],
},
};
};