forked from pressbooks/pressbooks-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mix.js
69 lines (63 loc) · 2.39 KB
/
webpack.mix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let mix = require( 'laravel-mix' );
let path = require( 'path' );
let normalizeNewline = require( 'normalize-newline' );
let fs = require( 'fs' );
/*
|--------------------------------------------------------------------------
| 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.
|
*/
const dist = 'dist';
// Normalize Newlines
const normalizeNewlines = ( dir ) => {
fs.readdirSync( dir ).forEach( function( file ) {
file = path.join( dir, file );
fs.readFile( file, 'utf8', function( err, buffer ) {
if ( err ) return console.log( err );
buffer = normalizeNewline( buffer );
fs.writeFile( file, buffer, 'utf8', function( err ) {
if ( err ) return console.log( err );
} );
} );
} );
};
mix
.setPublicPath( 'dist' )
.scripts( 'node_modules/sharer.js/sharer.js', 'dist/scripts/sharer.js' )
.scripts( 'node_modules/lity/dist/lity.js', 'dist/scripts/lity.js' )
.scripts( 'node_modules/jquery.localscroll/jquery.localScroll.js', 'dist/scripts/jquery.localScroll.js' )
.scripts( 'node_modules/jquery.scrollto/jquery.scrollTo.js', 'dist/scripts/jquery.scrollTo.js' )
.scripts( 'node_modules/details-element-polyfill/dist/details-element-polyfill.js', 'dist/scripts/details-element-polyfill.js' )
.js( 'assets/src/scripts/book.js', 'dist/scripts/book.js' )
.js( 'assets/src/scripts/pane.js', 'dist/scripts/pane.js' )
.js(
'assets/src/scripts/collapse-sections.js',
'dist/scripts/collapse-sections.js'
)
.js( 'assets/src/scripts/lightbox.js', 'dist/scripts/lightbox.js' )
.sass( 'assets/src/styles/book.scss', 'dist/styles' )
.sass( 'assets/legacy/styles/web-house-style.scss', 'dist/styles' )
.copy( 'node_modules/lity/dist/lity.css', 'dist/styles/lity.css' )
.copyDirectory( 'assets/src/images', 'dist/images' )
.version()
.options( { processCssUrls: false } )
.then( () => {
normalizeNewlines( 'dist/scripts/' );
normalizeNewlines( 'dist/styles/' );
} );
// BrowserSync
mix.browserSync( {
host: 'localhost',
proxy: 'https://pressbooks.test/standardtestbook',
port: 3200,
files: [ '*.php', '', `${dist}/**/*.css`, `${dist}/**/*.js` ],
} );
// Source maps when not in production.
if ( ! mix.inProduction() ) {
mix.sourceMaps();
}