Last active
October 19, 2019 09:55
-
-
Save SigurdMW/bb774416baebfd2f820f959b4ae49e14 to your computer and use it in GitHub Desktop.
Webpack config for Epi Server. Handles .scss, .css, .js, font-files, images (in .js/.scss/.css). Autoprefix and minifying is included
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "skuld-frontend", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "backstop test", | |
"approve-tests": "backstop approve", | |
"build": "set NODE_ENV=production && webpack -p", | |
"watch": "webpack --cache=false --watch" | |
}, | |
"author": "Sigurd Moland Wahl", | |
"license": "ISC", | |
"devDependencies": { | |
"autoprefixer": "^7.1.2", | |
"babel-core": "^6.25.0", | |
"babel-loader": "^7.1.1", | |
"babel-minify": "^0.2.0", | |
"babel-minify-webpack-plugin": "^0.2.0", | |
"babel-preset-es2015": "^6.24.1", | |
"babel-preset-react": "^6.24.1", | |
"clean-webpack-plugin": "^0.1.16", | |
"css-loader": "^0.28.4", | |
"cssnano": "^3.10.0", | |
"extract-text-webpack-plugin": "^3.0.0", | |
"file-loader": "^0.11.2", | |
"node-sass": "^4.5.3", | |
"path": "^0.12.7", | |
"postcss-discard-duplicates": "^2.1.0", | |
"postcss-loader": "^2.0.6", | |
"sass-loader": "^6.0.6", | |
"style-loader": "^0.18.2", | |
"sw-precache-webpack-plugin": "^0.11.4", | |
"url-loader": "^0.5.9", | |
"webpack": "^3.3.0" | |
}, | |
"dependencies": { | |
"a11y-dialog": "^3.0.2", | |
"siema": "^1.4.6" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const MinifyPlugin = require("babel-minify-webpack-plugin"); | |
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); | |
console.log("Current ENV is: " + process.env.NODE_ENV); | |
const PUBLIC_PATH = "/assets/dist/"; | |
// TODO cache google fonts with service worker | |
// if change filename: remember to change reference to this file in _Root.cshtml | |
const serviceWorkerFileName = "service-worker.js"; | |
const cleanOptions = { | |
root: path.resolve("../"), | |
verbose: true, | |
dry: false, | |
watch: true, | |
} | |
const pathsToClean = [ | |
'assets/dist', | |
serviceWorkerFileName, | |
]; | |
module.exports = [{ | |
entry: "./src/main.js", | |
output: { | |
path: path.resolve('dist'), | |
filename: 'index_bundle.[hash].js', | |
publicPath: PUBLIC_PATH | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.js$/, | |
loader: 'babel-loader', | |
exclude: /node_modules/, | |
include: path.resolve(__dirname, "src") | |
}, | |
{ | |
test: /\.scss$/, | |
include: path.resolve(__dirname, "src"), | |
loader: ExtractTextPlugin.extract({ | |
fallback: 'style-loader/useable', | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
autoprefixer: false, | |
sourceMap: true, | |
importLoaders: 1 | |
} | |
}, | |
{ | |
loader: 'postcss-loader', | |
options: { | |
sourceMap: true | |
} | |
}, | |
{ | |
loader: 'sass-loader', | |
options: { sourceMap: true } | |
} | |
] | |
}) | |
}, | |
{ | |
test: /\.woff(2)?(\?[a-z0-9]+)?$/, | |
include: path.resolve(__dirname, "src"), | |
loader: "url-loader" | |
}, | |
{ | |
test: /\.(ttf|eot|svg)(\?[a-z0-9]+)?$/, | |
include: path.resolve(__dirname, "src"), | |
loader: "file-loader" | |
}, | |
] | |
}, | |
plugins: [ | |
new CleanWebpackPlugin(pathsToClean, cleanOptions), | |
new ExtractTextPlugin('styles.[hash].css'), | |
new webpack.DefinePlugin({ | |
'process.env': { | |
'NODE_ENV': JSON.stringify('production') | |
} | |
}), | |
new MinifyPlugin(), | |
new SWPrecacheWebpackPlugin( | |
{ | |
cacheId: 'skuld-cache', | |
dontCacheBustUrlsMatching: /\.\w{8}\./, | |
filepath: path.resolve("../") + "/" + serviceWorkerFileName, | |
runtimeCaching: [ | |
{ handler: 'fastest', urlPattern: /^https:\/\/fonts\.googleapis\.com/ }, | |
{ handler: 'fastest', urlPattern: /^https:\/\/fonts\.gstatic\.com/} | |
], | |
minify: false, | |
navigateFallback: '/index.html', | |
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/], | |
} | |
) | |
] | |
}, { | |
entry: "./src/editor.css", | |
output: { | |
path: path.resolve('dist/editor'), | |
filename: 'editor.css' | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.css/, | |
include: path.resolve(__dirname, "src"), | |
loader: ExtractTextPlugin.extract({ | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
sourceMap: false | |
} | |
} | |
] | |
}) | |
} | |
] | |
}, | |
plugins: [ | |
new ExtractTextPlugin('editor.css') | |
] | |
}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment