-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwebpack.common.js
96 lines (92 loc) · 2.4 KB
/
webpack.common.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
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const fs = require('fs');
const globImporter = require('node-sass-glob-importer');
const WorkerPlugin = require('worker-plugin');
const CopyPlugin = require("copy-webpack-plugin");
function getPageEntries() {
// Read all files under /assets/javascripts/pages/* and create
// a webpack entry point for each one
const pagesPath = path.join(__dirname, 'assets', 'javascripts', 'pages');
const pageFilenames = fs.readdirSync(pagesPath)
const pageEntries = {}
pageFilenames.forEach(pageFilename => {
const name = path.basename(pageFilename, '.js');
const fullPath = path.join(pagesPath, pageFilename);
pageEntries[name] = [fullPath];
});
return pageEntries;
}
module.exports = {
entry: Object.assign({},
{
common: [
'babel-polyfill',
path.join(__dirname, 'assets', 'javascripts', 'common.js'),
path.join(__dirname, 'assets', 'stylesheets', 'common.scss')
]
},
getPageEntries()
),
output: {
path: path.join(__dirname, '.tmp', 'dist'),
filename: 'javascripts/[name].js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: 'file-loader',
options: {
name: 'common.css',
},
},
{ loader: 'extract-loader' },
{ loader: 'css-loader' },
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer()]
}
},
{
loader: 'sass-loader',
options: {
includePaths: ['./node_modules'],
importer: globImporter()
}
},
]
},
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
query: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
]
},
plugins: [
new webpack.DefinePlugin({
__PREVIEW__: !!process.env.PREVIEW
}),
new WorkerPlugin(),
new CopyPlugin({
patterns: [
{ from: path.join(__dirname, 'node_modules', 'streamsaver', 'sw.js'), to: "" },
{ from: path.join(__dirname, 'node_modules', 'streamsaver', 'mitm.html'), to: "" },
],
}),
],
optimization: {
splitChunks: {
chunks: 'all',
name: 'vendors'
}
},
};