Created
October 14, 2018 16:16
-
-
Save kuzminT/d6a56489d61c2f977900ac7ce618f555 to your computer and use it in GitHub Desktop.
Webpack 4 confige example
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
'use strict'; | |
const webpack = require('webpack'); | |
const path = require('path'); | |
const NODE_ENV = process.env.NODE_ENV || 'development'; | |
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); | |
// process.noDeprecation = true; | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const BasePath = path.resolve(__dirname, 'app'); | |
const config = { | |
entry: | |
{ | |
bundle: path.resolve(BasePath, 'src/js/index.js') | |
}, | |
output: { | |
filename: '[name].js', | |
path: path.resolve(__dirname, 'app/build') | |
}, | |
devtool: 'cheap-source-map', | |
// context: __dirname, | |
resolve: { | |
// options for resolving module requests | |
// (does not apply to resolving to loaders) | |
modules: [ | |
"node_modules" | |
// path.resolve(__dirname) | |
], | |
// directories where to look for modules | |
extensions: [".js", ".json", ".jsx", ".css"] | |
// extensions that are used | |
}, | |
watch: NODE_ENV === 'development', | |
watchOptions: { | |
poll: 1000, | |
ignored: /node_modules/ | |
}, | |
module: { | |
// configuration regarding modules | |
rules: [ | |
// rules for modules (configure loaders, parser options, etc.) | |
{ | |
test: /\.jsx?$/, | |
include: [ | |
path.resolve(BasePath, "src/js") | |
], | |
exclude: [ | |
path.resolve(__dirname, "node_modules") | |
], | |
// Best practices: | |
// - Use RegExp only in test and for filename matching | |
// - Use arrays of absolute paths in include and exclude | |
// - Try to avoid exclude and prefer include | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['@babel/preset-env'] | |
} | |
}, | |
// options for the loader | |
}, | |
{ | |
test: /\.scss$/, | |
use: ExtractTextPlugin.extract( | |
{ | |
fallback: 'style-loader', | |
use: ['css-loader', 'sass-loader'] | |
}) | |
/*[ | |
// { | |
// loader: "style-loader" // creates style nodes from JS strings | |
// }, | |
// { | |
// loader: "css-loader" // translates CSS into CommonJS | |
// }, | |
// { | |
// loader: "sass-loader" // compiles Sass to CSS | |
// } | |
]*/ | |
} | |
] | |
}, | |
plugins: [ | |
new ExtractTextPlugin('style.css') | |
] | |
}; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment