Last active
June 12, 2018 04:34
-
-
Save darkamenosa/555a49af6e01778d664fba86a0fcf54c to your computer and use it in GitHub Desktop.
Webpack 4 config for simple project without angular, react, ... only jquery
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
// CSS import | |
import 'bootstrap/dist/css/bootstrap.css'; | |
import 'font-awesome/css/font-awesome.css'; | |
import 'progressively/dist/progressively.min.css'; | |
import 'owl.carousel/dist/assets/owl.carousel.css'; | |
import 'owl.carousel/dist/assets/owl.theme.default.min.css'; | |
import 'animsition/dist/css/animsition.min.css'; | |
import 'toastr/build/toastr.css'; | |
import './lib/css/bootstrap-theme.min.css'; | |
import './css/margin.css'; | |
import './css/style.css'; | |
import './css/responsive.css'; | |
// JS import | |
import 'jquery'; | |
import 'bootstrap'; | |
import 'owl.carousel'; | |
import 'animsition'; | |
import 'toastr'; | |
import 'sweetalert'; | |
import './lib/js/jquery.sticky.js'; | |
import './lib/js/validator/jquery.form-validator.min.js'; | |
import './lib/js/validator/lang/vi.js'; | |
import './plugins/form.multi.js'; | |
import './pageload-action.js'; |
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
{ | |
"name": "banker-group", | |
"version": "1.0.0", | |
"description": "Banker group js and css app", | |
"scripts": { | |
"dev": "cross-env NODE_ENV=dev webpack --watch --progress", | |
"build": "cross-env NODE_ENV=production webpack" | |
}, | |
"author": "tuyenhx", | |
"license": "MIT", | |
"devDependencies": { | |
"autoprefixer": "^8.6.2", | |
"babel-core": "^6.26.3", | |
"babel-loader": "^7.1.4", | |
"babel-plugin-transform-object-rest-spread": "^6.26.0", | |
"babel-preset-env": "^1.7.0", | |
"clean-webpack-plugin": "^0.1.19", | |
"copy-webpack-plugin": "^4.5.1", | |
"cross-env": "^5.1.6", | |
"css-loader": "^0.28.11", | |
"file-loader": "^1.1.11", | |
"mini-css-extract-plugin": "^0.4.0", | |
"optimize-css-assets-webpack-plugin": "^4.0.2", | |
"postcss-loader": "^2.1.5", | |
"precss": "^3.1.2", | |
"style-loader": "^0.21.0", | |
"url-loader": "^1.0.1", | |
"webpack": "^4.11.1", | |
"webpack-cli": "^3.0.3" | |
}, | |
"dependencies": { | |
"animsition": "^4.0.2", | |
"bootstrap": "^3.3.7", | |
"font-awesome": "^4.7.0", | |
"jquery": "^1.11.0", | |
"owl.carousel": "^2.3.4", | |
"progressively": "^1.1.2", | |
"sweetalert": "^2.1.0", | |
"toastr": "^2.1.4" | |
} | |
} |
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 webpack = require("webpack"); | |
const UglifyJSPlugin = require("uglifyjs-webpack-plugin"); | |
const CleanWebpackPlugin = require("clean-webpack-plugin"); | |
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); | |
const env = process.env.NODE_ENV; | |
const optimizePlugins = | |
env === "production" | |
? [ | |
new OptimizeCSSAssetsPlugin({}), | |
new UglifyJSPlugin({ | |
sourceMap: true | |
}) | |
] | |
: []; | |
const mode = env === "production" ? "production" : "development"; | |
module.exports = { | |
entry: { | |
home: "./src/home.js", | |
form: "./src/form.js" | |
}, | |
output: { | |
path: path.resolve(__dirname, "dist/"), | |
filename: "[name].bundle.js", | |
publicPath: "/app/dist/" | |
}, | |
mode: mode, | |
devtool: "source-map", | |
watchOptions: { | |
aggregateTimeout: 300, | |
poll: 1000 | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: { | |
loader: "babel-loader", | |
options: { | |
presets: ["env"], | |
plugins: ["transform-object-rest-spread"] | |
} | |
} | |
}, | |
{ | |
test: /\.css$/, | |
use: [ | |
{ loader: MiniCssExtractPlugin.loader }, | |
{ loader: "css-loader", options: { url: false, importLoaders: 1 } }, | |
{ | |
loader: "postcss-loader", // Run post css actions | |
options: { | |
plugins: function() { | |
// post css plugins, can be exported to postcss.config.js | |
return [require("precss"), require("autoprefixer")({})]; | |
} | |
} | |
} | |
] | |
}, | |
{ | |
test: /\.(woff|woff2|eot|ttf|otf|svg)$/, | |
use: ["file-loader"] | |
}, | |
{ | |
test: /\.(jpe?g|png|gif)$/, | |
use: ["file-loader"] | |
} | |
] | |
}, | |
optimization: { | |
minimizer: [...optimizePlugins], | |
splitChunks: { | |
cacheGroups: { | |
commons: { | |
name: "common", | |
chunks: "initial", | |
minChunks: 2, | |
minSize: 0 | |
} | |
} | |
} | |
}, | |
plugins: [ | |
new CleanWebpackPlugin(["dist"]), | |
new webpack.ProvidePlugin({ | |
$: "jquery", | |
jQuery: "jquery", | |
"window.jQuery": "jquery" | |
}), | |
new webpack.DefinePlugin({ | |
"process.env.NODE_ENV": env | |
}), | |
new MiniCssExtractPlugin({}), | |
new webpack.WatchIgnorePlugin(["node_modules/**/*"]) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment