Last active
May 14, 2019 09:21
-
-
Save fvilches17/181155bcbc1662daaef0c51f9d0a666b to your computer and use it in GitHub Desktop.
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 CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const WasmPackPlugin = require('@wasm-tool/wasm-pack-plugin'); | |
function loadOutput(environment) { | |
const filename = environment.production ? 'scripts/[name].[hash].min.js' : 'scripts/[name].js'; | |
const chunkFilename = environment.production ? '[name].[hash].min.js' : '[name].js'; | |
return { | |
path: path.resolve(__dirname, 'dist'), | |
filename, | |
chunkFilename, | |
publicPath: '/' | |
}; | |
}; | |
function loadPlugins(environment) { | |
let wasmPackArgs = '--no-typescript'; | |
if (environment.production) wasmPackArgs += ' --release'; | |
return [ | |
new HtmlWebpackPlugin({ | |
template: './src/index.html', | |
chunks: ['app'], | |
hash: true | |
}), | |
new WasmPackPlugin({ | |
crateDirectory: path.resolve(__dirname, `./src/hello_world`), | |
extraArgs: wasmPackArgs | |
}), | |
new CleanWebpackPlugin() | |
]; | |
}; | |
module.exports = environment => { | |
const mode = environment.production ? 'production' : 'development'; | |
const entry = { app: './src/app.js' }; | |
const output = loadOutput(environment); | |
const plugins = loadPlugins(environment); | |
//Base Config | |
const config = { mode, entry, output, plugins }; | |
//Additional Production Config | |
if (environment.production) { | |
config.devtool = 'source-map'; | |
} | |
//Additional Development Config | |
else { | |
config.devServer = { | |
contentBase: path.join(__dirname, 'dist'), | |
open: true, | |
overlay: { errors: true, warnings: false }, | |
port: 5000, | |
watchContentBase: true | |
}; | |
} | |
return config; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment