This gist shows how to create a flow for assets compilation in Adonis Framework.
Adonis uses public
folder for assets, so the best folder structure in that case and for that webpack config file is:
public/
|-- styles/
| |-- application/
| |-- manage/
| |-- application.less
| |-- manage.less
|-- scripts/
| |-- application/
| |-- manage/
| |-- application.js
| |-- manage.js
|-- images/
This config uses webpack
as a core. The flow is built around LESS + JS (ES2015) + Babel.
Before running compilation install these packages (add --save-dev
if you compile assets locally and then deploy):
npm i webpack autoprefixer babel-core babel-loader babel-preset-env babel-preset-es2015 \
less less-loader css-loader file-loader style-loader url-loader \
extract-text-webpack-plugin assets-webpack-plugin\
uglify-js
Copy webpack.config.js
to project folder.
Copy code from hooks.js
to app/hooks.js
, in order to define custom edge globals.
Add tasks to package.json
to scripts section in order to start and process webpack tasks.
"scripts": {
"build": "mkdir -p public/build && rm -rf public/build/* && webpack -p",
"watch": "mkdir -p public/build && rm -rf public/build/* && webpack -w",
}
After all is done you can call js and css assets in edge templates by using created global, it will insert specific file defined in assets.json
created by webpack in public/build
{{ webpack_asset('manage.js') }}
Work still in progress. Basing on that config you can easily add Vue/React compilation and etc.