When using Aurelia, I see the following for CSS.
import 'bootstrap/css/bootstrap.css!';
My questions is, can you configure it to support less files? Or do we need to run the preprocessor separately, converting our less files into css files first?
Thanks in advance.
I think your question is very broad, the answer depends on the solution you choose.
The get started page of Aerelia shows you how to integrate Bootstrap using jspm. Some source 1, 2 suggest to fork the Bootstrap repository on github and use this customized fork instead of the original with jspm. In the package.json fiile of your project replace Bootstrap with your own fork in the jspm dependencies, or run:
jspm install github:{username}/bootstrap#master
For the long term i expect that the above will cause you troubles with keeping your fork up to date. Also you will have to compile Bootstrap (local) and push your changes to github for every change.
Alternatively you can indeed download Bootstrap and add to Less compile task to the gulp build tasks of your project. As already suggested by #matthew-james-davis in the comments you can use Using SASS with Aurelia's Skeleton Navigation project to find out how to do this.
I suggest to use bower to locally install Bootstrap:
bower install bootstrap
The above will install bootstrap in the bower_components/bootstrap folder. Don't modify these files directly. Create a less/project.less:
#import "bootstrap";
// your custom code here
Notice that compiling Bootstrap requires the autoprefix css processor too. See also: http://bassjobsen.weblogs.fm/compile-bootstrap-less-v2-autoprefix-plugin/
So you gulp build task should look like that shown below:
var LessPluginCleanCSS = require('less-plugin-clean-css'),
LessPluginAutoPrefix = require('less-plugin-autoprefix'),
cleancss = new LessPluginCleanCSS({ advanced: true }),
autoprefix= new LessPluginAutoPrefix({ browsers: ["Android 2.3,Android >= 4,Chrome >= 20,Firefox >= 24,Explorer >= 8,iOS >= 6,Opera >= 12,Safari >= 6"] });
gulp.task('build-less', function() {
gulp.src('less/project.less')
.pipe(sourcemaps.init())
.pipe(less({
plugins: [autoprefix, cleancss],
paths: [ path.join(__dirname, 'bower_components/bootstrap/less/') ]
}))
.pipe(sourcemaps.write(paths.sourceMapRelativePath))
.pipe(gulp.dest('css/'))
});
The above task should compile css/project.css you can reference this file in the index.html of your project:
<link rel="stylesheet" type="text/css" href="css/project.css">
You also will have to load Bootstrap Javascripts plugin. These plugin depends on jQuery. Link bootstrap.min.js from your bower_component folder.
Related
I am working on a SPA application built using vue.js 2.6, bootstrap-vue 2.8, sass 1.34 (dart-sass) as preprocessor and sass-loader 10.2.
With the time the project is getting quite big and we've switched from Node-Sass to Dart-Sass (as node-sass is deprecated).
Unfortunately, we're now getting performance issues when building or developping on the project, as it now takes approximately 15 minutes to create a new built, and we're often encountering high memory usage in development.
After reading this article, I figure out using the speed-measure-webpack-plugin that 95% of the compilation time is due to css compilation purposes as most of the SMP stacktrace contains such several entries:
mini-css-extract-plugin, and
css-loader, and
vue-loader, and
postcss-loader, and
sass-loader, and
cache-loader, and
vue-loader took 2 mins, 40.68 secs
Removing the bootstrap imports on the main app.scss file really improve performance, and totally removing the sass compilation removes 95% of the time spent.
Reading this page on dart-sass Github, I understood that the dart Sass native executable is more powerful than the dart sass on node.js version.
Here is my vue.config.js:
process.env.VUE_APP_VERSION = require('./package.json').version
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
module.exports = {
runtimeCompiler: true,
devServer: {
disableHostCheck: true
},
css: {
loaderOptions: {
scss: {
implementation: require('sass'), // This line must in sass option
additionalData: `#import "#/assets/scss/app.scss";`
}
}
},
chainWebpack: config => {
config.module
.rule('eslint')
.use('eslint-loader')
.options({
fix: false
})
config.plugin('speed-measure-webpack-plugin')
.use(SpeedMeasurePlugin)
.end()
}
}
If I've well understand, using this configuration the Dart Sass on Node.js is used during compilation.
I've setup the dart-sass standalone version from this page and I can execute it on the command line, but I don't actually know if it's possible to run it in the webpack compilation instead of the Node.js version ?
I've searched on the vue.js, webpack and sass-loader documentations but without success.
EDIT:
The compilation time issue described in this post was due to the import of a file containing the css of the whole app in additionalData (additionalData: #import "#/assets/scss/app.scss";).
We did this to use Bootstrap variables in several components but it's clearly not the good way to do it.
If you wish to use bootstrap variables in vue components the best option might be to import a file containing your custom and bootstrap variables on every components requiring it, like:
<style lang="scss" scoped>
#import '#/assets/scss/bootstrap';
</style>
Using Dart VM from webpack/sass-loader is probably not possible
I had a feeling (confirmed by comments) that you are including too much with additionalData: '#import "#/assets/scss/app.scss";'
additionalData is pre-pended to any style compilation - which in case of Vue + sass-loader means that everything inside #/assets/scss/app.scss is compiled every time there is a <style> block inside Vue SFC (as each <style> block is compiled separately)
additionalData is useful for variables you need inside most of the components. Things such primary color, text sizes etc. NOT to include some global/dependency styles!
Just move most of the SASS/CSS imports to your main.js or App.vue or simply remove additionalData and your app build time will improve considerably...
I created a new Kotlin/JS Gradle project using the wizard in IntelliJ.
I'm unclear how I'm supposed to add css to the project. The documentation explains how to enable css webpack support, but it doesn't actually say how to add the css file into your project (i.e., how to use the file).
For example, in a normal project, you would just import it in a javascript file. Since I am writing in Kotlin, how do I do it now?
The current documentation is not very precise about this. There are actually two cases:
Importing CSS from existing packages
You can pretty easily import CSS files from other Node-modules using the require() function:
import kotlinext.js.require
import kotlinx.browser.document
import react.dom.h1
import react.dom.render
fun main() {
require("bootstrap/dist/css/bootstrap.css")
render(document.getElementById("root")) {
h1 { +"Hello"}
}
}
For this to work, you need to specify cssSupport.enabled = true in your Gradle build, just like described in the documentation. CSS imported this way will be processed by Webpack.
Incorporating your own CSS into the Webpack build
This seems to be a bit tricky right now. The KotlinJS plugin doesn't copy any resources to the Webpack's build directory (build/js/packages/<project_name>) by default and I didn't find any obvious configuration option for this. To solve it, you have to tell Webpack where it can find your styles:
Create webpack.conf.d directory in project's root and put inside some JS file containing:
config.resolve.modules.push("<your_stylesheet_dir>");
This config will be picked up by the KotlinJS plugin and merged into the generated build/js/packages/<project_name>/webpack.config.js. With this configuration you can just require() project's styles like in the example above. It is kind of mentioned in the documentation.
Alternatively you can tweak the Gradle build, so it copies the stylesheets into the Webpack's build dir:
task("copyStylesheets", Copy::class) {
from(kotlin.sourceSets["main"].resources) {
include("styles/**")
}
into("${rootProject.buildDir}/js/packages/${kotlin.js().moduleName}")
// kotlin { js { moduleName = "xyz" }} has to be set for this to work
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJsDce::class) {
dependsOn("copyStylesheets")
}
Simply sticking a CSS file into main/resources and referencing it in index.html worked for both browserDevelopmentRun and serving the production build, statically. The CSS file appears in build/distributions.
My build:
kotlin("js") version "1.7.20"
index.html
<link rel="stylesheet" href="index.css">
index.css is in the same resource folder as index.html.
This also works for images anything else, apparently.
I have followed the official Tailwind + Nuxt documentation to add Tailwind to Nuxt. I have done so for 2 new Projects and 1 existing Nuxt project. And it works fine for the first 2 projects, but...
The existing Nuxt project is giving me a hard time now as it seems to ignore the tailwind.config.js file.
Tailwind works but it is using the default config, no matter what changes I make to the config file. Nuxt also does not hot-reload when changes are made to the config.
My IDE on the other hand detects the changes and offers them as IntelliSense auto-complete option.
I am pretty lost and not sure where to start troubleshooting. Happy to share the repo if that helps.
Any help greatly appreciated. Thanks!
-- Miss J
Did you register tailwindcss in the buildModules of the nuxt.config.js (and not modules) ?
buildModules: [
// https://go.nuxtjs.dev/tailwindcss
'#nuxtjs/tailwindcss'
],
Can you add some of your code to help troubleshoot ?
package.json
nuxt.config.js
tailwind.config.js
What are you trying to change inside the tailwind config ?
The Nuxt module for Tailwind CSS is using v1.9.6 and not the latest v.2.0.3, so some things you try to change in your config file following the docs are maybe not possible with the current nuxt package.
You can upgrade to latest Tailwind version :
https://stackoverflow.com/a/30650609/13541914
yarn add --dev tailwindcss#npm:#tailwindcss/postcss7-compat postcss#^7 autoprefixer#^9
All I did was add a tailwind.config.js file.
Hope it helps
On my windows 10 machine, I'm using Git Bash, and I have a successful npm start of Webpack bundling several CSS and JavaScript files for a custom web project. But I am struggling in getting Modernizr to work at all with Webpack 4.8.3. Does anyone have any success stories on this specific implementation? Looking for any guidance. I have tried 3 different npm packages to get modernizr integrated and then working, but no luck on the latter.
Many thanks for any example steps and / or instructions.
I'm a little late to the party, but I figured I would post my solution going off of klewis' response, using webpack 4.23.1. Bear with me, as this is my first stack overflow answer 🎉.
After constructing my Modernizr build file and adding to my /src directory, instead of using the HTML Webpack Plugin, I set another entry point for webpack like so...
entry: {
bundle: './app/src/scripts/main.js',
modernizr: './app/src/scripts/lib/modernizr_custom.js'
},
Then changed the output filename to filename: '[name].js', which then the built file is with my bundle.js as modernizr.js.
That file can now be hooked into my templates: <script src="/scripts/bundle.js"></script>
Hope this solution is able to help someone else!
It appears that HTML Webpack Plugin can provide assistance with getting Modernizr wired up (naturally with a plugin, but that wasn't working for me). It took me some time to figure out an alternative approach, but here is what I did and will probably do moving forward for development builds...
Installed Webpack 4.8.3, along with the HTML Webpack Plugin, all via npm.
Constructed my Modernizr js Build file
Downloaded the file into my Webpack /src directory
Went into my weback.config.js file and told my HTML Webpack Plugin to add my Modernizr.js file like so...
new HTMLWebpackPlugin({
template: 'src/index.html',
links: [
'modernizr.js'
]
}),
Then added the necessary hook to my index.html template like so...
<head>
<script src="<%= htmlWebpackPlugin.options.links[0] %>"></script>
</head>
Finally, ran npm start
and now Modernizr is working for my web project and injecting classes into my <head> element. 2 easy steps once you have all the right dependencies and configurations set in place.
Hopefully this is a help for others.
I have set up a basic webpack/babel/mocha project just for playing around. Now I installed jQuery and Paper.js to my project with Bower, but I want them to be bundled with webpack on npm start, I don't want to write extra <script> tags etc.
I just want to use them as import $ jQuery from 'jquery'. But now my setup looks for the jquery package in npm_modules. How can I tell npm to look for these in the bower_components folder?
Is this a logical decision tho? Or am I supposed to set up this any other way?
Personally, I'd usually recommend installing everything through NPM - most frontend dependencies are on there these days. However, it does say on the Paper.js NPM page that they recommend using Bower to download the browser version of the library (perhaps there's some Node-specific code in the NPM package? I'm not sure).
To get Webpack working with Bower packages, you can set a custom name/path using config.resolve.alias:
var path = require("path");
var config = {
...
resolve: {
alias: {
"jquery": path.resolve(__dirname, "path/to/bower/file"),
"paper": path.resolve(__dirname, "path/to/bower/file")
}
}
...
}
This can come in handy in quite a few situations outside of Bower, too - for example, if you need to use a library that isn't currently distributed through a package manager, you can just add it to your project folder and use an alias to make it available to your code.