Created
November 15, 2018 16:03
-
-
Save aditodkar/ea792f6537f391ae4b2a5ca0e0b902d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 HtmlWebpackPlugin = require("html-webpack-plugin"); | |
const CleanWebpackPlugin = require("clean-webpack-plugin"); | |
const settings = { | |
distPath: path.join(__dirname, "dist"), | |
srcPath: path.join(__dirname, "src") | |
}; | |
function srcPathExtend(subpath) { | |
return path.join(settings.srcPath, subpath) | |
} | |
module.exports = (env, options) => { | |
const isDevMode = options.mode === "development"; | |
return { | |
devtool: isDevMode ? "source-map" : false, | |
resolve: { | |
extensions: [".ts", ".tsx", ".js"], | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.tsx?$/, | |
use: ["babel-loader", "ts-loader", "tslint-loader"] | |
}, | |
{ | |
test: /\.scss$/, | |
use: [ | |
"style-loader", | |
{ | |
loader: "css-loader", | |
options: { | |
sourceMap: isDevMode | |
} | |
}, | |
{ | |
loader: "postcss-loader", | |
options: { | |
plugins: [ | |
require("autoprefixer")() | |
], | |
sourceMap: isDevMode | |
} | |
}, | |
{ | |
loader: "sass-loader", | |
options: { | |
sourceMap: isDevMode | |
} | |
} | |
] | |
}, | |
{ | |
test: /\.(ttf|eot|woff|woff2)$/, | |
use: { | |
loader: "file-loader", | |
options: { | |
name: "fonts/[name].[ext]", | |
}, | |
}, | |
}, | |
{ | |
test: /\.(jpe?g|png|gif|svg|ico)$/i, | |
use: [ | |
{ | |
loader: "file-loader", | |
options: { | |
outputPath: "assets/" | |
} | |
} | |
] | |
} | |
] | |
}, | |
plugins: [ | |
new CleanWebpackPlugin([settings.distPath], { | |
verbose: true | |
}), | |
new HtmlWebpackPlugin({ | |
template: srcPathExtend("index.html") | |
}) | |
] | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment