Here you can find the steps to deploy your app/site, I put all the infos together about Netlify, Travis and Webpack configuration.
- log into your netlify account
- create an app in
New OAuth App
- get the access token number, click on
New access token
and keep it because it will be disappear eventually - create a site, go to site's settings and get the API ID
- activate travis to your github's repo
- create
.travis.yml
, see the travi's file - change the
site_id
- install travis command line (mac:
brew install travis
) - add netlify auth key
travis encrypt --add deploy.auth NETLIFY_ACCESS_TOKEN
- set env variables through travis
travis env set <VARIABLE_NAME> <VARIABLE_VALUE>
, e.g:travis env set SITE_URL https://5f54c3de080cf05d5362f758--thirsty-agnesi-9078d4.netlify.app/
- add build script to package.json
"build": "webpack --mode production --env.TWITCH_URL=$TWITCH_URL --env.TOKEN=$TOKEN --env.CLIENT_ID=$CLIENT_ID"
- add dev script to package.json
"start": "webpack-dev-server --env.TWITCH_URL=<YOUR_TWITCH_URL> --env.TOKEN=<YOUR_TOKEN> --env.CLIENT_ID=<YOUR_CLIENT_ID>",
- add
webpack.DefinePlugin
to webpack's plugin
new webpack.DefinePlugin({
"process.env.TWITCH_URL": JSON.stringify(env.TWITCH_URL),
"process.env.TOKEN": JSON.stringify(env.TOKEN),
"process.env.CLIENT_ID": JSON.stringify(env.CLIENT_ID),
}),
- convert webpacks module.export to function to accepts
env
parameter
module.exports = (env) => {
console.log(env);
return {
module: {
.
.
.
plugins: [
new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html",
}),
new webpack.SourceMapDevToolPlugin({}),
new webpack.DefinePlugin({
"process.env.TWITCH_URL": JSON.stringify(env.TWITCH_URL),
"process.env.TOKEN": JSON.stringify(env.TOKEN),
"process.env.CLIENT_ID": JSON.stringify(env.CLIENT_ID),
}),
],
};
};