-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
125 lines (112 loc) · 3.85 KB
/
Copy pathwebpack.config.js
File metadata and controls
125 lines (112 loc) · 3.85 KB
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
var webpack = require('webpack');
var path = require('path');
const autoprefixer = require('autoprefixer');
const glob = require('glob');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var NunjucksWebpackPlugin = require("nunjucks-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
var SvgStore = require('webpack-svgstore-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const isDev = (process.env.NODE_ENV === 'development') ? true : false;
const basePath = process.cwd();
const nunjucksContext = require('./html/data');
const nunjucksDevConfig = require('./html/config.dev.json');
const nunjucksProdConfig = require('./html/config.prod.json');
nunjucksContext.config = (isDev) ? nunjucksDevConfig : nunjucksProdConfig;
const nunjucksOptions = JSON.stringify({
searchPaths: basePath + '/html/',
context: nunjucksContext
});
const pages = glob.sync('**/*.njk', {
cwd: path.join(basePath, 'html/pages/'),
root: '/',
}).map(page =>
new HtmlWebpackPlugin({
filename: path.join(basePath, '/assets/html/'+page.slice(0,-4)+'_page.html'),
template: `html/pages/${page}`,
})
);
module.exports = {
context: __dirname,
entry: {
scripts: ["./build.js"],
styles: ["./scss/style.scss"]
},
output: {
libraryTarget: "umd",
library: "friday",
filename: '[name].js',
path: path.resolve(__dirname, './assets')
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
extensions: [".webpack.js", ".web.js", ".js"]
},
module: {
rules: [
{ test: /\.woff2?$|\.ttf$|\.eot$|\.svg$/, loader: 'file-loader?name=fonts/[name].[ext]?[hash]'},
{ test: /\.png|\.jpe?g|\.gif$/, loader: 'file-loader?name=img/[name].[ext]?[hash]'},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options : { autoprefixer: false, sourceMap: true, importLoaders: 1}
},
{
loader: 'resolve-url-loader',
options: {keepQuery:true}
},
{
loader: 'postcss-loader',
options: {
plugins: [
autoprefixer({
browsers:['ie >= 10', 'last 4 version']
})
],
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {sourceMap:true}
}
]
})
},
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ] },
{
test: /\.(njk|nunjucks)$/,
loader: ['html-loader', `nunjucks-html-loader?${nunjucksOptions}`]
},
]
},
plugins:[
...pages,
new ExtractTextPlugin({ filename: '[name].css', disable: false, allChunks: true }),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new SvgStore({
// svgo options
svgoOptions: {
plugins: [
{ removeTitle: true }
]
},
prefix: 'icon'
}),
new BrowserSyncPlugin({
host: 'localhost',
port: 3000,
server: { }
})
],
externals: {
},
};