The first was introduced in main.js directly declare loader
demo:
import '!style-loader!css-loader!less-loader!./assets/css/common.less'
This allows variable global scope common.less style, but can not use the less be declared in the local vue file
The second use style-resourses-loader this loader, the official website also described, many of which are checked this way:
Installation loader
npm install style-resources-loader -D
In vue.config.js the configuration pluginOptions
as follows:
// 第三方插件配置 pluginOptions: { "style-resources-loader": { preProcessor: "less", patterns: [path.resolve(__dirname, "./src/assets/css/common.less")] } }
CSS: { loaderOptions: { Sass: { // Sass file path to process Data: `@import" ~@/assets/css/common.less " ;` } }
CSS: { loaderOptions: { less: { // global variable name globalVars: { Color1: 'Red'; } } } }
Defined background element in the path problem sass less file:
background: url("~../assets/logo.png");
If you write directly in the style tag vue file, you can directly opposite path, css files also, less scss documents required in front of the path - coupled with the introduction of local pictures img tag, but also can directly write the relative path a;
Data in data declaration, a local path that has an image, the method requires the introduction of the module:
require('../assets/logo.png')