Answer the question
In order to leave comments, you need to log in
How to load styles in webpack from the right folder?
Conditionally, I have default styles written, and I need to include overloaded styles
. That is, conditionally, I have a main page component
/* main.js */
import './style.css';
class Main {
}
$ webpack -какой_то_ключ override
import './style.override.css';
class Main {
}
module.exports = {
context: __dirname, // точка входа в приложение
entry: { // точки входа
core: './angular/vendor.js',
app: './angular/app.module.js'
},
output: { // выходные файлы
path: '../webapp/js/',
publicPath: '/js/',
filename: '[name].js',
library: '[name]'
},
watchOptions: {
aggregateTimeout: 100
},
module: {
loaders: [
{ // используем ES6 to ES5
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel', // 'babel-loader' is also a legal name to reference
query: {
presets: ['es2015'],
compact : false
}
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader!'
},
{
test: /\.scss$/,
loaders: ['style', 'css', 'sass?sourceMap']
},
]
},
};
Answer the question
In order to leave comments, you need to log in
You can add synonyms ( alias ):
module.exports = {
resolve: {
alias: {
// имя синонима: путь
'style': path.join(__dirname, 'style.override.css'),
'любоеУдобноеИмяСинонима': path.join(__dirname, 'путь к модулю'),
'любоеУдобноеИмяСинонима2': 'илиТакЕслиВкорне',
}
}
}
import 'style';
import 'любоеУдобноеИмяСинонима';
require('любоеУдобноеИмяСинонима2');
var suffix = '.override';
module.exports = {
resolve: {
alias: {
'style': path.join(__dirname, 'style' + suffix + '.css'),
}
}
}
console.log('process.env', process.env);
console.log('ANY_NAME', process.env.ANY_NAME);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question