Last active
December 22, 2018 04:40
-
-
Save anwas/916f3d94d63039039be1d0d69b5aba53 to your computer and use it in GitHub Desktop.
[Webpack workflow]
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-dev", | |
"version": "1.0.0", | |
"description": "Webpack development workflow with laravel-mix", | |
"main": "index.js", | |
"scripts": { | |
"dev": "npm run development", | |
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", | |
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", | |
"hot": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", | |
"prod": "npm run production", | |
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"browser-sync": "^2.26.3", | |
"browser-sync-webpack-plugin": "^2.0.1", | |
"cross-env": "^5.2.0", | |
"laravel-mix": "^4.0.12", | |
"node-sass": "^4.11.0", | |
"sass": "^1.15.2", | |
"sass-loader": "^7.1.0", | |
"vue-template-compiler": "^2.5.21" | |
}, | |
"browserslist": { | |
"production": [ | |
"> 1%", | |
"last 3 versions", | |
"ie 10" | |
], | |
"development": [ | |
"last 15 chrome version", | |
"last 15 firefox version", | |
"ie 10" | |
] | |
} | |
} |
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
let mix = require('laravel-mix'); | |
// require('mix-html-builder'); | |
require('laravel-mix-criticalcss'); | |
let siteUrl = 'http://v3.lanbox.lt'; | |
let siteFolder = '/laravelmix-test'; | |
let siteRoot = '../html'; | |
let siteAssetsFolder = siteRoot + siteFolder + '/assets'; | |
let siteSrcFolder = siteRoot + siteFolder + '/_src'; | |
let siteOptions = { | |
jsSrc: siteSrcFolder + '/js', | |
sassSrc: siteSrcFolder + '/sass', | |
js: siteAssetsFolder + '/js', | |
css: siteAssetsFolder + '/css', | |
} | |
/* | |
|-------------------------------------------------------------------------- | |
| Mix Asset Management | |
|-------------------------------------------------------------------------- | |
| | |
| Mix provides a clean, fluent API for defining some Webpack build steps | |
| for your Laravel application. By default, we are compiling the Sass | |
| file for your application, as well as bundling up your JS files. | |
| | |
*/ | |
mix.extract(['jquery']) | |
.autoload({ | |
jquery: ['$', 'window.jQuery', 'jQuery'] | |
}) | |
.js( siteOptions.jsSrc + '/main.js', siteOptions.js + '/' ) | |
.sass( siteOptions.sassSrc + '/style.scss', siteOptions.css + '/' ) | |
.setPublicPath( siteRoot + siteFolder ) | |
.options({ | |
processCssUrls: false, | |
autoprefixer: { | |
options: { | |
browsers: [ | |
'last 6 versions', | |
] | |
} | |
} | |
}) | |
.criticalCss({ | |
enabled: mix.inProduction(), | |
paths: { | |
base: siteUrl + '/', | |
templates: siteOptions.css | |
}, | |
urls: [ | |
{ url: siteRoot + siteFolder + '/index.html', template: 'main' }, | |
], | |
options: { | |
minify: true, | |
}, | |
}) | |
// .buildHtml({ | |
// htmlRoot: './_src/html-files/index.html', // Your html root file | |
// output: './index.html', // The html output file | |
// partialRoot: './_src/html-files/partials/' // OPTIONAL: default partial path | |
// }) | |
.browserSync({ | |
proxy: siteUrl + siteFolder, | |
port: 8887, | |
https: false, | |
files: [ | |
// '!**/_src/html-files/**/*', | |
siteOptions.js + '/**/*.js', | |
siteOptions.css + '/**/*.css', | |
siteRoot + siteFolder + '/**/*.php', | |
siteRoot + siteFolder + '/**/*.html' | |
], | |
ghostMode: { | |
clicks: true, | |
forms: true, | |
scroll: true, | |
location: true | |
}, | |
reloadOnRestart: true, | |
notify: false, | |
reloadDelay: 350 | |
}) | |
.disableNotifications() | |
.version(); | |
// Full API | |
// mix.js(src, output); | |
// mix.react(src, output); <-- Identical to mix.js(), but registers React Babel compilation. | |
// mix.preact(src, output); <-- Identical to mix.js(), but registers Preact compilation. | |
// mix.coffee(src, output); <-- Identical to mix.js(), but registers CoffeeScript compilation. | |
// mix.ts(src, output); <-- TypeScript support. Requires tsconfig.json to exist in the same folder as webpack.mix.js | |
// mix.extract(vendorLibs); | |
// mix.sass(src, output); | |
// mix.less(src, output); | |
// mix.stylus(src, output); | |
// mix.postCss(src, output, [require('postcss-some-plugin')()]); | |
// mix.browserSync('my-site.test'); | |
// mix.combine(files, destination); | |
// mix.babel(files, destination); <-- Identical to mix.combine(), but also includes Babel compilation. | |
// mix.copy(from, to); | |
// mix.copyDirectory(fromDir, toDir); | |
// mix.minify(file); | |
// mix.sourceMaps(); // Enable sourcemaps | |
// mix.version(); // Enable versioning. | |
// mix.disableNotifications(); | |
// mix.setPublicPath('path/to/public'); | |
// mix.setResourceRoot('prefix/for/resource/locators'); | |
// mix.autoload({}); <-- Will be passed to Webpack's ProvidePlugin. | |
// mix.webpackConfig({}); <-- Override webpack.config.js, without editing the file directly. | |
// mix.babelConfig({}); <-- Merge extra Babel configuration (plugins, etc.) with Mix's default. | |
// mix.then(function () {}) <-- Will be triggered each time Webpack finishes building. | |
// mix.extend(name, handler) <-- Extend Mix's API with your own components. | |
// mix.options({ | |
// extractVueStyles: false, // Extract .vue component styling to file, rather than inline. | |
// globalVueStyles: file, // Variables file to be imported in every component. | |
// processCssUrls: true, // Process/optimize relative stylesheet url()'s. Set to false, if you don't want them touched. | |
// purifyCss: false, // Remove unused CSS selectors. | |
// terser: {}, // Terser-specific options. https://github.com/webpack-contrib/terser-webpack-plugin#options | |
// postCss: [] // Post-CSS options: https://github.com/postcss/postcss/blob/master/docs/plugins.md | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment