webpack - 凤凰框架中 Webpack 不编译 Elm 文件
问题描述
我刚刚将我的 elm 文件从手动编译转换为通过 Webpack 自动编译,因为它捆绑在 Phoenix 框架中。
问题是重新编译效果不好。如果我删除所有缓存文件和编译输出,它有时会重新编译,但通常不会。看起来输出文件是直接从某个地方(我不知道在哪里)复制的,没有进行任何编译。
这是我的 webpack.config.js 文件:
const path = require('path');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (env, options) => {
const devMode = options.mode !== 'production';
const srcPaths = [
path.resolve(__dirname, './elm-db'),
path.resolve(__dirname, './elm-ledger'),
];
const elmRules = srcPaths.map(featurePath => ({
test: new RegExp(`^${featurePath}.*elm$`),
include: featurePath,
exclude: [/elm-stuff/, /node_modules/],
use: [
{
loader: require.resolve('elm-webpack-loader'),
options: {
cwd: featurePath,
debug: options.mode === "development",
optimize: options.mode === "production",
},
},
],
}));
return {
optimization: {
minimizer: [
new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
new OptimizeCSSAssetsPlugin({}),
]
},
entry: {
// 'app': './js/app.js',
'main': './sass/main.sass',
'db': './sass/db.sass',
'ledger': './sass/ledger.sass',
'client-db': './js/client_db.js',
'client-ledger': './js/client_ledger.js',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, '../priv/static/js'),
publicPath: '/js/',
},
devtool: devMode ? 'inline-source-map' : undefined,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: {} },
{ loader: 'sass-loader', options: {} },
],
},
].concat(elmRules)
},
plugins: [
new MiniCssExtractPlugin({ filename: '../css/[name].css' }),
new CopyWebpackPlugin([{ from: 'static/', to: '../' }]),
].concat(devMode ? [new HardSourceWebpackPlugin()] : []),
}
};
这是我的 client_db.js 文件:
import clientDb from "./routes_db"
import socket from "./socket"
let db_channel = socket.channel("ledgers", {})
db_channel.join()
.receive("ok", resp => {
console.log("Joined successfully", resp)
clientDb(db_channel)
})
.receive("error", resp => { console.log("Unable to join", resp) })
.receive("timeout", () => console.log("Networking issue. Still waiting..."))
这是 routes_db.js 的开始:
import { Elm } from "../elm-db/src/Main.elm"
let clientDb = (channel) => {
console.log("CONNECTED")
const app = Elm.Main.init()
app.ports.loadLedgers.subscribe(() => {
channel.push("load_ledgers", {})
})
...
解决方案
推荐阅读
- haskell - 如何像 Maybe monad 一样使用 Scotty 的 ActionT monad,并为错误返回早期的 http 响应?
- c# - 测试永远不会失败 - 为什么 Assert 不起作用?
- html - 在 mat-list-item 中包含 href 不起作用
- pine-script - pine 脚本版本 4 中的编译错误
- amazon-athena - 雅典娜中的 timestamp_micros 函数
- linux - 保存 bash 命令的输出以与管道命令 (|) 一起使用
- swift - 如何在 RealityKit 中仅围绕一个轴旋转对象?
- r - 在给定阈值上查找接下来几个月的预测值在 r 中的概率
- sas - SAS 拟合回归模型以通过其他五个变量预测“mpg”。报告变异膨胀因素并解释
- string - 使用应用脚本在 Google 电子表格中找不到替换功能