webpack -p --progress --colors我已经能够在 webpack 开发服务器上使用样式组件,没有任何问题,但在构建生产项目或运行项目时,样式没有添加webpack -d --progress --colors --watch
生产中添加的唯一样式是空样式
<style data-styled="" data-styled-version="4.4.1"></style>
Run Code Online (Sandbox Code Playgroud)
在 webpack.config.js 中,我有以下针对开发和生产运行的规则:
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
},
]
Run Code Online (Sandbox Code Playgroud)
},
插件,注意 debug 用于判断是否是生产版本
plugins: debug ? [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'template.html')
})
] : [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production"),
},
}),
new CleanWebpackPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new UglifyJsPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'template.html')
})
],
Run Code Online (Sandbox Code Playgroud)
开发服务器设置:
devServer: {
contentBase: BUILD_DIR,
historyApiFallback: true,
watchContentBase: true,
port: 9000
},
Run Code Online (Sandbox Code Playgroud)
您是否创建了createGlobalStyle包含 css 的全局样式@import?从我的网站删除导入刚刚解决了我的问题。(听起来像是同一个问题)。
https://github.com/styled-components/styled-components/issues/2911#issuecomment-592012166
| 归档时间: |
|
| 查看次数: |
5878 次 |
| 最近记录: |