Skip to content

Instantly share code, notes, and snippets.

@esausilva
Last active Dec 4, 2018
Embed
What would you like to do?
Webpack config to compile JS and Sass files. (In Visual Studio )Using "NPM Task Runner" to run "dev" script when project opens and "build" script before each build
{
"name": "fullcalendar-core",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack --watch",
"build": "cross-env NODE_ENV=production webpack"
},
"author": "Esau Silva (@_esausilva)",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"babel-loader": "^8.0.4",
"cross-env": "^5.2.0",
"css-loader": "^1.0.1",
"cssnano": "^4.1.7",
"file-loader": "^2.0.0",
"mini-css-extract-plugin": "^0.4.5",
"node-sass": "^4.10.0",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.4.0",
"sass-loader": "^7.1.0",
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2"
},
"browserslist": [
">0.25%",
"not dead",
"not ie <= 10",
"not op_mini all"
],
"-vs-binding": {
"BeforeBuild": [
"build"
],
"ProjectOpened": [
"dev"
]
}
}
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const postcssPresetEnv = require('postcss-preset-env');
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
mode: devMode ? 'development' : 'production',
entry: ['./Scripts/calendar.js','./Styles/calendar.scss'],
output: {
path: path.resolve(__dirname, 'wwwroot'),
publicPath: '/',
filename: devMode ? 'js/calendar.js' : 'js/calendar.min.js'
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.(sa|sc)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
importLoaders: 2
}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: devMode
? () => []
: () => [
postcssPresetEnv({
browsers: ['>0.25%', 'not dead', 'not ie <= 10','not op_mini all']
}),
require('cssnano')()
]
}
},
{
loader: 'sass-loader'
}
]
},
{
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: '../images',
emitFile: false
}
}
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: devMode ? 'css/calendar.css' : 'css/calendar.min.css'
})
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment