【发布时间】:2019-08-27 04:30:12
【问题描述】:
我想打包 css 文件并将其插入到我的应用程序的 shadow DOM 中。
我已经尝试过css-loader的方式:
如下文件:webpack.config.js
const path = require('path');
const CopyWebpackPlugin = require("copy-webpack-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
context: path.resolve(__dirname, 'src'),
entry: {
content: './content/index.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'to-string-loader',
{
loader: 'css-loader',
options: {}
}
]
}
]
}
}
我尝试使用这样的方式:
const css = require('./test.css').toString();
console.log(css); // [Object, Object]
import styles from './test.css';
console.log(styles) // {}
CSS 文件:
#app{
position: fixed;
right: 0;
top:0;
width: 420px;
height: 420px;
z-index: 9999;
}
这似乎不适合我。
有办法吗?
【问题讨论】:
-
@DacreDenny 不,这是来自
css-loader的解决方案 -
我试过
const css = require('to-string-loader!css-loader!./test.css').toString();和const css = require('to-string-loader!./test.css').toString();,第一种方法是CssSyntaxError,另一种输出结果相同。 -
输出为
"[object Object]" -
你可以在 OP 中包含你的 css 的内容吗?
-
我已经在 OP 中添加了 css 文件上下文
标签: javascript css webpack es6-modules