-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
146 lines (144 loc) · 4.1 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
const path = require('path')
const webpack = require('webpack')
const WebpackMd5Hash = require('webpack-md5-hash');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CommonsPlugin = new require("webpack/lib/optimize/CommonsChunkPlugin");
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
const PreloadWebpackPlugin = require('preload-webpack-plugin');
const PUBLIC_PATH = 'https://pmcalabrese.github.io/riotjs-webpack/';
const SERVICE_WORKER_FILENAME = 'service-worker.js';
const extractSass = new ExtractTextPlugin({
filename: "[name].[contenthash].css",
disable: process.env.NODE_ENV === "development"
});
module.exports = {
resolveLoader: {
"modules": [
"./node_modules"
]
},
entry: {
app: [
"./src/main.js"
],
styles: [
"./src/styles.scss"
]
},
output: {
path: path.resolve(__dirname, './public'),
publicPath: '',
filename: '[name].bundle.js',
chunkFilename: "[chunkhash].[name].chunk.js"
},
plugins: [
extractSass,
new SWPrecacheWebpackPlugin(
{
cacheId: 'riotjs',
dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'service-worker.js',
minify: true,
navigateFallback: PUBLIC_PATH + 'index.html',
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/]
}
),
new UglifyJSPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module) => module.resource && module.resource.startsWith(nodeModules),
filename: 'vendor.bundle.js',
"chunks": [
"main"
]
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new HtmlWebpackPlugin({
template: "./src/index.html",
filename: "./index.html",
hash: true,
inject: true,
compile: true,
favicon: false,
minify: false,
cache: true,
showErrors: true,
chunks: "all",
excludeChunks: [],
serviceWorker: `/${SERVICE_WORKER_FILENAME}`,
}),
new PreloadWebpackPlugin({
rel: 'preload',
include: ['navigationtag', 'apptag']
}),
// new ScriptExtHtmlWebpackPlugin({
// defer: './src/styles.css'
// }),
new CopyWebpackPlugin([
{ from: 'src/manifest.json' },
{ from: 'src/assets', to:'assets' }
]),
new webpack.ProvidePlugin({ riot: 'riot' }),
],
module: {
loaders: [
{
test: /\.tag\.html$/,
exclude: /node_modules/,
loader: 'riot-tag-loader',
// options: {
// type: 'es6', // transpile the riot tags using babel
// hot: true,
// debug: false
// }
},
{
test: /\.tag\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ["stage-3", "stage-2", "stage-1", "es2015"],
plugins: ["autobind-class-methods", "babel-plugin-transform-class-properties"]
},
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ["stage-3", "stage-2", "stage-1", "es2015"],
plugins: ["autobind-class-methods", "babel-plugin-transform-class-properties"]
},
},
// {
// test: /\.css$/i,
// use: ExtractTextPlugin.extract({
// fallback: 'style-loader',
// use: 'css-loader'
// })
// },
{
test: /\.scss$/,
use: extractSass.extract({
use: [{
loader: "css-loader", options:{
minimize: true,
sourceMap: true
}
}, {
loader: "sass-loader", options: {
minimize: true,
sourceMap: true
}
}],
// use style-loader in development
fallback: "style-loader"
})
}
]
}
}