Last active
April 2, 2018 04:29
-
-
Save coverslide/784caaadec4383491fcfd1e073864db0 to your computer and use it in GitHub Desktop.
Webpack Base
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
Webpack Base |
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
Show hidden characters
{ | |
"presets": ["env"] | |
} |
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
/node_modules | |
package-lock.json |
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": "webpack-base", | |
"private": true, | |
"version": "1.0.0", | |
"description": "", | |
"main": "src/index.js", | |
"scripts": { | |
"start": "webpack-dev-server", | |
"build": "webpack", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Richard Hoffman", | |
"license": "ISC", | |
"devDependencies": { | |
"autoprefixer": "^8.2.0", | |
"babel-loader": "^7.1.4", | |
"babel-preset-env": "^1.6.1", | |
"copy-webpack-plugin": "^4.5.1", | |
"css-loader": "^0.28.11", | |
"extract-text-webpack-plugin": "^4.0.0-beta.0", | |
"postcss-loader": "^2.1.3", | |
"pug": "^2.0.3", | |
"pug-html-loader": "^1.1.5", | |
"raw-loader": "^0.5.1", | |
"sass-loader": "^6.0.7", | |
"webpack": "^4.4.1", | |
"webpack-cli": "^2.0.13", | |
"webpack-dev-server": "^3.1.1" | |
} | |
} |
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
module.exports = { | |
plugins: [ | |
require('autoprefixer') | |
] | |
} |
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 CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; | |
const ExtractCss = new ExtractTextPlugin('[name].css'); | |
const ExtractHtml = new ExtractTextPlugin('[name].html'); | |
module.exports = { | |
mode: process.env.NODE_ENV, | |
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false, | |
entry: { | |
main: path.join(__dirname, 'src', 'index.js'), | |
// these two will create extra .js files | |
style: path.join(__dirname, 'style', 'index.scss'), | |
index: path.join(__dirname, 'views', 'index.pug'), | |
}, | |
output: { | |
path: path.resolve(__dirname, 'build'), | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.(txt)$/, | |
use: 'raw-loader' | |
}, | |
{ | |
test: /\.js$/, | |
use: 'babel-loader', | |
}, | |
{ | |
test: /\.pug$/, | |
use: ExtractHtml.extract({ | |
use: ['raw-loader', 'pug-html-loader'] | |
}) | |
}, | |
{ | |
test: /\.(s[ca]|c)ss$/, | |
use: ExtractCss.extract({ | |
use: ['css-loader', 'sass-loader', 'postcss-loader'] | |
}) | |
} | |
] | |
}, | |
devServer: { | |
contentBase: path.join(__dirname, "public"), | |
host: '0.0.0.0', // so I can test on other devices | |
}, | |
plugins: [ | |
ExtractCss, | |
ExtractHtml, | |
// any extra assets can be placed here | |
new CopyWebpackPlugin([ | |
path.resolve(__dirname, 'public'), | |
]), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment